Cannot retrieve the access token when using silentRenew in angular-auth-oidc-client

Discussão em 'Angular' iniciado por Paul, Janeiro 7, 2025.

  1. Paul

    Paul Guest

    I need to pass the access token to a service each time is obtained, so this is what I did:

    export class AppComponent implements OnInit {

    constructor(
    private eventService: PublicEventsService,
    private oidcSecurityService: OidcSecurityService
    ) { }

    ngOnInit(): void {

    this.eventService.registerForEvents().pipe(
    filter(notification => notification.type === EventTypes.NewAuthenticationResult
    && (notification.value as AuthStateResult)?.isAuthenticated),
    withLatestFrom(this.oidcSecurityService.getAccessToken()),
    map(([_, accessToken]) => accessToken)
    )
    .subscribe(async accessToken => {
    console.log('New access token:', accessToken);
    // This behaves inconsistently for me, sometimes the accessToken is valid, sometimes is null.
    });
    }

    }


    The accessToken is sometimes null, sometimes valid. What am I missing?

    Thanks.

    Angular: version 15
    angular-auth-oidc-client: 15.0.3

    Continue reading...

Compartilhe esta Página