below given is the code for authenticating my angular SPA using AD FS using angular-oauth2-oidc
initializeOAuthService(): void {
this.oauthService.configure({
redirectUri: window.location.origin + '/app/search',
requireHttps: true,
scope: 'openid profile email',
responseType: 'id_token token',
oidc: true,
clientId: environment.adfsClientId,
loginUrl: environment.adfsUrl + '/oauth2/authorize',
issuer: environment.adfsUrl,
logoutUrl:
environment.adfsUrl +
'/ls/?wa=wsignoutcleanup1.0&wreply=' +
location.protocol +
'//' +
location.hostname +
(location.port ? ':' + location.port : ''),
postLogoutRedirectUri:
location.protocol +
'//' +
location.hostname +
(location.port ? ':' + location.port : ''),
});
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.setStorage(localStorage);
if (!this.oauthService.hasValidAccessToken()) {
console.log('no access token available');
this.oauthService
.loadDiscoveryDocumentAndTryLogin()
.then(() => {
if (!this.oauthService.hasValidAccessToken()) {
this.oauthService.initImplicitFlow();
}
})
.catch((error) => {
console.log(error);
});
}
// this.oauthService.setupAutomaticSilentRefresh();
}
I can log in to the application successfully and I can see the access and id tokens in the URL.
but when I call "oauthService.getAccessToken()" or "this.oauthService.getIdentityClaims()" I am getting null as result.
Can anyone tell me what I am missing?
Note: I have called the above method from the login component's constructor. The login page and page to which the AD FS redirected are different.