From b2af415d13ef3830f1fe697495116f93ffd0d3c9 Mon Sep 17 00:00:00 2001 From: RebeccaSelvaggini <115783755+RebeccaSelvaggini@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:43:02 +0200 Subject: [PATCH] refactor(oauth): getClaims from token now return authorization_details (#157) --- pkg/oauth/src/model.ts | 11 ++--------- pkg/oauth/src/plugin.ts | 8 ++++---- pkg/oauth/test/e2e.ts | 2 +- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/pkg/oauth/src/model.ts b/pkg/oauth/src/model.ts index 44d806b8..ff61fe67 100644 --- a/pkg/oauth/src/model.ts +++ b/pkg/oauth/src/model.ts @@ -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; } } diff --git a/pkg/oauth/src/plugin.ts b/pkg/oauth/src/plugin.ts index fe20ed60..f185e965 100644 --- a/pkg/oauth/src/plugin.ts +++ b/pkg/oauth/src/plugin.ts @@ -343,7 +343,7 @@ 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 @@ -351,11 +351,11 @@ Input: 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; @@ -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)); } diff --git a/pkg/oauth/test/e2e.ts b/pkg/oauth/test/e2e.ts index aa0d5c7a..e6ad8718 100644 --- a/pkg/oauth/test/e2e.ts +++ b/pkg/oauth/test/e2e.ts @@ -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