How to get access token using angular-oauth2-oidc for PKCE code authentication?
Asked Answered
L

1

6

I am using angular-oauth2-oidc for authentication and I dont know how to get access token. I am using PKCE code flow with this configuraion

  authConfig: AuthConfig = {
    issuer: 'https://test.com/oauth/token',
    // requireHttps: false,
    redirectUri:'http://localhost:4200/',
    strictDiscoveryDocumentValidation: false,
    tokenEndpoint: 'https://test.com/oauth/token',
    clientId: 'test',
    // dummyClientSecret: 'test',
    scope: 'openid',
    oidc: true,
    responseType: 'code',
    showDebugInformation: true,
    requestAccessToken: true
  };

Flow is initiated with this code and after login it's redirected but I can't get any tokens.

  getAutherizationCodeWithPKCE() {
    this.oauthService.configure(this.authConfig);
    this.oauthService.initCodeFlow();
    this.oauthService.loadDiscoveryDocumentAndTryLogin
}
Landmark answered 7/2, 2022 at 15:43 Comment(2)
Check this sample project referenced from the angular-oauth2-oidc github and its auth.service.ts.Waterresistant
this is the older project and I am using PKCE flow.Landmark
L
7

Issue is resolved with sending client secret in the example above

   dummyClientSecret: 'test',

I am using Cloud Foundry authorization server that seems to require client secret. Access token then can be easily obtained with

this.oauthService.getAccessToken()

versions:

angular 13.1.2
angular-oauth2-oidc 13.0.1
cloud foundry uaa 75.11.0

I am not deleting this question in case someone get same issue in the future.

Landmark answered 8/2, 2022 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.