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

Request fixes #713

Merged
merged 1 commit into from
Oct 10, 2023
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
22 changes: 7 additions & 15 deletions lib/build/recipe/thirdparty/providers/bitbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,30 @@ function Bitbucket(input) {
);
if (userInfoFromAccessToken.status >= 400) {
logger_1.logDebugMessage(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
throw new Error(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
}
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.response;
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.jsonResponse;
const userInfoFromEmail = await utils_1.doGetRequest(
"https://api.bitbucket.org/2.0/user/emails",
undefined,
headers
);
if (userInfoFromEmail.status >= 400) {
logger_1.logDebugMessage(
`Received response with status ${
userInfoFromEmail.status
} and body ${await userInfoFromEmail.rawResponse.text()}`
`Received response with status ${userInfoFromEmail.status} and body ${userInfoFromEmail.stringResponse}`
);
throw new Error(
`Received response with status ${
userInfoFromEmail.status
} and body ${await userInfoFromEmail.rawResponse.text()}`
`Received response with status ${userInfoFromEmail.status} and body ${userInfoFromEmail.stringResponse}`
);
}
rawUserInfoFromProvider.fromUserInfoAPI.email = userInfoFromEmail.response;
rawUserInfoFromProvider.fromUserInfoAPI.email = userInfoFromEmail.jsonResponse;
let email = undefined;
let isVerified = false;
for (const emailInfo of userInfoFromEmail.response.values) {
for (const emailInfo of userInfoFromEmail.jsonResponse.values) {
if (emailInfo.is_primary) {
email = emailInfo.email;
isVerified = emailInfo.is_confirmed;
Expand Down
20 changes: 6 additions & 14 deletions lib/build/recipe/thirdparty/providers/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,17 +254,13 @@ function NewProvider(input) {
const tokenResponse = await utils_1.doPostRequest(tokenAPIURL, accessTokenAPIParams);
if (tokenResponse.status >= 400) {
logger_1.logDebugMessage(
`Received response with status ${
tokenResponse.status
} and body ${await tokenResponse.rawResponse.text()}`
`Received response with status ${tokenResponse.status} and body ${tokenResponse.stringResponse}`
);
throw new Error(
`Received response with status ${
tokenResponse.status
} and body ${await tokenResponse.rawResponse.text()}`
`Received response with status ${tokenResponse.status} and body ${tokenResponse.stringResponse}`
);
}
return tokenResponse.response;
return tokenResponse.jsonResponse;
},
getUserInfo: async function ({ oAuthTokens, userContext }) {
const accessToken = oAuthTokens["access_token"];
Expand Down Expand Up @@ -329,17 +325,13 @@ function NewProvider(input) {
);
if (userInfoFromAccessToken.status >= 400) {
logger_1.logDebugMessage(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
throw new Error(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
}
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.response;
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.jsonResponse;
}
const userInfoResult = getSupertokensUserInfoResultFromRawUserInfo(impl.config, rawUserInfoFromProvider);
return {
Expand Down
14 changes: 6 additions & 8 deletions lib/build/recipe/thirdparty/providers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ function Github(input) {
throw new Error("Invalid access token");
}
if (
applicationResponse.response.app === undefined ||
applicationResponse.response.app.client_id !== clientConfig.clientId
applicationResponse.jsonResponse.app === undefined ||
applicationResponse.jsonResponse.app.client_id !== clientConfig.clientId
) {
throw new Error("Access token does not belong to your application");
}
Expand All @@ -84,17 +84,15 @@ function Github(input) {
const emailInfoResp = await utils_1.doGetRequest("https://api.github.com/user/emails", undefined, headers);
if (emailInfoResp.status >= 400) {
throw new Error(
`Getting userInfo failed with ${emailInfoResp.status}: ${await emailInfoResp.rawResponse.text()}`
`Getting userInfo failed with ${emailInfoResp.status}: ${emailInfoResp.stringResponse}`
);
}
rawResponse.emails = emailInfoResp.response;
rawResponse.emails = emailInfoResp.jsonResponse;
const userInfoResp = await utils_1.doGetRequest("https://api.github.com/user", undefined, headers);
if (userInfoResp.status >= 400) {
throw new Error(
`Getting userInfo failed with ${userInfoResp.status}: ${await userInfoResp.rawResponse.text()}`
);
throw new Error(`Getting userInfo failed with ${userInfoResp.status}: ${userInfoResp.stringResponse}`);
}
rawResponse.user = userInfoResp.response;
rawResponse.user = userInfoResp.jsonResponse;
const rawUserInfoFromProvider = {
fromUserInfoAPI: rawResponse,
fromIdTokenPayload: {},
Expand Down
24 changes: 8 additions & 16 deletions lib/build/recipe/thirdparty/providers/linkedin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,13 @@ function Linkedin(input) {
undefined,
headers
);
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.response;
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.jsonResponse;
if (userInfoFromAccessToken.status >= 400) {
logger_1.logDebugMessage(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
throw new Error(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
}
const emailAPIURL = "https://api.linkedin.com/v2/emailAddress";
Expand All @@ -80,23 +76,19 @@ function Linkedin(input) {
);
if (userInfoFromEmail.status >= 400) {
logger_1.logDebugMessage(
`Received response with status ${
userInfoFromEmail.status
} and body ${await userInfoFromEmail.rawResponse.text()}`
`Received response with status ${userInfoFromEmail.status} and body ${userInfoFromEmail.stringResponse}`
);
throw new Error(
`Received response with status ${
userInfoFromEmail.status
} and body ${await userInfoFromEmail.rawResponse.text()}`
`Received response with status ${userInfoFromEmail.status} and body ${userInfoFromEmail.stringResponse}`
);
}
if (userInfoFromEmail.response.elements && userInfoFromEmail.response.elements.length > 0) {
if (userInfoFromEmail.jsonResponse.elements && userInfoFromEmail.jsonResponse.elements.length > 0) {
rawUserInfoFromProvider.fromUserInfoAPI.email =
userInfoFromEmail.response.elements[0]["handle~"].emailAddress;
userInfoFromEmail.jsonResponse.elements[0]["handle~"].emailAddress;
}
rawUserInfoFromProvider.fromUserInfoAPI = Object.assign(
Object.assign({}, rawUserInfoFromProvider.fromUserInfoAPI),
userInfoFromEmail.response
userInfoFromEmail.jsonResponse
);
return {
thirdPartyUserId: rawUserInfoFromProvider.fromUserInfoAPI.id,
Expand Down
10 changes: 3 additions & 7 deletions lib/build/recipe/thirdparty/providers/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,13 @@ function Twitter(input) {
);
if (tokenResponse.status >= 400) {
logger_1.logDebugMessage(
`Received response with status ${
tokenResponse.status
} and body ${await tokenResponse.rawResponse.text()}`
`Received response with status ${tokenResponse.status} and body ${tokenResponse.stringResponse}`
);
throw new Error(
`Received response with status ${
tokenResponse.status
} and body ${await tokenResponse.rawResponse.text()}`
`Received response with status ${tokenResponse.status} and body ${tokenResponse.stringResponse}`
);
}
return tokenResponse.response;
return tokenResponse.jsonResponse;
};
if (oOverride !== undefined) {
originalImplementation = oOverride(originalImplementation);
Expand Down
8 changes: 4 additions & 4 deletions lib/build/recipe/thirdparty/providers/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export declare function doGetRequest(
[key: string]: string;
}
): Promise<{
response: any;
jsonResponse: Record<string, any> | undefined;
status: number;
rawResponse: Response;
stringResponse: string;
}>;
export declare function doPostRequest(
url: string,
Expand All @@ -23,9 +23,9 @@ export declare function doPostRequest(
[key: string]: string;
}
): Promise<{
response: any;
jsonResponse: Record<string, any> | undefined;
status: number;
rawResponse: Response;
stringResponse: string;
}>;
export declare function verifyIdTokenFromJWKSEndpointAndGetPayload(
idToken: string,
Expand Down
34 changes: 20 additions & 14 deletions lib/build/recipe/thirdparty/providers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ async function doGetRequest(url, queryParams, headers) {
let response = await cross_fetch_1.default(finalURL.toString(), {
headers: headers,
});
const respData = await response.clone().json();
logger_1.logDebugMessage(`Received response with status ${response.status} and body ${JSON.stringify(respData)}`);
const stringResponse = await response.text();
let jsonResponse = undefined;
if (response.status < 400) {
jsonResponse = JSON.parse(stringResponse);
}
logger_1.logDebugMessage(`Received response with status ${response.status} and body ${stringResponse}`);
return {
response: respData,
stringResponse,
status: response.status,
rawResponse: response.clone(),
jsonResponse,
};
}
exports.doGetRequest = doGetRequest;
Expand All @@ -83,12 +87,16 @@ async function doPostRequest(url, params, headers) {
body,
headers,
});
const respData = await response.clone().json();
logger_1.logDebugMessage(`Received response with status ${response.status} and body ${JSON.stringify(respData)}`);
const stringResponse = await response.text();
let jsonResponse = undefined;
if (response.status < 400) {
jsonResponse = JSON.parse(stringResponse);
}
logger_1.logDebugMessage(`Received response with status ${response.status} and body ${stringResponse}`);
return {
response: respData,
stringResponse,
status: response.status,
rawResponse: response.clone(),
jsonResponse,
};
}
exports.doPostRequest = doPostRequest;
Expand All @@ -112,14 +120,12 @@ async function getOIDCDiscoveryInfo(issuer) {
);
if (oidcInfo.status >= 400) {
logger_1.logDebugMessage(
`Received response with status ${oidcInfo.status} and body ${await oidcInfo.rawResponse.text()}`
);
throw new Error(
`Received response with status ${oidcInfo.status} and body ${await oidcInfo.rawResponse.text()}`
`Received response with status ${oidcInfo.status} and body ${oidcInfo.stringResponse}`
);
throw new Error(`Received response with status ${oidcInfo.status} and body ${oidcInfo.stringResponse}`);
}
oidcInfoMap[issuer] = oidcInfo.response;
return oidcInfo.response;
oidcInfoMap[issuer] = oidcInfo.jsonResponse;
return oidcInfo.jsonResponse;
}
async function discoverOIDCEndpoints(config) {
if (config.oidcDiscoveryEndpoint !== undefined) {
Expand Down
22 changes: 7 additions & 15 deletions lib/ts/recipe/thirdparty/providers/bitbucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,13 @@ export default function Bitbucket(input: ProviderInput): TypeProvider {

if (userInfoFromAccessToken.status >= 400) {
logDebugMessage(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
throw new Error(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
}
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.response;
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.jsonResponse;

const userInfoFromEmail = await doGetRequest(
"https://api.bitbucket.org/2.0/user/emails",
Expand All @@ -98,22 +94,18 @@ export default function Bitbucket(input: ProviderInput): TypeProvider {

if (userInfoFromEmail.status >= 400) {
logDebugMessage(
`Received response with status ${
userInfoFromEmail.status
} and body ${await userInfoFromEmail.rawResponse.text()}`
`Received response with status ${userInfoFromEmail.status} and body ${userInfoFromEmail.stringResponse}`
);
throw new Error(
`Received response with status ${
userInfoFromEmail.status
} and body ${await userInfoFromEmail.rawResponse.text()}`
`Received response with status ${userInfoFromEmail.status} and body ${userInfoFromEmail.stringResponse}`
);
}

rawUserInfoFromProvider.fromUserInfoAPI.email = userInfoFromEmail.response;
rawUserInfoFromProvider.fromUserInfoAPI.email = userInfoFromEmail.jsonResponse;

let email = undefined;
let isVerified = false;
for (const emailInfo of userInfoFromEmail.response.values) {
for (const emailInfo of userInfoFromEmail.jsonResponse!.values) {
if (emailInfo.is_primary) {
email = emailInfo.email;
isVerified = emailInfo.is_confirmed;
Expand Down
20 changes: 6 additions & 14 deletions lib/ts/recipe/thirdparty/providers/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,14 @@ export default function NewProvider(input: ProviderInput): TypeProvider {

if (tokenResponse.status >= 400) {
logDebugMessage(
`Received response with status ${
tokenResponse.status
} and body ${await tokenResponse.rawResponse.text()}`
`Received response with status ${tokenResponse.status} and body ${tokenResponse.stringResponse}`
);
throw new Error(
`Received response with status ${
tokenResponse.status
} and body ${await tokenResponse.rawResponse.text()}`
`Received response with status ${tokenResponse.status} and body ${tokenResponse.stringResponse}`
);
}

return tokenResponse.response;
return tokenResponse.jsonResponse;
},

getUserInfo: async function ({ oAuthTokens, userContext }): Promise<UserInfo> {
Expand Down Expand Up @@ -359,18 +355,14 @@ export default function NewProvider(input: ProviderInput): TypeProvider {

if (userInfoFromAccessToken.status >= 400) {
logDebugMessage(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
throw new Error(
`Received response with status ${
userInfoFromAccessToken.status
} and body ${await userInfoFromAccessToken.rawResponse.text()}`
`Received response with status ${userInfoFromAccessToken.status} and body ${userInfoFromAccessToken.stringResponse}`
);
}

rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.response;
rawUserInfoFromProvider.fromUserInfoAPI = userInfoFromAccessToken.jsonResponse;
}

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