-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added aindows claims Guard into angular application.
- Loading branch information
Alexander Kulik
committed
Jul 25, 2019
1 parent
3324526
commit 2820f59
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/ClientApp/src/app/api-authorization/authorize-windows-group-guard.guard.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { map, tap } from 'rxjs/operators'; | ||
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router, UrlTree } from '@angular/router'; | ||
import { AuthorizeService } from "./authorize.service"; | ||
import { ApplicationPaths, QueryParameterNames } from './api-authorization.constants'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AuthorizeWindowsGroupGuardGuard implements CanActivate { | ||
constructor(private authorize: AuthorizeService, private router: Router) { } | ||
|
||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | | ||
Promise<boolean | UrlTree> | | ||
boolean | | ||
UrlTree { | ||
return this.authorize.getUser().pipe(map((u: any) => !!u && !!u.hasUsersGroup)).pipe(tap((isAuthorized: boolean) => this.handleAuthorization(isAuthorized, state)));; | ||
} | ||
|
||
private handleAuthorization(isAuthenticated: boolean, state: RouterStateSnapshot) { | ||
if (!isAuthenticated) { | ||
window.location.href = "/Identity/Account/Login?" + QueryParameterNames.ReturnUrl + "=/"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters