63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { Component, OnInit } from '@angular/core';
|
|
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
@Component({
|
|
selector: 'app-home',
|
|
templateUrl: './home.component.html',
|
|
styleUrls: ['./home.component.css']
|
|
})
|
|
export class HomeComponent implements OnInit {
|
|
|
|
id_token = 'x';
|
|
state = 'y';
|
|
parsedToken;
|
|
|
|
constructor(private http: HttpClient, private router: Router, private activatedRoute: ActivatedRoute) { }
|
|
|
|
ngOnInit(): void {
|
|
this.paramsFromUrl();
|
|
console.log(this.parsedToken);
|
|
this.activatedRoute.fragment.subscribe(data => console.log(data));
|
|
}
|
|
|
|
logout() {
|
|
const headerDict = {
|
|
'Accept': '*/*',
|
|
'Access-Control-Allow-Origin': '*'
|
|
};
|
|
this.http.get('https://waecm-sso.inso.tuwien.ac.at/auth/realms/waecm/protocol/openid-connect/logout' +
|
|
'?id_token_hint=' + this.id_token + '&\n' +
|
|
'post_logout_redirect_uri=http://localhost:4200&\n' +
|
|
'state=' + this.state,
|
|
{
|
|
headers: new HttpHeaders(headerDict),
|
|
responseType: 'text'
|
|
}).subscribe(() => this.router.navigate(['login']));
|
|
}
|
|
|
|
gotoBackend() {
|
|
const headerDict = {
|
|
'Authorization': 'Bearer ' + this.id_token
|
|
};
|
|
this.http.get('http://localhost:8000/api/login',
|
|
{
|
|
headers: new HttpHeaders(headerDict)
|
|
})
|
|
.subscribe(data => console.log(data));
|
|
}
|
|
|
|
paramsFromUrl() {
|
|
const url = window.location.href;
|
|
const params: string = url.split('#')[1];
|
|
this.state = params.split('&')[0].split('session_state=')[1];
|
|
this.id_token = params.split('&')[1].split('id_token=')[1];
|
|
try {
|
|
this.parsedToken = JSON.parse(atob(this.id_token.split('.')[1]));
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
}
|
|
|
|
}
|