Skip to content

Commit dd09ce7

Browse files
committed
auth state selector should check non-image resources
- IIIF Auth2 services will be members of a probe service - #3789
1 parent e486f54 commit dd09ce7

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

__tests__/src/selectors/auth.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import manifestFixture001 from '../../fixtures/version-2/001.json';
22
import manifestFixture019 from '../../fixtures/version-2/019.json';
3+
import manifestFixtureAuth2ActiveVideo from '../../fixtures/version-3/auth2-active.json';
34
import settings from '../../../src/config/settings';
45
import {
56
getAccessTokens,
@@ -61,6 +62,9 @@ describe('selectCurrentAuthServices', () => {
6162
b: {
6263
json: manifestFixture019,
6364
},
65+
c: {
66+
json: manifestFixtureAuth2ActiveVideo,
67+
},
6468
},
6569
windows: {
6670
noCanvas: {
@@ -84,6 +88,12 @@ describe('selectCurrentAuthServices', () => {
8488
'https://purl.stanford.edu/fr426cg9537/iiif/canvas/fr426cg9537_1',
8589
],
8690
},
91+
z: {
92+
manifestId: 'c',
93+
visibleCanvases: [
94+
'https://auth.example.org/my-video1',
95+
],
96+
},
8797
},
8898
};
8999

@@ -93,6 +103,7 @@ describe('selectCurrentAuthServices', () => {
93103

94104
it('returns the next auth service to try', () => {
95105
expect(selectCurrentAuthServices(state, { windowId: 'w' })[0].id).toEqual('external');
106+
expect(selectCurrentAuthServices(state, { windowId: 'z' })[0].id).toEqual('https://auth.example.org/login');
96107
});
97108

98109
it('returns the service if the next auth service is interactive', () => {

src/state/selectors/auth.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { createSelector } from 'reselect';
22
import { Utils } from 'manifesto.js';
33
import flatten from 'lodash/flatten';
4+
import {
5+
audioResourcesFrom, filterByTypes, textResourcesFrom, videoResourcesFrom,
6+
} from '../../lib/typeFilters';
47
import MiradorCanvas from '../../lib/MiradorCanvas';
58
import { miradorSlice } from './utils';
69
import { getConfig } from './config';
@@ -48,15 +51,27 @@ export const selectCurrentAuthServices = createSelector(
4851
}));
4952
}
5053

54+
if (currentAuthResources.length === 0 && canvases) {
55+
currentAuthResources = flatten(canvases.map(c => {
56+
const miradorCanvas = new MiradorCanvas(c);
57+
const canvasResources = miradorCanvas.imageResources;
58+
return videoResourcesFrom(canvasResources)
59+
.concat(audioResourcesFrom(canvasResources))
60+
.concat(textResourcesFrom(canvasResources));
61+
}));
62+
}
63+
5164
if (!currentAuthResources) return [];
5265
if (currentAuthResources.length === 0) return [];
5366

5467
const currentAuthServices = currentAuthResources.map(resource => {
5568
let lastAttemptedService;
56-
const services = Utils.getServices(resource);
69+
const resourceServices = Utils.getServices(resource);
70+
const probeServices = filterByTypes(resourceServices, 'AuthProbeService2');
71+
const probeServiceServices = flatten(probeServices.map(p => Utils.getServices(p)));
5772

5873
for (const authProfile of serviceProfiles) {
59-
const profiledAuthServices = services.filter(
74+
const profiledAuthServices = resourceServices.concat(probeServiceServices).filter(
6075
p => authProfile.profile === p.getProfile(),
6176
);
6277

0 commit comments

Comments
 (0)