Skip to content

Instantly share code, notes, and snippets.

@stupiduglyfool
Created October 17, 2017 09:30
Show Gist options
  • Save stupiduglyfool/cfdadb7005ef548f79d91227ee00c89a to your computer and use it in GitHub Desktop.
Save stupiduglyfool/cfdadb7005ef548f79d91227ee00c89a to your computer and use it in GitHub Desktop.
@openid/appauth async/await demo
public async signIn(username?: string) {
if (username) extras['login_hint'] = username;
if (this._config.clientSecret) extras['client_secret'] = this._config.clientSecret;
if (this._verifier) {
extras['code_challenge'] = this._verifier.challenge;
extras['code_challenge_method'] = this._verifier.method;
extras['code_verifier'] = this._verifier.verifier;
}
// create a request
let authRequest = new AuthorizationRequest(this._config.clientId, this._config.redirectUri, this._config.scope, AuthorizationRequest.RESPONSE_TYPE_CODE, undefined, extras);
let authResponse = await this._authorizationHandler.performAuthorizationRequest(this._authServiceConfig, authRequest);
let tokenResponse = await this.performTokenRequest(authResponse.response.code);
this._accessTokenResponse = tokenResponse;
this._refreshToken = tokenResponse.refreshToken;
}
private async performTokenRequest(code: string) {
let extras: StringMap = {};
if (this._config.clientSecret) extras['client_secret'] = this._config.clientSecret;
if (this._verifier) {
extras['code_challenge'] = this._verifier.challenge;
extras['code_challenge_method'] = this._verifier.method;
extras['code_verifier'] = this._verifier.verifier;
}
let request = new TokenRequest(this._config.clientId, this._config.redirectUri, GRANT_TYPE_AUTHORIZATION_CODE, code, undefined, extras);
return await this._tokenHandler.performTokenRequest(this._authServiceConfig, request);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment