File tree 3 files changed +30
-9
lines changed
3 files changed +30
-9
lines changed Original file line number Diff line number Diff line change 2
2
< h1 *ngIf ="!givenName "> Welcome!</ h1 >
3
3
< h1 *ngIf ="givenName "> Welcome, {{ givenName }} {{ familyName }}!</ h1 >
4
4
5
+ < div *ngIf ="login " style ="color: red ">
6
+ You have to login before you can search for flights.
7
+ </ div >
8
+
5
9
< div class ="panel panel-default ">
6
10
< div class ="panel-body ">
7
11
< 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';
2
2
import { Component , OnInit } from '@angular/core' ;
3
3
import { OAuthService } from 'angular-oauth2-oidc' ;
4
4
import { authCodeFlowConfig } from '../auth-code-flow.config' ;
5
+ import { ActivatedRoute } from '@angular/router' ;
5
6
6
7
@Component ( {
7
8
templateUrl : './home.component.html'
@@ -10,10 +11,19 @@ export class HomeComponent implements OnInit {
10
11
loginFailed : boolean = false ;
11
12
userProfile : object ;
12
13
usePopup : boolean ;
14
+ login : false ;
13
15
14
- constructor ( private oauthService : OAuthService ) { }
16
+ constructor (
17
+ private route : ActivatedRoute ,
18
+ private oauthService : OAuthService ) {
19
+ }
15
20
16
21
ngOnInit ( ) {
22
+
23
+ this . route . params . subscribe ( p => {
24
+ this . login = p [ 'login' ] ;
25
+ } ) ;
26
+
17
27
// This would directly (w/o user interaction) redirect the user to the
18
28
// login page if they are not already logged in.
19
29
/*
Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@angular/core' ;
2
2
import {
3
- CanActivate ,
4
- ActivatedRouteSnapshot ,
5
- RouterStateSnapshot
3
+ CanActivate , Router
6
4
} from '@angular/router' ;
5
+ import { OAuthService } from 'angular-oauth2-oidc' ;
7
6
8
7
@Injectable ( )
9
8
export 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
+ }
15
22
}
16
23
}
You can’t perform that action at this time.
0 commit comments