Skip to content

Commit

Permalink
changed README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobritodev committed Jan 2, 2020
1 parent ff47ad8 commit 263fde0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ Client configuration
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
"jp_api.is4"
"jp_api.is4",
"role"
}
},

Expand Down Expand Up @@ -126,6 +127,12 @@ Api resource configuration
}
```
Identity Resource:
```
new IdentityResource("role", new List<string>(){"roles"}),
```
## Table of Contents ##
- [Several break changes](#several-break-changes)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
import { SettingsService } from '@core/settings/settings.service';
import { Observable } from 'rxjs';
import { filter, map, tap } from 'rxjs/operators';

Expand All @@ -11,17 +12,24 @@ export class AuthGuardOnlyAdmin implements CanActivate {

constructor(
private authService: AuthService,
private settings: SettingsService,
private router: Router
) {
this.authService.isAuthenticated$.subscribe(i => this.isAuthenticated = i);
}

canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot,
): Observable<boolean> {
return this.authService.isDoneLoading$
.pipe(filter(isDone => isDone))
.pipe(tap(_ => this.isAuthenticated || this.authService.login(state.url)))
.pipe(map(_ => this.isAuthenticated));
.pipe(map(_ => {
if (this.isAuthenticated && this.settings.getUserClaims()["role"] === "Administrator") {
return true;
}
this.router.navigate(['/not-found']);
return false;
}));
}
}

0 comments on commit 263fde0

Please sign in to comment.