首页 > 解决方案 > ng-oidc-client:clientSettings.userStore 不是函数

问题描述

遵循设置指南时,我clientSettings.userStore is not a function在加载页面时得到。

我复制了 oidc_config 对象,并简单地更改了权限:

StoreModule.forRoot({}),
EffectsModule.forRoot([]),
NgOidcClientModule.forRoot({
    oidc_config: {
        authority: 'http://localhost:49853/',
        client_id: 'ng-oidc-client-identity',
        redirect_uri: 'http://localhost:49853/callback.html',
        response_type: 'id_token token',
        scope: 'openid profile offline_access api1',
        post_logout_redirect_uri: 'http://localhost:49853/signout-callback.html',
        silent_redirect_uri: 'http://localhost:49853/renew-callback.html',
        accessTokenExpiringNotificationTime: 10,
        automaticSilentRenew: true,
        userStore: new WebStorageStateStore({ store: window.localStorage })
    },
    log: {
        logger: console,
        level: Log.NONE
    }
})

并添加了相应的资产文件:

    "assets": [
      "src/favicon.ico",
      "src/assets",
      {
        "glob": "**/*",
        "input": "src/static",
        "output": "/"
      },
      {
        "glob": "oidc-client.min.js",
        "input": "node_modules/oidc-client/dist",
        "output": "/"
      }
    ],

版本:

"@ngrx/effects": "7.4.0",
"@ngrx/store": "7.4.0",
"ng-oidc-client": "1.0.5",
"oidc-client": "^1.9.1"

堆栈闪电战

我已经尝试修改版本控制,因为我正在运行 Angular 7,但 npm 默认情况下会在 8 上安装依赖项。但是到目前为止似乎没有任何工作。

标签: angularauthenticationopenid-connect

解决方案


您需要提供用户存储作为这样的功能。

export function getWebStorageStateStore() {
  return new WebStorageStateStore({ store: window.localStorage });
}

NgOidcClientModule.forRoot({
    oidc_config: {
        authority: 'http://localhost:49853/',
        client_id: 'ng-oidc-client-identity',
        redirect_uri: 'http://localhost:49853/callback.html',
        response_type: 'id_token token',
        scope: 'openid profile offline_access api1',
        post_logout_redirect_uri: 'http://localhost:49853/signout-callback.html',
        silent_redirect_uri: 'http://localhost:49853/renew-callback.html',
        accessTokenExpiringNotificationTime: 10,
        automaticSilentRenew: true,
        userStore: getWebStorageStateStore
    },
    log: {
        logger: console,
        level: Log.NONE
    }
}


推荐阅读