Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(oauth): get claims from token now return authorization_details #157

Merged
merged 1 commit into from
Jun 20, 2024
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
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
Loading