This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve typings on KeycloakContext
- Loading branch information
Dara Hayes
committed
Jul 10, 2019
1 parent
77f9e99
commit 18c295e
Showing
5 changed files
with
42 additions
and
33 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,21 +1,20 @@ | ||
import { AuthContextProvider } from './api' | ||
import Keycloak from 'keycloak-connect' | ||
|
||
export class KeycloakContext implements AuthContextProvider { | ||
public readonly request: any | ||
public readonly accessToken: any | ||
public readonly authenticated: boolean | ||
public readonly request: Keycloak.GrantedRequest | ||
public readonly accessToken: Keycloak.Token | undefined | ||
|
||
constructor ({ req }: { req: any }) { | ||
constructor ({ req }: { req: Keycloak.GrantedRequest }) { | ||
this.request = req | ||
this.accessToken = (req && req.kauth && req.kauth.grant) ? req.kauth.grant.access_token : undefined | ||
this.authenticated = this.accessToken && !this.accessToken.isExpired() | ||
} | ||
|
||
public isAuthenticated (): boolean { | ||
return this.authenticated | ||
return (this.accessToken && !this.accessToken.isExpired()) ? true : false | ||
} | ||
|
||
public hasRole (role: string): boolean { | ||
return this.isAuthenticated() && this.accessToken.hasRole(role) | ||
return ((this.accessToken && !this.accessToken.isExpired()) && this.accessToken.hasRole(role)) ? true : false | ||
} | ||
} |
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
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