Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/catif.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,53 @@ describe('Common Access Token If', () => {
]
});
});

test('can handle catu in catif', async () => {
const withCatu = CommonAccessTokenIf.fromDict({
exp: [
307,
{
Location: [
'https://auth.example.net/?CAT=',
{
iss: null,
iat: null,
catu: {
scheme: {
'exact-match': 'https'
},
path: {
'prefix-match': '/'
}
}
}
]
},
'abc123'
]
});
expect(withCatu.toDict()).toEqual({
exp: [
307,
{
Location: [
'https://auth.example.net/?CAT=',
{
iss: null,
iat: null,
catu: {
scheme: {
'exact-match': 'https'
},
path: {
'prefix-match': '/'
}
}
}
]
},
'abc123'
]
});
});
});
23 changes: 14 additions & 9 deletions src/catif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,28 @@ const valueToDict: { [key: string]: (value: any) => any } = {
const [code, headers, kid] = value;
const dictHeaders: { [h: string]: any } = {};
headers.forEach((v: any, header: string) => {
dictHeaders[header] = valueToDict[header] ? valueToDict[header](v) : v;
dictHeaders[header] = valueToDict[header.toLowerCase()]
? valueToDict[header.toLowerCase()](v)
: v;
});
return [code, dictHeaders, kid];
},
location: (value) => {
if (typeof value === 'string') {
return { Location: value };
return value;
} else {
const [url, map] = value;
const obj: { [key: string]: any } = {};
(map as Map<string, any>).forEach((v, claim) => {
obj[claim] = valueToDict[claim] ? valueToDict[claim](v) : v;
const label = parseInt(claim);
obj[labelsToClaim[label]] = valueToDict[labelsToClaim[label]]
? valueToDict[labelsToClaim[label]](v)
: v;
});
return { Location: [url, obj] };
return [url, obj];
}
},
catu: (value) => CommonAccessTokenUri.fromUnlabeledMap(value).toDict()
catu: (value) => CommonAccessTokenUri.fromMap(value).toDict()
};

const dictToValue: { [key: string]: (value: any) => any } = {
Expand All @@ -43,8 +48,8 @@ const dictToValue: { [key: string]: (value: any) => any } = {
for (const header in headers) {
map.set(
header,
dictToValue[header]
? dictToValue[header](headers[header])
dictToValue[header.toLowerCase()]
? dictToValue[header.toLowerCase()](headers[header])
: headers[header]
);
}
Expand All @@ -55,10 +60,10 @@ const dictToValue: { [key: string]: (value: any) => any } = {
return value;
} else {
const [url, dict] = value;
const lmap = new Map<string, any>();
const lmap = new Map<number, any>();
for (const key in dict) {
lmap.set(
key,
claimsToLabels[key],
dictToValue[key] ? dictToValue[key](dict[key]) : dict[key]
);
}
Expand Down
16 changes: 15 additions & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,21 @@ describe('CAT', () => {
exp: [
307,
{
Location: 'https://auth.example.net'
Location: [
'https://auth.example.net?CAT=',
{
iss: null,
iat: null,
catu: {
scheme: {
'exact-match': 'https'
},
path: {
'prefix-match': '/'
}
}
}
]
}
]
},
Expand Down
Loading