Skip to content

Commit 3283980

Browse files
committed
wxwork oauth2
1 parent 93c41e2 commit 3283980

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

proxy.config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"/janusec-admin/": {
3-
"target": "http://192.168.100.107",
3+
"target": "http://192.168.100.107:9080",
44
"secure": false
55
},
66
"/janusec-admin/webssh": {
7-
"target": "ws://192.168.100.107",
7+
"target": "ws://192.168.100.107:9080",
88
"secure": false,
99
"ws": true,
1010
"changeOrigin": true
1111
},
1212
"/favicon.ico": {
13-
"target": "http://192.168.100.107/janusec-admin/",
13+
"target": "http://192.168.100.107:9080/janusec-admin/",
1414
"secure": false
1515
}
1616
}

src/app/application.service.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
22
import { HttpClient, HttpHeaders } from '@angular/common/http';
33
import { Observable, of } from 'rxjs';
44
import { catchError, map, tap } from 'rxjs/operators';
5-
import { AuthUser, Application, Certificate, Domain, AppAdmin, VulnType, APIResponse, NodesKey, Node, LastRegexLogs, LastCCLogs } from './models';
5+
import { AuthUser, Application, Certificate, Domain, AppAdmin, VulnType, APIResponse, NodesKey, Node, LastRegexLogs, LastCCLogs, OAuthInfo } from './models';
66
import { MessageService } from './message.service';
77

88
const httpOptions = {
@@ -23,6 +23,7 @@ export class ApplicationService {
2323
vulntypemap: object = new(Object);
2424
lastRegexLogs: LastRegexLogs = new(LastRegexLogs);
2525
lastCCLogs: LastCCLogs = new (LastCCLogs);
26+
oauth: OAuthInfo = new (OAuthInfo);
2627

2728
constructor(private http: HttpClient,
2829
private messageService: MessageService) { }
@@ -54,6 +55,19 @@ export class ApplicationService {
5455
});
5556
}
5657

58+
getResponseByURL(url:string, callback:(obj: object)=>any, id?:number, obj?:object) {
59+
// Get Request
60+
this.http.get<APIResponse>(url, httpOptions).pipe(
61+
tap( _ => {}),
62+
catchError(this.handleError<APIResponse>('Get response'))
63+
).subscribe((response: APIResponse) => {
64+
if(response.err==null) {
65+
callback(response.object);
66+
}
67+
else this.messageService.add('Error:' + response.err);
68+
});
69+
}
70+
5771
getApplications() {
5872
var self = this;
5973
this.getResponse('getapps', function(obj: Application[]){

src/app/login-form/login-form.component.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ <h1>Login</h1>
99
<input matInput type="password" placeholder="Password" [(ngModel)]="password" required>
1010
</mat-form-field>
1111

12-
<button mat-button (click)="onSubmit($event)">Submit</button>
13-
12+
<button mat-button (click)="onSubmit($event)">Submit</button>
13+
</div>
14+
<div *ngIf="oauth.use_oauth==true" class="container">
15+
<a href="{{ oauth.entrance_url }}">{{ oauth.display_name }}</a>
1416
</div>
1517
</div>

src/app/login-form/login-form.component.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
33
import { Router } from '@angular/router';
44
import * as bcrypt from 'bcryptjs';
55
import * as cryptojs from 'crypto-js';
6-
import { AuthUser } from '../models';
6+
import { AuthUser, OAuthInfo } from '../models';
77
import { MessageService } from '../message.service';
88
import { ApplicationService } from '../application.service';
99
declare var require: any;
@@ -17,6 +17,7 @@ export class LoginFormComponent implements OnInit {
1717
username: string;
1818
password: string;
1919
submitted = false;
20+
oauth: OAuthInfo = new (OAuthInfo);
2021

2122
onSubmit(event) {
2223
if(!this.username || !this.password){
@@ -42,7 +43,14 @@ export class LoginFormComponent implements OnInit {
4243
private http: HttpClient,
4344
private router: Router) { }
4445

45-
ngOnInit() {
46+
ngOnInit() {
47+
let self=this;
48+
this.applicationService.getResponseByURL('/janusec-admin/oauth/get',
49+
function(obj: OAuthInfo){
50+
self.oauth=obj;
51+
console.log(self.oauth);
52+
})
4653
}
54+
4755

4856
}

src/app/models.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,10 @@ export class Server {
272272
this.username =username;
273273
this.password = password;
274274
}
275+
}
276+
277+
export class OAuthInfo {
278+
use_oauth: boolean;
279+
display_name: string;
280+
entrance_url: string;
275281
}

0 commit comments

Comments
 (0)