Hello!
I have a Custom Social Connection configured like this: https://i.imgur.com/sheXeoX.png.
When testing I see and accept the Grant page of the third party, and then I am getting to the Fetch User Profile Script. Mine looks like this:
function(accessToken, ctx, cb) {
return cb(new Error(JSON.stringify(ctx))) // return early to debug object
const profile = {};
// Call OAuth2 API with the accessToken and create the profile
request.get(
{
url: `https://www.swcombine.com/ws/v2.0/character/Testing%20Character?access_token=${accessToken}`,
},
(err, resp, body) => {
if (err) {
return cb(err);
}
if (resp.statusCode !== 200) {
return cb(new Error(body));
}
let bodyParsed;
try {
bodyParsed = JSON.parse(body);
} catch (jsonError) {
return cb(new Error(body));
}
const profile = {
user_id: bodyParsed.account.uuid,
email: bodyParsed.account.email
};
cb(null, profile);
}
);
}
I tried logging the accessToken
parameter and it appears to be undefined. However when I log the ctx
object I see that there is xml instead of json, and on the auth0 test screen the error message is:
{
"error": "invalid_request",
"error_description": "{\"<?xml version\":\"\\\"1.0\\\" encoding=\\\"UTF-8\\\"?>\\n<OAuth><access_token>b9ae1d4a6cdb6d8364a0643ce58f7655</access_token><expires_in>3600</expires_in><scope>character_read</scope></OAuth>\\n\",\"options\":{\"scope\":\"character_read\",\"tokenURL\":\"https://www.swcombine.com/ws/oauth2/token/\",\"client_id\":\"e5c1500bf34c3cec3761f3049cbc947e1299c7d8\",\"client_secret\":\"061e0d225e7bb6056901233ae43d37e707dac25e\",\"authorizationURL\":\"https://www.swcombine.com/ws/oauth2/auth/\",\"set_user_root_attributes\":\"on_first_login\",\"store\":{}}}"
}
It seems what is happening is that the third party provider is returning xml instead of json. However, it supports returning json if the Accept header specifies Accept: āapplication/jsonā. I tried creating a Rule (even if decprecated) to modify the ctx.request.headers[āAcceptā] but Iām not sure that is effective or possible as when I ran the rule test there wasnāt a āheaderā property on the ctx.request object.
How can I make the request header accept json, or if not how can I convert the xml response to json? The auth0 sandbox doesnāt allow access to window
or DOMParser
.
Thanks for your time.