![](/img/trans.png)
[英]automaticSilentRenew not working for angular oidc-client library
[英]Auth0 with Angular and 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",
這看起來像是ng-oidc-client
和oidc-client
之間的版本沖突。
ng-oidc-client
期望您提供一個返回WebStorageStateStore
的函數。 但是, Config
的形狀直接來自oidc-client
,它應該是WebStorageStateStore
而不是函數。
直到最近, userStore
字段在oidc-client
被聲明為any
,這允許使用這個技巧。 在 1.10 中,oidc-client 被重構,新的類型是userStore: WebStorageStateStore
。
一個快速的解決方法是提供一個函數——正如 ng-oidc-client 所期望的那樣。 並添加類型斷言以抑制編譯錯誤。
userStore: (() => new WebStorageStateStore({ store: window.localStorage })) as any
也許為ng-oidc-client
提交錯誤報告。 :)
默認配置:
userStore: new WebStorageStateStore({
store: sessionStorage
}),
所以你可以這樣做:
userStore: new WebStorageStateStore({
store: window.localStorage
}),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.