From d2908480960b9708460ad71c010ea11e86497968 Mon Sep 17 00:00:00 2001 From: Joachim Van Herwegen Date: Tue, 17 May 2022 09:58:50 +0200 Subject: [PATCH] fix: Accept client WebIDs with a context array --- src/identity/storage/WebIdAdapterFactory.ts | 5 +++-- test/unit/identity/storage/WebIdAdapterFactory.test.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/identity/storage/WebIdAdapterFactory.ts b/src/identity/storage/WebIdAdapterFactory.ts index e4b489c07..6aa17d9c7 100644 --- a/src/identity/storage/WebIdAdapterFactory.ts +++ b/src/identity/storage/WebIdAdapterFactory.ts @@ -51,9 +51,10 @@ export class WebIdAdapter extends PassthroughAdapter { let json: any | undefined; try { json = JSON.parse(data); + const contexts = Array.isArray(json['@context']) ? json['@context'] : [ json['@context'] ]; // We can only parse as simple JSON if the @context is correct - if (json['@context'] !== 'https://www.w3.org/ns/solid/oidc-context.jsonld') { - throw new Error('Invalid context'); + if (!contexts.includes('https://www.w3.org/ns/solid/oidc-context.jsonld')) { + throw new Error('Missing context https://www.w3.org/ns/solid/oidc-context.jsonld'); } } catch (error: unknown) { json = undefined; diff --git a/test/unit/identity/storage/WebIdAdapterFactory.test.ts b/test/unit/identity/storage/WebIdAdapterFactory.test.ts index 9bf1979a8..55d38e572 100644 --- a/test/unit/identity/storage/WebIdAdapterFactory.test.ts +++ b/test/unit/identity/storage/WebIdAdapterFactory.test.ts @@ -85,6 +85,15 @@ describe('A WebIdAdapterFactory', (): void => { }); }); + it('can handle a context array.', async(): Promise => { + json['@context'] = [ json['@context'] ]; + fetchMock.mockResolvedValueOnce({ url: id, status: 200, text: (): string => JSON.stringify(json) }); + await expect(adapter.find(id)).resolves.toEqual({ + ...json, + token_endpoint_auth_method: 'none', + }); + }); + it('errors if there is a client_id mismatch.', async(): Promise => { json.client_id = 'someone else'; fetchMock.mockResolvedValueOnce({ url: id, status: 200, text: (): string => JSON.stringify(json) });