Requesting management api token from backend returns data field with weird encoding

Hi, I’m using a locally hosted server to request a management api token so that my backend can read a user’s metadata.

The request succeeds with status 200 OK and using curl I even get a readable response. But when I look at the console.loged data field from the response when the server makes the call, the reponse looks something like the below.

image

Any ideas as to why the data field seems to be in some sort of byte representation?

Thanks in advance

Flabberghasted

Hi there @jwpihlgren welcome to the community!

Interesting! I’m not positive, but do you mind sharing the server code you’re using the request the token?

Keep us posted!

Thanks for the quick reply @tyf!

I call a wrapper around axios like so:

async function getManagementAPIAccessToken(): Promise<any> {
    const url = `${process.env.AUTH0_DOMAIN}oauth/token`
    const options = {
        headers: {
            'content-type': 'application/json'
        }
    }
    const data = {
        client_id: process.env.AUTH0_CLIENT_ID,
        client_secret: process.env.AUTH0_CLIENT_SECRET,
        audience: process.env.AUTH0_MANAGEMENT_API_AUDIENCE,
        grant_type: process.env.AUTH0_GRANT_TYPE
    }

    const response = await HttpService.post(url, data, options)

    return response
}

And the wrapper looks like this:

async function post(url: string, data: any, config?: any ): Promise<any> {
    let result = {}
    try {
        const request = await axios.post(url, data, config)
        result = request.data
    }
    catch(error) {
        result["error"] = (error as any).response.data
    }
    return result
    
}

From my package.json:

  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.6",
    "@types/node": "^18.11.10",
    "@typescript-eslint/eslint-plugin": "^5.13.0",
    "@typescript-eslint/parser": "^5.13.0",
    "eslint": "^8.10.0",
    "ts-node": "^10.9.1",
    "typescript": "^4.9.3"
  },
  "dependencies": {
    "@types/mongoose": "^5.11.97",
    "@types/ws": "^8.5.3",
    "axios": "^1.2.0",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.17.1",
    "express-oauth2-jwt-bearer": "^1.1.0",
    "express-validator": "^6.14.0",
    "fast-xml-parser": "^4.0.8",
    "heartbeats": "^5.0.1",
    "mongoose": "^6.7.5",
    "nodemon": "^2.0.7",
    "ws": "^8.7.0"
  }

Thank your for your attention to this matter.

1 Like

I obviously should have stated that I’m using nodejs with typescript.

I switched from axios to fetch and I get a proper response now.

For my intents and purposes this is solved. I would believe that the fault lies with the axios library rather than you but I would be willing to provide further information upon request.

Thank you for your attention to this matter!

1 Like

Hmm that’s interesting - Thanks for following up here and glad to know that solved it for you! :smile:

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