File tree Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Original file line number Diff line number Diff line change 22< h1 *ngIf ="!givenName "> Welcome!</ h1 >
33< h1 *ngIf ="givenName "> Welcome, {{ givenName }} {{ familyName }}!</ h1 >
44
5+ < div *ngIf ="login " style ="color: red ">
6+ You have to login before you can search for flights.
7+ </ div >
8+
59< div class ="panel panel-default ">
610 < div class ="panel-body ">
711 < p > Login with Authorization Server</ p >
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { authConfig } from '../auth.config';
22import { Component , OnInit } from '@angular/core' ;
33import { OAuthService } from 'angular-oauth2-oidc' ;
44import { authCodeFlowConfig } from '../auth-code-flow.config' ;
5+ import { ActivatedRoute } from '@angular/router' ;
56
67@Component ( {
78 templateUrl : './home.component.html'
@@ -10,10 +11,19 @@ export class HomeComponent implements OnInit {
1011 loginFailed : boolean = false ;
1112 userProfile : object ;
1213 usePopup : boolean ;
14+ login : false ;
1315
14- constructor ( private oauthService : OAuthService ) { }
16+ constructor (
17+ private route : ActivatedRoute ,
18+ private oauthService : OAuthService ) {
19+ }
1520
1621 ngOnInit ( ) {
22+
23+ this . route . params . subscribe ( p => {
24+ this . login = p [ 'login' ] ;
25+ } ) ;
26+
1727 // This would directly (w/o user interaction) redirect the user to the
1828 // login page if they are not already logged in.
1929 /*
Original file line number Diff line number Diff line change 11import { Injectable } from '@angular/core' ;
22import {
3- CanActivate ,
4- ActivatedRouteSnapshot ,
5- RouterStateSnapshot
3+ CanActivate , Router
64} from '@angular/router' ;
5+ import { OAuthService } from 'angular-oauth2-oidc' ;
76
87@Injectable ( )
98export class AuthGuard implements CanActivate {
10- canActivate (
11- route : ActivatedRouteSnapshot ,
12- state : RouterStateSnapshot
13- ) : boolean {
14- return true ;
9+
10+ constructor (
11+ private router : Router ,
12+ private oauthService : OAuthService ) {
13+ }
14+
15+ canActivate ( ) {
16+ if ( this . oauthService . hasValidAccessToken ( ) && this . oauthService . hasValidIdToken ( ) ) {
17+ return true ;
18+ } else {
19+ this . router . navigate ( [ '/home' , { login : true } ] ) ;
20+ return false ;
21+ }
1522 }
1623}
You can’t perform that action at this time.
0 commit comments