From 1c5c461753d0cde26170006f23234a7da59c5b59 Mon Sep 17 00:00:00 2001 From: Chris Beer <cabeer@stanford.edu> Date: Wed, 16 Sep 2020 10:10:27 -0700 Subject: [PATCH] Support IIIF Auth v0.9 --- src/config/settings.js | 4 ++++ src/containers/IIIFAuthentication.js | 2 ++ src/state/sagas/auth.js | 9 ++++++--- src/state/sagas/iiif.js | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/config/settings.js b/src/config/settings.js index 0c40de205..abea8f9fe 100644 --- a/src/config/settings.js +++ b/src/config/settings.js @@ -344,6 +344,10 @@ export default { { profile: 'http://iiif.io/api/auth/1/kiosk', kiosk: true }, { profile: 'http://iiif.io/api/auth/1/clickthrough' }, { profile: 'http://iiif.io/api/auth/1/login' }, + { profile: 'http://iiif.io/api/auth/0/external', external: true }, + { profile: 'http://iiif.io/api/auth/0/kiosk', kiosk: true }, + { profile: 'http://iiif.io/api/auth/0/clickthrough' }, + { profile: 'http://iiif.io/api/auth/0/login' } ] } }; diff --git a/src/containers/IIIFAuthentication.js b/src/containers/IIIFAuthentication.js index ba2eb5aed..819796c8c 100644 --- a/src/containers/IIIFAuthentication.js +++ b/src/containers/IIIFAuthentication.js @@ -23,9 +23,11 @@ const mapStateToProps = (state, { windowId }) => { const accessTokenService = service && ( Utils.getService(service, 'http://iiif.io/api/auth/1/token') + || Utils.getService(service, 'http://iiif.io/api/auth/0/token') ); const logoutService = service && ( Utils.getService(service, 'http://iiif.io/api/auth/1/logout') + || Utils.getService(service, 'http://iiif.io/api/auth/0/logout') ); const authStatuses = getAuth(state) || {}; diff --git a/src/state/sagas/auth.js b/src/state/sagas/auth.js index 5f99c8c85..21135885e 100644 --- a/src/state/sagas/auth.js +++ b/src/state/sagas/auth.js @@ -52,7 +52,8 @@ export function* refetchInfoResponses({ serviceId }) { const haveThisTokenService = infoResponse => { const services = Utils.getServices(infoResponse); return services.some(e => { - const infoTokenService = Utils.getService(e, 'http://iiif.io/api/auth/1/token'); + const infoTokenService = Utils.getService(e, 'http://iiif.io/api/auth/1/token') + || Utils.getService(e, 'http://iiif.io/api/auth/0/token'); return infoTokenService && infoTokenService.id === serviceId; }); }; @@ -89,7 +90,8 @@ export function* doAuthWorkflow({ infoJson, windowId }) { // start the auth yield put(addAuthenticationRequest(windowId, authService.id, authService.getProfile())); } else if (profileConfig.external) { - const tokenService = Utils.getService(authService, 'http://iiif.io/api/auth/1/token'); + const tokenService = Utils.getService(authService, 'http://iiif.io/api/auth/1/token') + || Utils.getService(authService, 'http://iiif.io/api/auth/0/token'); if (!tokenService) return; // resolve the auth @@ -105,7 +107,8 @@ export function* rerequestOnAccessTokenFailure({ infoJson, windowId, tokenServic // make sure we have an auth service to try const authService = Utils.getServices(infoJson).find(service => { - const tokenService = Utils.getService(service, 'http://iiif.io/api/auth/1/token'); + const tokenService = Utils.getService(service, 'http://iiif.io/api/auth/1/token') + || Utils.getService(service, 'http://iiif.io/api/auth/0/token'); return tokenService && tokenService.id === tokenServiceId; }); diff --git a/src/state/sagas/iiif.js b/src/state/sagas/iiif.js index 9f5334235..f0ce4c537 100644 --- a/src/state/sagas/iiif.js +++ b/src/state/sagas/iiif.js @@ -126,7 +126,8 @@ function* getAccessTokenService(resource) { for (let i = 0; i < services.length; i += 1) { const authService = services[i]; - const accessTokenService = Utils.getService(authService, 'http://iiif.io/api/auth/1/token'); + const accessTokenService = Utils.getService(authService, 'http://iiif.io/api/auth/1/token') + || Utils.getService(authService, 'http://iiif.io/api/auth/0/token'); const token = accessTokenService && accessTokens[accessTokenService.id]; if (token && token.json) return token; } -- GitLab