# Parsing custom response from OAuth2 Token endpoint

**URL:** <https://community.auth0.com/t/parsing-custom-response-from-oauth2-token-endpoint/103199>\
**Category:** Get Help\
**Tags:** custom-social-connections-branding, connections\
**Created:** [March 23, 2023, 7:16pm UTC](https://community.auth0.com/t/parsing-custom-response-from-oauth2-token-endpoint/103199 "2023-03-23T19:16:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alefuser1](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@alefuser1](https://community.auth0.com/u/alefuser1)\
**Post date:** [March 23, 2023, 7:16pm UTC](https://community.auth0.com/t/parsing-custom-response-from-oauth2-token-endpoint/103199/1 "2023-03-23T19:16:54Z")

</div>

Hi, I’m adding a new Custom Social Connection to my list of Authentications and I face an issue when parsing a response from Token URL, which is used to get access token.  
According to [documentation](https://auth0.com/docs/secure/tokens/access-tokens/get-access-tokens#response) the response from endpoint that provides access token is expected in this format

```auto
{
  "access_token":"eyJz93a...k4laUWw",
  "token_type":"Bearer",
  "expires_in":86400
}

```

But I get a response that looks like that

```auto
{
    "$data": {
        "access_token": "6j42gte2lk1n29nte2lqmkk42g1n28nf0lbl9q",
        "refresh_token": "av439q8nlbl0l4309fp39q8nf0mkn43943f09f",
        "expires_in": 3600
    }
}

```

This is a response from `https://ed.link/api/authentication/token` doc [here](https://ed.link/docs/guides/v1.0/authentication)

As a result `accessToken` variable is empty and I cannot use it in my Fetch User Profile Script. How can I customize parsing of Token response body?

---

<div class="post-metadata">

**Author:** ![alefuser1](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@alefuser1](https://community.auth0.com/u/alefuser1)\
**Post date:** [March 24, 2023, 6:59am UTC](https://community.auth0.com/t/parsing-custom-response-from-oauth2-token-endpoint/103199/2 "2023-03-24T06:59:23Z")

</div>

I found a solution, instead of using `accessToken` parameter in `fetchUserProfile` I can use `context`. Like this:

```auto
function fetchUserProfile(accessToken, ctx, cb) {
  const theToken = ctx.$data.access_token;
  ...
}

```

---

<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:** [December 6, 2024, 12:27am UTC](https://community.auth0.com/t/parsing-custom-response-from-oauth2-token-endpoint/103199/3 "2024-12-06T00:27:43Z")

</div>

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