How to use the @openid/appauth.TokenRequest function in @openid/appauth

To help you get started, we’ve selected a few @openid/appauth examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pingidentity / angular-spa-sample / src / app / authorization.service.ts View on Github external
this.notifier.setAuthorizationListener((request, response, error) => {
          console.log('Authorization request complete ', request, response, error);
          if (response && response.code) {
            const tokenHandler = new BaseTokenRequestHandler(this.requestor);

            // use the code to make the token request.
            const extras: StringMap = {};
            if (this.environment.client_secret) {
              extras['client_secret'] = this.environment.client_secret;
            }
            extras['code_verifier'] = request.internal['code_verifier'];
            const tokenRequest = new TokenRequest({
              client_id: this.environment.client_id,
              redirect_uri: this.environment.redirect_uri,
              grant_type: GRANT_TYPE_AUTHORIZATION_CODE,
              code: response.code,
              extras: extras
            });

            console.log('making token request:' + JSON.stringify(tokenRequest.toStringMap()));
            tokenHandler.performTokenRequest(configuration, tokenRequest)
              .then((tokenResponse) => {
                console.log('received token response ', tokenResponse);
                this._tokenResponses.next(tokenResponse);
                resolve(tokenResponse);
              });
          } else {
            reject(error);
github imodeljs / imodeljs / core / clients-backend / src / oidc / OidcDeviceClient.ts View on Github external
private async makeRefreshTokenRequest(requestContext: ClientRequestContext): Promise {
    requestContext.enter();
    if (!this._configuration)
      throw new BentleyError(AuthStatus.Error, "Not initialized. First call initialize()", Logger.logError, loggerCategory);
    if (!this._tokenResponse)
      throw new BentleyError(AuthStatus.Error, "Missing refresh token. First call signIn() and ensure it's successful", Logger.logError, loggerCategory);

    const tokenRequestJson: TokenRequestJson = {
      grant_type: GRANT_TYPE_REFRESH_TOKEN,
      refresh_token: this._tokenResponse.refreshToken,
      redirect_uri: this._clientConfiguration.redirectUri,
      client_id: this._clientConfiguration.clientId,
    };

    const request = new TokenRequest(tokenRequestJson);
    return this._tokenHandler.performTokenRequest(this._configuration, request);
  }
github imodeljs / imodeljs / core / clients-backend / src / oidc / OidcDeviceClient.ts View on Github external
let extras: StringMap | undefined;
    if (authRequest && authRequest.internal) {
      extras = {};
      extras.code_verifier = authRequest.internal.code_verifier;
    }

    const tokenRequestJson: TokenRequestJson = {
      grant_type: GRANT_TYPE_AUTHORIZATION_CODE,
      code: authCode,
      redirect_uri: this._clientConfiguration.redirectUri,
      client_id: this._clientConfiguration.clientId,
      extras,
    };

    const request = new TokenRequest(tokenRequestJson);
    return this._tokenHandler.performTokenRequest(this._configuration, request);
  }