Skip to content

Commit

Permalink
refactor(oauth): getClaims from token now return authorization_details (
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaSelvaggini authored Jun 20, 2024
1 parent 42bc5b8 commit b2af415
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
11 changes: 2 additions & 9 deletions pkg/oauth/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,20 +519,13 @@ export class InMemoryCache implements AuthorizationCodeModel {

}

async getClaimsFromToken(accessToken: string) {
async getAuthDetailsFromToken(accessToken: string) {
const token = await this.getAccessToken(accessToken);
if (!token) throw new InvalidTokenError("Given token is not valid");
const auth_details = token['authorization_details'];
if (!auth_details) throw new InvalidTokenError("authorization_details not found in accessToken");
var claims: { [key: string]: any }[] = [];
auth_details.map((dict: { [key: string]: any }) => {
delete dict['type'];
delete dict['locations'];
delete dict['credential_configuration_id'];
claims.push(dict);
});

return claims;
return auth_details;
}
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/oauth/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,19 @@ export const createRequestUri = p.new(
*/
//Sentence that given an access token return the authorization_details
/**
Given I send token 'token' and send server_data 'server' and get claims from token and output into 'claims'
Given I send token 'token' and send server_data 'server' and get authorization details from token and output into 'claims'
Input:
server_data: MUST be a string dictionary with keys
jwk: JWK containing the public key of the authorization_server
url: url of the authorization_server
authentication_url: did resolver for client pk
token: MUST be a string representing a valid access_token
Output:
claims: string array of the authorization_details linked to the access_token (without `locations` and `credentail_configuration_id`)
claims: string array of the authorization_details linked to the access_token
*/
export const getClaims = p.new(
['token', 'server_data'],
'get claims from token',
'get authorization details from token',
async (ctx) => {
const serverData = ctx.fetch('server_data') as { jwk: JWK, url: string, authenticationUrl: string };
const accessToken = ctx.fetch('token') as string;
Expand All @@ -371,7 +371,7 @@ export const getClaims = p.new(

let res
try {
res = await model.getClaimsFromToken(accessToken);
res = await model.getAuthDetailsFromToken(accessToken);
} catch(e) {
return ctx.fail(new OauthError(e.message));
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/oauth/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Then print data
const scriptGetClaims = `
Rule unknown ignore
Given I send token 'token' and send server_data 'server' and get claims from token and output into 'claims'
Given I send token 'token' and send server_data 'server' and get authorization details from token and output into 'claims'
Given I have a 'string array' named 'claims'
Then print data
Expand Down

0 comments on commit b2af415

Please sign in to comment.