Skip to content

Commit 0c0bbf6

Browse files
committed
chore: merge from main
Signed-off-by: Wouter Termont <wouter.termont@ugent.be>
2 parents ee858e2 + 94e8cf4 commit 0c0bbf6

8 files changed

Lines changed: 1187 additions & 1350 deletions

File tree

packages/css/config/uma/default.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
"baseUrl": {
3939
"@id": "urn:solid-server:default:variable:baseUrl"
4040
},
41+
"umaIdStore": {
42+
"@id": "urn:solid-server:default:UmaIdStore",
43+
"@type": "MemoryMapStorage"
44+
},
4145
"keyGen": {
4246
"@id": "urn:solid-server:default:JwkGenerator"
4347
},
@@ -73,10 +77,6 @@
7377
"store": {
7478
"@id": "urn:solid-server:default:ResourceStore"
7579
},
76-
"umaIdStore": {
77-
"@id": "urn:solid-server:default:UmaIdStore",
78-
"@type": "MemoryMapStorage"
79-
},
8080
"ownerUtil": {
8181
"@id": "urn:solid-server:default:OwnerUtil"
8282
},

packages/css/src/identity/configuration/InMemoryJwksKeyHolder.ts

Lines changed: 0 additions & 140 deletions
This file was deleted.

packages/css/src/identity/configuration/JwksKeyHolder.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 12 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,38 @@
1-
import type { ResourceIdentifier, MonitoringStore, KeyValueStorage } from '@solid/community-server';
1+
import type { UmaClient } from '../uma/UmaClient';
2+
import type { ResourceIdentifier, MonitoringStore } from '@solid/community-server';
23
import { AS, getLoggerFor, StaticHandler } from '@solid/community-server';
34
import { OwnerUtil } from '../util/OwnerUtil';
4-
import { ResourceDescription } from '@solidlab/uma';
5-
import type { UmaClient } from '../uma/UmaClient';
65

76
export class ResourceRegistrar extends StaticHandler {
87
protected readonly logger = getLoggerFor(this);
98

109
public constructor(
1110
protected store: MonitoringStore,
12-
protected umaIdStore: KeyValueStorage<string, string>,
1311
protected ownerUtil: OwnerUtil,
1412
protected umaClient: UmaClient,
1513
) {
1614
super();
1715

1816
store.on(AS.Create, async (resource: ResourceIdentifier): Promise<void> => {
19-
const owners = await this.ownerUtil.findOwners(resource).catch(() => []);
20-
for (const owner of owners) this.createResource(resource, owner);
17+
for (const owner of await this.findOwners(resource)) {
18+
this.umaClient.createResource(resource, await this.findIssuer(owner));
19+
}
2120
});
2221

2322
store.on(AS.Delete, async (resource: ResourceIdentifier): Promise<void> => {
24-
const owners = await this.ownerUtil.findOwners(resource).catch(() => []);
25-
for (const owner of owners) this.deleteResource(resource, owner);
23+
for (const owner of await this.findOwners(resource)) {
24+
this.umaClient.deleteResource(resource, await this.findIssuer(owner));
25+
}
2626
});
2727
}
2828

29-
protected async createResource(resource: ResourceIdentifier, owner: string): Promise<void> {
30-
const issuer = await this.ownerUtil.findIssuer(owner);
31-
32-
if (!issuer) throw new Error(`Could not find UMA AS for resource owner ${owner}`);
33-
34-
const { resource_registration_endpoint: endpoint } = await this.umaClient.fetchUmaConfig(issuer);
35-
36-
const description: ResourceDescription = {
37-
resource_scopes: [
38-
'urn:example:css:modes:read',
39-
'urn:example:css:modes:append',
40-
'urn:example:css:modes:create',
41-
'urn:example:css:modes:delete',
42-
'urn:example:css:modes:write',
43-
]
44-
};
45-
46-
this.logger.info(`Creating resource registration for <${resource.path}> at <${endpoint}>`);
47-
48-
const request = {
49-
url: endpoint,
50-
method: 'POST',
51-
headers: {
52-
'Content-Type': 'application/json',
53-
'Accept': 'application/json',
54-
},
55-
body: JSON.stringify(description),
56-
};
57-
58-
// do not await - registration happens in background to cope with errors etc.
59-
this.umaClient.signedFetch(endpoint, request).then(async resp => {
60-
if (resp.status !== 201) {
61-
throw new Error (`Resource registration request failed. ${await resp.text()}`);
62-
}
63-
64-
const { _id: umaId } = await resp.json();
65-
66-
if (!umaId || typeof umaId !== 'string') {
67-
throw new Error ('Unexpected response from UMA server; no UMA id received.');
68-
}
69-
70-
this.umaIdStore.set(resource.path, umaId);
71-
}).catch(error => {
72-
// TODO: Do something useful on error
73-
this.logger.warn(
74-
`Something went wrong during UMA resource registration to create ${resource.path}: ${(error as Error).message}`
75-
);
76-
});
29+
private async findOwners(resource: ResourceIdentifier): Promise<string[]> {
30+
return await this.ownerUtil.findOwners(resource).catch(() => []);
7731
}
7832

79-
protected async deleteResource(resource: ResourceIdentifier, owner: string): Promise<void> {
33+
private async findIssuer(owner: string): Promise<string> {
8034
const issuer = await this.ownerUtil.findIssuer(owner);
81-
8235
if (!issuer) throw new Error(`Could not find UMA AS for resource owner ${owner}`);
83-
84-
const { resource_registration_endpoint: endpoint } = await this.umaClient.fetchUmaConfig(issuer);
85-
86-
this.logger.info(`Deleting resource registration for <${resource.path}> at <${endpoint}>`);
87-
88-
const umaId = await this.umaIdStore.get(resource.path);
89-
const url = `${endpoint}/${umaId}`;
90-
91-
const request = {
92-
url,
93-
method: 'DELETE',
94-
headers: {}
95-
};
96-
97-
// do not await - registration happens in background to cope with errors etc.
98-
this.umaClient.signedFetch(endpoint, request).then(async _resp => {
99-
if (!umaId) throw new Error('Trying to delete unknown/unregistered resource; no UMA id found.');
100-
101-
await this.umaClient.signedFetch(url, request);
102-
}).catch(error => {
103-
// TODO: Do something useful on error
104-
this.logger.warn(
105-
`Something went wrong during UMA resource registration to delete ${resource.path}: ${(error as Error).message}`
106-
);
107-
});
36+
return issuer;
10837
}
10938
}

0 commit comments

Comments
 (0)