I have been trying to implement a the oidc oauth workflow with pkce following this guide ‘https://blog.ordina-jworks.io/security/2020/08/18/Securing-Applications-Azure-AD.html’.
However, the library never seems to set the access_token needed for the backend resource server.
In the angular app i have guards, that redirect users that are not logged in to the /login page.
// login.component.ts
export class LoginComponent {
constructor(private authService: AuthService, private activatedRoute: ActivatedRoute, private oAuthService: OAuthService) {
this.oAuthService.configure(authConfig);
this.oAuthService.loadDiscoveryDocumentAndLogin();
this.oAuthService.setupAutomaticSilentRefresh();
}
}
The authConfig is (basically the one from the library documentation https://github.com/manfredsteyer/angular-oauth2-oidc):
// auth.config.ts
export const authConfig: AuthConfig = {
issuer: 'https://idsvr4.azurewebsites.net',
redirectUri: window.location.origin + '/index.html',
clientId: 'spa',
responseType: 'code',
strictDiscoveryDocumentValidation: false,
scope: 'openid profile email offline_access api'
}
And finally the redirect component is:
constructor(private oauthService: OAuthService, private accountService: AccountService) {
console.log(this.oauthService.getAccessToken());
accountService.get(15).subscribe({
next: (v) => {console.log(v);},
error: (e) => {console.log(e);}
})
}
When accessing the website, i get sent to the /login page as expected. From there to the authorization server. However, after logging in and trying to access my Backend there is no access_token. Am i missing something? Do i have to perform some other step?
Is there something I am missing on how to obtain the access_token? Any help is highly appreciated