Skip to content

sendAccessToken sends null token when using local storage #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
uzzafar opened this issue Mar 6, 2018 · 4 comments
Closed

sendAccessToken sends null token when using local storage #255

uzzafar opened this issue Mar 6, 2018 · 4 comments

Comments

@uzzafar
Copy link

uzzafar commented Mar 6, 2018

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();
    });
  }
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

@slx2005
Copy link

slx2005 commented Apr 9, 2018

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

@Brototype
Copy link

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

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

@manfredsteyer
Copy link
Owner

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.

@NeelBhatt
Copy link

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

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

You saved my day, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants