An authentication session manager for OpenID Connect using PKCE.
npm install pkce-spaAn authentication session manager for OpenID Connect using PKCE.
The session manager will keep the user's session permanently active until they
either explicitly logout, or the authentication server denies a refresh attempt.
- Automatic token refresh
- Cross-tab session syncronisation
- Exposes access_token as an event listener
- Zero dependencies
``sh`
$ npm install pkce-spa
`ts
import { Session } from "pkce-spa";
const session = new Session({ ...config });
session.onChange((accessToken) => {
// Start the redirect flow if there isn't an active session
if (accessToken === null) session.login();
});
`
`tsx
const Token = createContext();
function TokenProvider({ children }) {
const [token, setToken] = useState(null);
useEffect(() => session.onChange(setToken), []); // Will clean up effect automatically
return
}
`
See examples for more usage examples.
- Must have authorization_code and refresh_token grant types enablednone`
- Must have token endpoint authentication method set to
- Must have refresh token rotation turned on