I'm using angular-oauth2-oidc to implement authorization code flow in an angular 10 application. The main idea is pretty easy, I just have an app component with a button. When the user clicks on it, he must be redirected to the authentication provider login page and back on the application when successfully logged in.
The authentication is handled by the following service:
export class AuthenticationService {
private authCodeFlowConfig: AuthConfig = {
issuer: ...
};
constructor(public oauthService: OAuthService) {
this.oauthService.configure(this.authCodeFlowConfig);
if (location.href.indexOf('?code') > 0) {
this.oauthService.loadDiscoveryDocumentAndLogin();
}
}
async login(): Promise<void> {
await this.oauthService.loadDiscoveryDocumentAndLogin();
}
}
This works but I'm a bit bothered by the URL check in the constructor. However, if I don't do that, the user is correctly redirected to the login page and back on the application once succesfully logged in, but he gets stuck in the middle of the code flow. Indeed, the authorization code is present in the URL, however, angular-oauth2-oidc is not processing it, which is why I have to call again the login method in the constructor if the "code" query string is present.
I suspect that I'm doing something wrong as I was expecting that angular-oauth2-oidc would process the code automatically.
Am I missing something here ?