Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

fix: pass params in url for introspect jwt flow #48

Merged
merged 2 commits into from
Aug 5, 2021
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
1 change: 0 additions & 1 deletion src/smartAuthorizationHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ describe('introspectJwtToken', () => {
introspectJwtToken(jwt, expectedAudValue, expectedIssValue, introspectionOptions),
).resolves.toEqual({
...payload,
active: true,
});
});

Expand Down
22 changes: 9 additions & 13 deletions src/smartAuthorizationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export async function introspectJwtToken(
introspectionOptions: IntrospectionOptions,
) {
// used to verify if `iss` or `aud` is valid
decodeJwtToken(token, expectedAudValue, expectedIssValue);
const decodedTokenPayload = decodeJwtToken(token, expectedAudValue, expectedIssValue).payload;
const { introspectUrl, clientId, clientSecret } = introspectionOptions;

// setup basic authentication
Expand All @@ -221,22 +221,18 @@ export async function introspectJwtToken(
const auth = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`;

try {
const response = await axios.post(
introspectUrl,
{ token },
{
headers: {
'content-type': 'application/x-www-form-urlencoded',
accept: 'application/json',
authorization: auth,
'cache-control': 'no-cache',
},
const response = await axios.post(introspectUrl, `token=${token}`, {
headers: {
'content-type': 'application/x-www-form-urlencoded',
accept: 'application/json',
authorization: auth,
'cache-control': 'no-cache',
},
);
});
if (!response.data.active) {
throw new UnauthorizedError(GENERIC_ERR_MESSAGE);
}
return response.data;
return decodedTokenPayload;
} catch (e) {
if (axios.isAxiosError(e)) {
if (e.response) {
Expand Down