1

I am trying to follow the example from this page https://manfredsteyer.github.io/angular-oauth2-oidc/docs/additional-documentation/configure-custom-oauthstorage.html

What I am trying to do is to use localStorage for storing the tokens .

I have followed the article and declared the factory method like this

export function storageFactory() : OAuthStorage {
  console.log('calling factory method');
  return localStorage;
}

And add it in my providers in app.module like this:

@NgModule({
  imports: [ 
    // etc.
    HttpClientModule,
    OAuthModule.forRoot()
  ],
  declarations: [
    AppComponent,
    HomeComponent,
    // etc.
  ],
  bootstrap: [
    AppComponent 
  ],
  providers: [
    { provide: OAuthStorage, useFactory: storageFactory }
  ]
})
export class AppModule {
}

However it still saves tokens into session storage . Also the console.log in my factory method is never displayed and I suspect my factory method is ignored I am using angular14 and version 14 of project. Any ideas what am I missing?

Manos Kounelakis
  • 2,848
  • 5
  • 31
  • 55
  • Funky.... the code you've posted should work. I do [something very similar](https://github.com/jeroenheijmans/sample-angular-oauth2-oidc-with-auth-guards/blob/master/src/app/core/core.module.ts) in my sample, which you could try to clone and compare to your own setup? – Jeroen Jul 22 '23 at 22:31
  • 1
    @Jeroen due to multiple issues with this library probably due to our server config we ended up writing the oauth2 communication from scratch. Also for localStorage to work I think i wrote an app initializer and wrote something like oauthStorage.useStorage(localStorage) – Manos Kounelakis Jul 24 '23 at 06:04

0 Answers0