Angular-oauth2-oidc: sendAccessToken sends null token when using local storage

Created on 6 Mar 2018  路  4Comments  路  Source: manfredsteyer/angular-oauth2-oidc

sendAccessToken is sending null token when using local storage
here is my configuration

import { AuthConfig } from 'angular-oauth2-oidc';

export const authConfig: AuthConfig = {
  issuer: '',
  redirectUri: window.location.origin + '/home',
  silentRefreshRedirectUri: window.location.origin + '/assets/silent-refresh.html',
  clientId: '',
  dummyClientSecret: '',
  scope: '',
  strictDiscoveryDocumentValidation: false,
  oidc: false
}
private configureWithNewConfigApi() {
    this.oauthService.configure(authConfig);
    this.oauthService.setStorage(localStorage);
    this.oauthService.tokenValidationHandler = new JwksValidationHandler();
    this.oauthService.loadDiscoveryDocument('').then(() => {
      this.oauthService.tryLogin();
      this.oauthService.setupAutomaticSilentRefresh();
    });
  }



md5-1e1ffcd102308d6ad3e689fff3c8ca9b



OAuthModule.forRoot({
      resourceServer: {
        allowedUrls: [''],
        sendAccessToken: true
      }
    })

when I remove this.oauthService.setStorage(localStorage) it is working fine as expected

can you please look into this issue asap

Most helpful comment

You could also (as a workaround) do this in you app module

...
    providers: [
    ...
       { provide: OAuthStorage, useValue: localStorage },
    ...
    ]
....

All 4 comments

I have this issue too, whilst debugging the issue, looks like when angular-oauth2-oidc configures the DefaultOAuthInterceptor it uses 'sessionStorage', ignoring the set storage 'localStorage', a work around is to register an interceptor manually

You could also (as a workaround) do this in you app module

...
    providers: [
    ...
       { provide: OAuthStorage, useValue: localStorage },
    ...
    ]
....

Thanks for this hint. I would consider this the official solution. setStorage is there only for legacy reasons to prevent breaking existing code. But using DI is the way to go.

You could also (as a workaround) do this in you app module

...
    providers: [
    ...
       { provide: OAuthStorage, useValue: localStorage },
    ...
    ]
....

You saved my day, thanks.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zulander1 picture zulander1  路  4Comments

godhar picture godhar  路  3Comments

CharlyRipp picture CharlyRipp  路  3Comments

grzegorz-skowronski picture grzegorz-skowronski  路  3Comments

Maximaximum picture Maximaximum  路  3Comments