Skip to content

Commit

Permalink
Refactor based on PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nkshah2 committed Sep 29, 2023
1 parent 95cf4c9 commit 4155631
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 40 deletions.
19 changes: 7 additions & 12 deletions lib/build/recipe/thirdparty/providers/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ function NewProvider(input) {
});
}
}
if (impl.config.validateAccessToken !== undefined && accessToken !== undefined) {
await impl.config.validateAccessToken({
accessToken: accessToken,
clientConfig: impl.config,
userContext,
});
}
if (accessToken && impl.config.userInfoEndpoint !== undefined) {
const headers = {
Authorization: "Bearer " + accessToken,
Expand Down Expand Up @@ -307,18 +314,6 @@ function NewProvider(input) {
);
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken;
}
/**
* This is intentionally not part of the above if block. This is because the user may want to validate the access
* token payload even if the user info API has not been provided by the provider. In this case they would get an
* empty object and they can fail if they always expect a non-empty object.
*/
if (impl.config.validateAccessToken !== undefined) {
await impl.config.validateAccessToken({
accessToken: accessToken,
clientConfig: impl.config,
userContext,
});
}
const userInfoResult = getSupertokensUserInfoResultFromRawUserInfo(impl.config, rawUserInfoFromProvider);
return {
thirdPartyUserId: userInfoResult.thirdPartyUserId,
Expand Down
7 changes: 0 additions & 7 deletions lib/build/recipe/thirdparty/providers/google.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@ function Google(input) {
{ included_grant_scopes: "true", access_type: "offline" },
input.config.authorizationEndpointQueryParams
);
// if (input.config.validateAccessToken === undefined) {
// input.config.validateAccessToken = async ({ accessTokenPayload, clientConfig }) => {
// if (accessTokenPayload.aud !== clientConfig.clientId) {
// throw Error("accessTokenPayload.aud does not match clientId");
// }
// };
// }
const oOverride = input.override;
input.override = function (originalImplementation) {
const oGetConfig = originalImplementation.getConfigForClientType;
Expand Down
21 changes: 8 additions & 13 deletions lib/ts/recipe/thirdparty/providers/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ export default function NewProvider(input: ProviderInput): TypeProvider {
}
}

if (impl.config.validateAccessToken !== undefined && accessToken !== undefined) {
await impl.config.validateAccessToken({
accessToken: accessToken,
clientConfig: impl.config,
userContext,
});
}

if (accessToken && impl.config.userInfoEndpoint !== undefined) {
const headers: { [key: string]: string } = {
Authorization: "Bearer " + accessToken,
Expand Down Expand Up @@ -335,19 +343,6 @@ export default function NewProvider(input: ProviderInput): TypeProvider {
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken;
}

/**
* This is intentionally not part of the above if block. This is because the user may want to validate the access
* token payload even if the user info API has not been provided by the provider. In this case they would get an
* empty object and they can fail if they always expect a non-empty object.
*/
if (impl.config.validateAccessToken !== undefined) {
await impl.config.validateAccessToken({
accessToken: accessToken,
clientConfig: impl.config,
userContext,
});
}

const userInfoResult = getSupertokensUserInfoResultFromRawUserInfo(impl.config, rawUserInfoFromProvider);

return {
Expand Down
8 changes: 0 additions & 8 deletions lib/ts/recipe/thirdparty/providers/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ export default function Google(input: ProviderInput): TypeProvider {
...input.config.authorizationEndpointQueryParams,
};

// if (input.config.validateAccessToken === undefined) {
// input.config.validateAccessToken = async ({ accessTokenPayload, clientConfig }) => {
// if (accessTokenPayload.aud !== clientConfig.clientId) {
// throw Error("accessTokenPayload.aud does not match clientId");
// }
// };
// }

const oOverride = input.override;

input.override = function (originalImplementation) {
Expand Down

0 comments on commit 4155631

Please sign in to comment.