Skip to content

Commit

Permalink
[data-model] fix: client id document uses jsonld
Browse files Browse the repository at this point in the history
closes #81

Co-authored-by: elf Pavlik <[email protected]>
  • Loading branch information
samurex and elf-pavlik committed Mar 18, 2024
1 parent 1785a97 commit bd57479
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
9 changes: 8 additions & 1 deletion packages/data-model/src/readable/client-id-document.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OIDC } from '@janeirodigital/interop-utils';
import { OIDC, parseJsonld } from '@janeirodigital/interop-utils';
import { InteropFactory } from '..';
import { ReadableResource } from './resource';

Expand Down Expand Up @@ -28,4 +28,11 @@ export class ReadableClientIdDocument extends ReadableResource {
await instance.bootstrap();
return instance;
}

protected async fetchData(): Promise<void> {
const response = await this.fetch.raw(this.iri, {
headers: { Accept: 'application/ld+json' }
});
this.dataset = await parseJsonld(await response.text(), response.url);
}
}
31 changes: 27 additions & 4 deletions packages/data-model/test/readable/client-id-document-test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
import { fetch } from '@janeirodigital/interop-test-utils';
import { randomUUID } from 'crypto';
import { RdfFetch } from '@janeirodigital/interop-utils';
import { AuthorizationAgentFactory } from '../../src';

const webId = 'https://alice.example/#id';
const agentId = 'https://jarvis.alice.example/#agent';
const snippetIri = 'http://localhost:3000/acme/projectron/id';
const snippetText = `
{
"@context": [
"https://www.w3.org/ns/solid/oidc-context.jsonld",
{
"interop": "http://www.w3.org/ns/solid/interop#"
}
] ,
"client_id": "http://localhost:3000/acme/projectron/id",
"client_name": "Projectron",
"logo_uri": "https://robohash.org/https://projectron.example/?set=set3",
"redirect_uris": ["http://localhost:4100/redirect"],
"grant_types" : ["refresh_token","authorization_code"],
"interop:hasAccessNeedGroup": "http://localhost:3000/acme/projectron/access-needs#need-group-pm",
"interop:hasAuthorizationCallbackEndpoint": "http://localhost:4100"
}
`;
const fetch = {
raw: async () => ({ text: async () => snippetText })
} as unknown as RdfFetch;

const factory = new AuthorizationAgentFactory(webId, agentId, { fetch, randomUUID });
const snippetIri = 'https://projectron.example/#app';

describe('getters', () => {
test('hasAccessNeedGroup', async () => {
const clientIdDocument = await factory.readable.clientIdDocument(snippetIri);
expect(clientIdDocument.hasAccessNeedGroup).toBe('https://projectron.example/access-needs#need-group-pm');
expect(clientIdDocument.hasAccessNeedGroup).toBe(
'http://localhost:3000/acme/projectron/access-needs#need-group-pm'
);
});
test('callbackEndpoint', async () => {
const clientIdDocument = await factory.readable.clientIdDocument(snippetIri);
expect(clientIdDocument.callbackEndpoint).toBe('https://projectron.example/');
expect(clientIdDocument.callbackEndpoint).toBe('http://localhost:4100');
});

test('clientName', async () => {
Expand Down

0 comments on commit bd57479

Please sign in to comment.