Skip to content

Commit

Permalink
[email protected] Add option to provide OIDC cookie name
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Morrison committed Oct 1, 2023
1 parent 94059ee commit 6b96480
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions packages/services/f-consumer-oidc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

v1.4.2
------------------------------
* October 1, 2023*

### Added
- Ability to provide your own OIDC cookie name


v1.4.1
------------------------------
Expand Down
3 changes: 2 additions & 1 deletion packages/services/f-consumer-oidc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The exports are:

This function attempts to get a valid JWT for the current user. It works as follows:

* it stores the token in a cookie (`je-oidc`), so if the user has already done this in their session it will retrieve that
* it stores the token in a cookie (`oidcSettings.cookie_name`), so if the user has already done this in their session it will retrieve that
* for the page lifetime (i.e. JS variable) it remembers if the user is not logged in, so that it doesn't attempt to get a token repeatedly
* by default it will silently refresh the token close to its expiry time, if possible. This functionality is built in to [`oidc-client`](https://github.com/IdentityModel/oidc-client-js/wiki).
* you should set the `silentRequestTimeout` setting to a low value, to avoid blocking UI components. By default this is a a very high value - 100 seconds.
Expand All @@ -83,6 +83,7 @@ Usage:
import { silentSignIn } from `@justeat/f-consumer-oidc`;

const oidcSettings = {
cookie_name: 'my-cookie-name',
silentRequestTimeout: 2000
};

Expand Down
2 changes: 1 addition & 1 deletion packages/services/f-consumer-oidc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@justeat/f-consumer-oidc",
"version": "1.4.1",
"version": "1.4.2",
"description": "Authentication helper to communicate with open apis",
"main": "dist/f-consumer-oidc.umd.js",
"module": "dist/f-consumer-oidc.es.js",
Expand Down
5 changes: 3 additions & 2 deletions packages/services/f-consumer-oidc/src/user-manager-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ export function userManagerFactory ({ UserManager }, settings) {
const root = `${location.protocol}//${location.host}`;

function getCookieData () {
return Cookies.getJSON('je-oidc') || {};
return Cookies.getJSON(settings.cookie_name) || {};
}

function setCookieData (obj) {
Cookies.set('je-oidc', obj); // TODO: expiry
Cookies.set(settings.cookie_name, obj); // TODO: expiry
}

const userStore = {
Expand Down Expand Up @@ -45,6 +45,7 @@ export function userManagerFactory ({ UserManager }, settings) {
const defaultSettings = {
authority: root,
client_id: 'je_web_native',
cookie_name: 'je-oidc', // Default cookie name
response_type: 'code',
scope: 'openid mobile_scope offline_access',
silent_redirect_uri: `${root}/tokenweb/content/silent-callback.html`,
Expand Down

0 comments on commit 6b96480

Please sign in to comment.