manfredsteyer / angular-oauth2-oidc

Support for OAuth 2 and OpenId Connect (OIDC) in Angular.
MIT License
1.86k stars 681 forks source link

adfs using initLoginFlow() returns auth token but getAccessToken() is null #1394

Open Msey opened 4 months ago

Msey commented 4 months ago

Describe the bug

I've made the most trivial example with auth flow

I'm not good at angular but I followed your examples from the main page and looks like the data after redirection is erased because when I try to get config values from oauthService it says that nothing there. How solve the problem?

Code description AppComponent has two buttons: actionOne and actionTwo

pressing actionOne button initiates auth flow and it seems to work just fine: I input login and password into the adfs form and it redirects me back to my page with authorization token (I skipped the large part from url for readability):

https://bp-vstupin.mercury.com:4200/#code=f0WXb9S6lTZZjy7lA &state= MWlvWF3

But when I try to get my access token by pressing actionTwo button which calls getAccessToken() from angular-oauth2-oidc it returns null

The following screenshot describes results:

image

Essential components:

AppModule


import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { OAuthModule } from 'angular-oauth2-oidc';

@NgModule({
    declarations: [
        AppComponent
    ],
    imports: [
        BrowserModule,
        HttpClientModule,
        OAuthModule.forRoot()
    ],
    bootstrap: [AppComponent]
})
export class AppModule { }

AppComponent

import { Component, OnInit } from '@angular/core';
import { OAuthService,  } from 'angular-oauth2-oidc';

@Component({
    selector: 'app',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {

    public message: string;
    public token: string;
    public idtoken: string;
    public isAuthenticatedSubject$: boolean;
    constructor(private oauthService: OAuthService) {
    }

    ngOnInit() {

    }

    actionOne() {
        this.oauthService.configure({
            issuer: 'https://sts.someadfsdomain.com/adfs',
            clientId: 'b9f8770e-c539-40b8-945a-3793a4660d66',
            dummyClientSecret: 'TXcebT0fssgLXoZxIVVg9t0saq5SwVRzD1MNxsei',
            redirectUri: 'https://bp-vstupin.mercury.com:4200/',
            responseType: 'code id_token',
            loginUrl: 'https://sts.someadfsdomain.com/adfs/oauth2/authorize/',
            scope: 'offline_access openid profile customscope',
        });

        this.oauthService.initLoginFlow();
        this.oauthService.loadDiscoveryDocumentAndLogin();
    }

    actionTwo() {

        console.log('clientId = ' + this.oauthService.clientId);
        console.log('getAccessToken = ' + this.oauthService.getAccessToken());

        console.table(location.hash.split('&').map(kvp => kvp.split('=')));
    }
  logout() {
      this.oauthService.logOut();
      window.location.href = 'https://sts.someadfsdomain.com/adfs/ls/?wa=wsignoutcleanup1.0';
  }
}

Expected behavior getAccessToken returns access token