OAuth2 and SSO with angular-oauth2-oidc won’t retrieve access token


here`s my problem

I am trying to implement SSO and OAuth2 flow with angular-oauth2-oidc. I can get the right response (the access_token) using POSTMAN and ThunderClient (VS code), but not with Angular

Here’s my configuration:

 authCodeFlowConfig: AuthConfig = {
    issuer: 'https://URL.com/',
    loginUrl: 'https://URL.com/authorize-client',
    clientId: environment.API.CLIENT_ID,
    responseType: 'code',
    scope: environment.API.SCOPE,
    tokenEndpoint: 'https://URL.com/request-access',
    dummyClientSecret: environment.API.CLIENT_SECRET,
    redirectUri: window.location.origin,
    showDebugInformation: true,
  }

...

  constructor(
    private httpClient: HttpClient,
    private oauthService: OAuthService
  ) {
    this.getAuthorizeClientCode()
  }

...


getAuthorizeClientCode() {
    this.oauthService.configure(this.authCodeFlowConfig);
    this.oauthService.tokenValidationHandler = new JwksValidationHandler()
    this.oauthService.tryLogin({
      onTokenReceived: context => {
        console.log(context)
      }
    })
      .then(() => {
        if (this.oauthService.hasValidAccessToken()) {
          this.oauthService.silentRefresh()
        } else {
          this.oauthService.initCodeFlow();
        }
      })
      .catch(err => console.log(err))
  }

What happens: The flow works up until one point. I do the login and it gets the code and call the endpoint ‘request_access’, but that’s it, the token endpoint throws me an error:

enter image description here

When I check the network tab I the info is there:

enter image description here

I searched everywhere and I really don’t know what I’m missing since the flow works in POSTMAN, but it won’t in Angular.

Source: JavaSript – Stack Overflow

September 20, 2021
Category : News
Tags: access-token | angular | javascript | oauth-2.0 | single sign-on

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.