PUNKT-15 Update Logowanie przez USOS
This commit is contained in:
parent
953b8f0dab
commit
f3be31ed7e
@ -6,6 +6,7 @@ import 'rxjs/add/operator/catch';
|
|||||||
import 'rxjs/add/observable/throw';
|
import 'rxjs/add/observable/throw';
|
||||||
import { MatSnackBar } from '@angular/material/snack-bar';
|
import { MatSnackBar } from '@angular/material/snack-bar';
|
||||||
import { Subject } from 'rxjs/Subject';
|
import { Subject } from 'rxjs/Subject';
|
||||||
|
import { USOSUrl, LoginKey } from './login';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthenticationService {
|
export class AuthenticationService {
|
||||||
@ -66,8 +67,8 @@ export class AuthenticationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getUSOSTokens(): Observable<string> {
|
getUSOSTokens(): Observable<USOSUrl> {
|
||||||
return this.http.get<string>(encodeURI('usos/request_token?oauth_callback=http://localhost:4200/login/usos'));
|
return this.http.get<USOSUrl>(encodeURI('usos/request_token?oauth_callback=http://localhost:4200/login/usos'));
|
||||||
}
|
}
|
||||||
|
|
||||||
getToken(): String {
|
getToken(): String {
|
||||||
@ -79,15 +80,15 @@ export class AuthenticationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getAccessByUSOS(outh_t: string, outh_t_secret: string, outh_ver: string): Observable<string> {
|
getAccessByUSOS(outh_t: string, outh_t_secret: string, outh_ver: string): Observable<LoginKey> {
|
||||||
const headers = new HttpHeaders({
|
const headers = new HttpHeaders({
|
||||||
'oauth_token' : outh_t,
|
'oauth_token' : outh_t,
|
||||||
'oauth_token_secret': outh_t_secret,
|
'oauth_token_secret': outh_t_secret,
|
||||||
'oauth_verifier' : outh_ver
|
'oauth_verifier' : outh_ver
|
||||||
});
|
});
|
||||||
|
|
||||||
return this.http.get<string>('usos/access_token' , {headers: headers});
|
return this.http.get<LoginKey>('usos/access_token' , {headers: headers});
|
||||||
}
|
}
|
||||||
|
|
||||||
isLoggedIn(): boolean {
|
isLoggedIn(): boolean {
|
||||||
const token: String = this.getToken();
|
const token: String = this.getToken();
|
||||||
|
14
FrontEnd/src/app/login.ts
Normal file
14
FrontEnd/src/app/login.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
export class USOSUrl {
|
||||||
|
|
||||||
|
url: string;
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LoginKey {
|
||||||
|
|
||||||
|
key: string;
|
||||||
|
username: string;
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
}
|
@ -9,10 +9,7 @@ import { Router, ActivatedRoute } from '@angular/router';
|
|||||||
})
|
})
|
||||||
export class LoginUsosComponent implements OnInit {
|
export class LoginUsosComponent implements OnInit {
|
||||||
|
|
||||||
username = '';
|
|
||||||
|
|
||||||
constructor(private authenticationService: AuthenticationService,
|
constructor(private authenticationService: AuthenticationService,
|
||||||
private activatedRoute: ActivatedRoute,
|
|
||||||
private router: Router) {}
|
private router: Router) {}
|
||||||
|
|
||||||
|
|
||||||
@ -23,7 +20,7 @@ export class LoginUsosComponent implements OnInit {
|
|||||||
this.authenticationService.getAccessByUSOS(localStorage.getItem('outh_token'),
|
this.authenticationService.getAccessByUSOS(localStorage.getItem('outh_token'),
|
||||||
localStorage.getItem('outh_token_secret'), localStorage.getItem('oauth_verifier')).subscribe(
|
localStorage.getItem('outh_token_secret'), localStorage.getItem('oauth_verifier')).subscribe(
|
||||||
message => {
|
message => {
|
||||||
this.authenticationService.usosLogin(this.username, message);
|
this.authenticationService.usosLogin(message.username, message.key);
|
||||||
this.router.navigate(['/home']);
|
this.router.navigate(['/home']);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -56,7 +56,7 @@ export class LoginComponent implements OnInit {
|
|||||||
loginWithUsos() {
|
loginWithUsos() {
|
||||||
let array = [] as string[];
|
let array = [] as string[];
|
||||||
this.authenticationService.getUSOSTokens().subscribe(el => {
|
this.authenticationService.getUSOSTokens().subscribe(el => {
|
||||||
array = el.split('?');
|
array = el.url.split('?');
|
||||||
array = array[1].split('&');
|
array = array[1].split('&');
|
||||||
this.outh_token = array[0];
|
this.outh_token = array[0];
|
||||||
this.outh_token = this.outh_token.replace('oauth_token=', '');
|
this.outh_token = this.outh_token.replace('oauth_token=', '');
|
||||||
@ -64,7 +64,7 @@ export class LoginComponent implements OnInit {
|
|||||||
this.outh_token_secret = this.outh_token_secret.replace('oauth_token_secret=', '');
|
this.outh_token_secret = this.outh_token_secret.replace('oauth_token_secret=', '');
|
||||||
localStorage.setItem('outh_token', array[0].replace('oauth_token=', ''));
|
localStorage.setItem('outh_token', array[0].replace('oauth_token=', ''));
|
||||||
localStorage.setItem('outh_token_secret', array[1].replace('oauth_token_secret=', ''));
|
localStorage.setItem('outh_token_secret', array[1].replace('oauth_token_secret=', ''));
|
||||||
window.location.href = el;
|
window.location.href = el.url;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user