# How to instruct Social Connection context request to use Accept header

**URL:** <https://community.auth0.com/t/how-to-instruct-social-connection-context-request-to-use-accept-header/115117>\
**Category:** Get Help\
**Tags:** custom-social-connections-branding, connections\
**Created:** [August 31, 2023, 1:37pm UTC](https://community.auth0.com/t/how-to-instruct-social-connection-context-request-to-use-accept-header/115117 "2023-08-31T13:37:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bpkennedy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bpkennedy/32/50424_2.png) [@bpkennedy](https://community.auth0.com/u/bpkennedy)\
**Post date:** [August 31, 2023, 1:37pm UTC](https://community.auth0.com/t/how-to-instruct-social-connection-context-request-to-use-accept-header/115117/1 "2023-08-31T13:37:54Z")

</div>

Hello!

I have a Custom Social Connection configured like this: [https://i.imgur.com/sheXeoX.png](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:

```auto
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:

```auto
{
  "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.

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [September 1, 2023, 10:12am UTC](https://community.auth0.com/t/how-to-instruct-social-connection-context-request-to-use-accept-header/115117/2 "2023-09-01T10:12:49Z")

</div>

Hey there and welcome @bpkennedy !

One thing that you can check is if you include the `audience` parameter in your /authorize request.

`audience` parameter takes a value of the API identifier you have set in your Auth0 tenant, that you request access to (this way you should get the jwt token instead of an opaque token).

Also, just in case you missed it - the app registered in Auth0 that is calling the API resources should be allowed for this API (for the API in question, please go to the Machine to Machine Applications tab and toggle the `Authorized` button for the app in question).

Hope this helps - let us know!

---

<div class="post-metadata">

**Author:** ![bpkennedy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bpkennedy/32/50424_2.png) [@bpkennedy](https://community.auth0.com/u/bpkennedy)\
**Post date:** [September 2, 2023, 12:09am UTC](https://community.auth0.com/t/how-to-instruct-social-connection-context-request-to-use-accept-header/115117/4 "2023-09-02T00:09:00Z")

</div>

Hello, and thank you @marcelina.barycka ! Well, I created this auth0 application as a “Regular Web Application” and not as a “Machine to Machine”. The web application is a Next.js type application. I do not have a separate auth0 API created - only the regular web application.

I’ve also used this nextjs-auth0 package to setup the authentication routes in the Next app. [GitHub - auth0/nextjs-auth0: Next.js SDK for signing in with Auth0](https://github.com/auth0/nextjs-auth0)

---

<div class="post-metadata">

**Author:** ![bpkennedy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bpkennedy/32/50424_2.png) [@bpkennedy](https://community.auth0.com/u/bpkennedy)\
**Post date:** [September 2, 2023, 12:58am UTC](https://community.auth0.com/t/how-to-instruct-social-connection-context-request-to-use-accept-header/115117/5 "2023-09-02T00:58:14Z")

</div>

Also is it truly an opaque token? The xml response has inside of it:

\<access\_token\>alphaNum\</access\_token\>

That seems like an access token, plain and simple, which I could use to make request for a resource from the third party provider, like:

[https://www.swcombine.com/ws/v2.0/character/Testing%20Character?access\_token=${accessToken}`](https://www.swcombine.com/ws/v2.0/character/Testing%20Character?access_token=$%7BaccessToken%7D%60)

---

<div class="post-metadata">

**Author:** ![marcelina.barycka](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/marcelina.barycka/32/56162_2.png) [@marcelina.barycka](https://community.auth0.com/u/marcelina.barycka)\
**Post date:** [September 4, 2023, 11:43am UTC](https://community.auth0.com/t/how-to-instruct-social-connection-context-request-to-use-accept-header/115117/8 "2023-09-04T11:43:29Z")

</div>

Thanks for following up!  
In terms of your direct question (adding a custom request header), you should find the below section under your Custom connection → Settings:

 ![image](https://global.discourse-cdn.com/auth0/original/3X/8/5/8500b9715352276507a69be048c342da12d121b1.png)

[https://auth0.com/docs/authenticate/identity-providers/social-identity-providers/oauth2#pass-static-parameters](https://auth0.com/docs/authenticate/identity-providers/social-identity-providers/oauth2#pass-static-parameters)

Let us please know how it goes! Thanks!

---

<div class="post-metadata">

**Author:** ![bpkennedy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bpkennedy/32/50424_2.png) [@bpkennedy](https://community.auth0.com/u/bpkennedy)\
**Post date:** [September 5, 2023, 1:47pm UTC](https://community.auth0.com/t/how-to-instruct-social-connection-context-request-to-use-accept-header/115117/9 "2023-09-05T13:47:30Z")

</div>

That worked for me! Thank you for your time and help!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [September 19, 2023, 1:48pm UTC](https://community.auth0.com/t/how-to-instruct-social-connection-context-request-to-use-accept-header/115117/10 "2023-09-19T13:48:21Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
