Created
May 23, 2019 15:08
-
-
Save SpicySyntax/33c2ec89f041dce8f932e0c9591d400a to your computer and use it in GitHub Desktop.
OIDC Auth
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
import { Log, User, UserManager } from 'oidc-client'; | |
import { Constants } from '../helpers/Constants'; | |
export class AuthService { | |
public userManager: UserManager; | |
constructor() { | |
const settings = { | |
authority: Constants.stsAuthority, | |
client_id: Constants.clientId, | |
redirect_uri: `${Constants.clientRoot}/signin-oidc`, | |
silent_redirect_uri: `${Constants.clientRoot}/signin-oidc`, | |
// tslint:disable-next-line:object-literal-sort-keys | |
//post_logout_redirect_uri: `${Constants.clientRoot}`, | |
response_type: 'id_token token', | |
scope: Constants.clientScope | |
}; | |
this.userManager = new UserManager(settings); | |
Log.logger = console; | |
Log.level = Log.INFO; | |
} | |
public getUser(): Promise<User> { | |
return this.userManager.getUser(); | |
} | |
public login(): Promise<void> { | |
return this.userManager.signinRedirect(); | |
} | |
public renewToken(): Promise<User> { | |
return this.userManager.signinSilent(); | |
} | |
public logout(): Promise<void> { | |
return this.userManager.signoutRedirect(); | |
} | |
} |
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
export class Constants { | |
public static stsAuthority = 'https://qa-imsoidc.bentley.com'; | |
public static clientId = 'spa-7yKd4iOg6v8wSetaxjt69serw'; | |
public static clientRoot = 'http://localhost:5000'; | |
public static clientScope = 'openid email profile organization'; | |
public static apiRoot = 'https://qa-imsoidc.bentley.com/api/'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment