Skip to content

Commit 6fb6b6a

Browse files
committed
feat: Support meta credential tokens
1 parent ba9b29c commit 6fb6b6a

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

packages/uma/config/credentials/verifiers/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
{
77
"@id": "urn:uma:default:Verifier",
88
"@type": "TypedVerifier",
9+
"metaType": "urn:solidlab:uma:claims:formats:meta",
910
"verifiers": [
1011
{
1112
"TypedVerifier:_verifiers_key": "urn:solidlab:uma:claims:formats:webid",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

22
export const JWT = 'urn:solidlab:uma:claims:formats:jwt';
33
export const UNSECURE = 'urn:solidlab:uma:claims:formats:webid';
4+
export const META = 'urn:solidlab:uma:claims:formats:meta';
45
export const OIDC = 'http://openid.net/specs/openid-connect-core-1_0.html#IDToken';

packages/uma/src/credentials/verify/TypedVerifier.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@ import { ClaimSet } from "../ClaimSet";
33
import { Credential } from "../Credential";
44
import { Verifier } from "./Verifier";
55

6+
/**
7+
* Redirect verification requests to the relevant verifier by matching the credential format
8+
* to the keys of the internal verifier map.
9+
* In case the credential format is the meta type, it is assumed the value is a key/value map
10+
* with keys being credential formats, and values the associated tokens.
11+
* These results will be merged, if multiple credentials map to the same claim,
12+
* the result will depend on the execution order.
13+
*/
614
export class TypedVerifier implements Verifier {
715
private readonly logger = getLoggerFor(this);
816

9-
constructor(protected verifiers: Record<string, Verifier>) {}
17+
constructor(
18+
protected readonly verifiers: Record<string, Verifier>,
19+
protected readonly metaType?: string,
20+
) {}
1021

1122
public async verify(credential: Credential): Promise<ClaimSet> {
23+
// Recursively verify in case of a meta credential token
24+
if (credential.format === this.metaType) {
25+
const metaClaims = {};
26+
for (const [ format, token ] of Object.entries(credential.token)) {
27+
Object.assign(metaClaims, await this.verify({ format, token }));
28+
}
29+
return metaClaims;
30+
}
31+
1232
const verifier = this.verifiers[credential.format];
1333
this.logger.debug(`Verifying credential with typed verifier ${JSON.stringify(credential)}`);
1434

0 commit comments

Comments
 (0)