Unable to use cookie storage to store ID and Access Tokens
Hi,
I am trying to use react-oidc-context with my Idp and wanted to store the tokens in the Cookie Storage. I saw there are options in the oidcConfig with which I can set the userStore to cookie storage . I am using a similar oidcConfig file but the tokens are not getting stored in the cookie storage.
Does react-oidc-context support storing into cookie storage ?
// src/index.jsx
import React from "react";
import ReactDOM from "react-dom";
import { AuthProvider } from "react-oidc-context";
import App from "./App";
const oidcConfig = {
// .... ,
userStore: new WebStorageStateStore({ store: window.cookieStorage}),
// ...
};
ReactDOM.render(
<AuthProvider {...oidcConfig}>
<App />
</AuthProvider>,
document.getElementById("app")
);
The interface of cookieStorage seems different than the direct supported localStorage, thus you cannot use WebStorageStateStore, but you can implement your own WebStorageStateStore and pass that to userStore....
Hi @pamapa , Thanks for the reply. Could you please point me to a reference where I can how I can implement a WebStorageStateStore with cookieStorage
This library is using underneath the library oidc-client-ts. For WebStorageStateStore see here https://github.com/authts/oidc-client-ts/blob/main/src/WebStorageStateStore.ts. You should be able either to exetnd form it and "override" or completely implement your custom class with implementation all public functions of WebStorageStateStore. In order to pass it down to the settings you may need to cast it, like userStore: new CustomWebStorageStateStore(...) as WebStorageStateStore.