Skip to content

Commit

Permalink
chore: return unencrypted state value along with jarm response
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Dec 11, 2024
1 parent dd8528d commit 61a14e6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { appendFragmentParams, appendQueryParams } from '../utils.js';
import type { JarmResponseMode, Openid4vpJarmResponseMode } from '../v-response-mode-registry.js';
import { getJarmDefaultResponseMode, validateResponseMode } from '../v-response-mode-registry.js';
import type { ResponseTypeOut } from '../v-response-type-registry.js';
import { appendFragmentParams, appendQueryParams } from '../utils.js'

Check warning on line 1 in packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts

View check run for this annotation

Codecov / codecov/patch

packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts#L1

Added line #L1 was not covered by tests
import type { JarmResponseMode, Openid4vpJarmResponseMode } from '../v-response-mode-registry.js'
import { getJarmDefaultResponseMode, validateResponseMode } from '../v-response-mode-registry.js'

Check warning on line 3 in packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts

View check run for this annotation

Codecov / codecov/patch

packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts#L3

Added line #L3 was not covered by tests
import type { ResponseTypeOut } from '../v-response-type-registry.js'

interface JarmAuthResponseSendInput {
authRequestParams: {
Expand All @@ -17,10 +17,11 @@ interface JarmAuthResponseSendInput {
);

authResponse: string;
state: string;
}

export const jarmAuthResponseSend = async (input: JarmAuthResponseSendInput): Promise<Response> => {
const { authRequestParams, authResponse } = input;
const { authRequestParams, authResponse, state } = input;

Check warning on line 24 in packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts

View check run for this annotation

Codecov / codecov/patch

packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts#L24

Added line #L24 was not covered by tests

const responseEndpoint = 'response_uri' in authRequestParams ? new URL(authRequestParams.response_uri) : new URL(authRequestParams.redirect_uri);

Expand All @@ -36,40 +37,39 @@ export const jarmAuthResponseSend = async (input: JarmAuthResponseSendInput): Pr

switch (responseMode) {
case 'direct_post.jwt':
return handleDirectPostJwt(responseEndpoint, authResponse);
return handleDirectPostJwt(responseEndpoint, authResponse, state);

Check warning on line 40 in packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts

View check run for this annotation

Codecov / codecov/patch

packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts#L40

Added line #L40 was not covered by tests
case 'query.jwt':
return handleQueryJwt(responseEndpoint, authResponse);
return handleQueryJwt(responseEndpoint, authResponse, state);

Check warning on line 42 in packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts

View check run for this annotation

Codecov / codecov/patch

packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts#L42

Added line #L42 was not covered by tests
case 'fragment.jwt':
return handleFragmentJwt(responseEndpoint, authResponse);
return handleFragmentJwt(responseEndpoint, authResponse, state);

Check warning on line 44 in packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts

View check run for this annotation

Codecov / codecov/patch

packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts#L44

Added line #L44 was not covered by tests
case 'form_post.jwt':
throw new Error('Not implemented. form_post.jwt is not yet supported.');
}
};

async function handleDirectPostJwt(responseEndpoint: URL, responseJwt: string) {
const response = await fetch(responseEndpoint, {
async function handleDirectPostJwt(responseEndpoint: URL, responseJwt: string, state: string) {
const response = await fetch(responseEndpoint, {

Check warning on line 51 in packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts

View check run for this annotation

Codecov / codecov/patch

packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts#L50-L51

Added lines #L50 - L51 were not covered by tests
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `response=${responseJwt}`,
});

body: `response=${responseJwt}&state=${state}`
})
return response;
}

async function handleQueryJwt(responseEndpoint: URL, responseJwt: string) {
async function handleQueryJwt(responseEndpoint: URL, responseJwt: string, state: string) {

Check warning on line 59 in packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts

View check run for this annotation

Codecov / codecov/patch

packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts#L59

Added line #L59 was not covered by tests
const responseUrl = appendQueryParams({
url: responseEndpoint,
params: { response: responseJwt },
params: { response: responseJwt, state },
});

const response = await fetch(responseUrl, { method: 'POST' });
return response;
}

async function handleFragmentJwt(responseEndpoint: URL, responseJwt: string) {
async function handleFragmentJwt(responseEndpoint: URL, responseJwt: string, state: string) {

Check warning on line 69 in packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts

View check run for this annotation

Codecov / codecov/patch

packages/jarm/lib/jarm-auth-response-send/jarm-auth-response-send.ts#L69

Added line #L69 was not covered by tests
const responseUrl = appendFragmentParams({
url: responseEndpoint,
fragments: { response: responseJwt },
fragments: { response: responseJwt, state },
});
const response = await fetch(responseUrl, { method: 'POST' });
return response;
Expand Down
1 change: 1 addition & 0 deletions packages/siop-oid4vp/lib/op/OP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export class OP {
response_type: responseType,
},
authResponse: response,
state: requestObjectPayload.state
})
void this.emitEvent(AuthorizationEvents.ON_AUTH_RESPONSE_SENT_SUCCESS, { correlationId, subject: response })
return jarmResponse
Expand Down

0 comments on commit 61a14e6

Please sign in to comment.