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",
This looks like version conflict between ng-oidc-client
and oidc-client
.
ng-oidc-client
expects you to provide a function that returns WebStorageStateStore
. However, the shape of Config
comes directly from oidc-client
, where it should be WebStorageStateStore
and not a function.
Until quite recently, userStore
field was declared as any
in oidc-client
, which allowed this trick. In 1.10 oidc-client was restructured, and the new typing is userStore: WebStorageStateStore
.
A quick fix would be to provide a function - just as ng-oidc-client expects. And add a type assertion to suppress compile errors.
userStore: (() => new WebStorageStateStore({ store: window.localStorage })) as any
And perhaps file a bug report for ng-oidc-client
. :)