0

I have created a new Angular application and I'm working on login with Auth0 but I encountered an issue with oidc-client by getting this error:

main.ts:12 TypeError: clientSettings.userStore is not a function
at new OidcService (ng-oidc-client.js:599)

In my auth.module I have this configuration:

NgOidcClientModule.forRoot({
      // prettier-ignore
      oidc_config: {
        authority: environment.sts.authority,
        client_id: environment.sts.clientId,
        redirect_uri: `${environment.appRoot}oidc-login-redirect-callback.html`,
        scope: 'openid profile',
        response_type: 'id_token token',
        post_logout_redirect_uri: `${environment.appRoot}/oidc-logout-redirect-callback.html`,
        silent_redirect_uri: `${environment.appRoot}/oidc-silent-renew-redirect-callback.html`,
        accessTokenExpiringNotificationTime: 10,
        automaticSilentRenew: true,
        metadata: {
          authorization_endpoint: `${environment.sts.authority}authorize audience=${environment.sts.audience}`,
          userinfo_endpoint: `${environment.sts.authority}userinfo`,
          issuer: environment.sts.authority,
          jwks_uri: `${environment.sts.authority}.well-known/jwks.json`,
          // tslint:disable-next-line: max-line-length
          end_session_endpoint: `${environment.sts.authority}v2/logout?returnTo=${environment.appRootEncoded + 'oidc-logout-redirect-callback.html'}&client_id=${environment.sts.clientId}`
        },
        userStore: new WebStorageStateStore({ store: window.localStorage })
      }
    })

and here is my environment file:

export const environment = {
  production: false,
  appRoot: 'http://localhost:4200',
  appRootEncoded: 'http://localhost:4200',
  apiUrl: 'http://localhost:4201',
  sts: {
    authority: 'https://dev-serj.eu.auth0.com/',
    clientId: 'R7fxgHNkPEj2VX1H7q4Fp0j2XnSqaudJ',
    audience: 'dev-serj-api'
  }
};

I'm more than sure there is a problem with userStore but I can't find a solution to fix it.

My oidc version:

"ng-oidc-client": "^1.0.7",
"oidc-client": "^1.10.1",
4

1 回答 1

2

ng-oidc-client这看起来像和之间的版本冲突oidc-client

ng-oidc-client期望您提供一个返回的函数WebStorageStateStore。然而,形状Config直接来自oidc-client,它应该在哪里WebStorageStateStore而不是一个函数。

直到最近,userStorefield 才被声明为anyin oidc-client,这使得这个技巧成为可能。在 1.10 oidc-client 进行了重组,新的类型是userStore: WebStorageStateStore.

一个快速的解决方法是提供一个函数——正如 ng-oidc-client 所期望的那样。并添加一个类型断言来抑制编译错误。

userStore: (() => new WebStorageStateStore({ store: window.localStorage })) as any

并且可能为ng-oidc-client. :)

于 2019-12-27T23:54:21.630 回答