带有Angular和Oidc客户端的Auth0

时间:2019-12-27 23:11:28

标签: angular auth0 oidc-client

我已经创建了一个新的Angular应用程序,并且正在使用Auth0登录,但是遇到此错误,我遇到了 oidc-client 问题:

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

在我的 auth.module 中,我具有以下配置:

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

这是我的环境文件:

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'
  }
};

我非常确定 userStore 存在问题,但是我找不到解决该问题的解决方案。

我的oidc版本:

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

1 个答案:

答案 0 :(得分:1)

这似乎是ng-oidc-clientoidc-client之间的版本冲突。

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

直到最近,userStore中的any字段都被声明为oidc-client,这才允许使用此技巧。在1.10版本中,oidc-client进行了重组,新的类型为userStore: WebStorageStateStore

一个快速解决方案是提供一个功能-就像ng-oidc-client期望的那样。并添加类型断言以抑制编译错误。

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

也许提交ng-oidc-client的错误报告。 :)