Not Able to get user details with user id auth0.getUser method

After login when i am trying to get the user details it is send error in respone as below

    "error": {
        "name": "Unauthorized",
        "message": "Invalid token",
        "statusCode": 401,
        "requestInfo": {
            "method": "get",
            "url": ""
        "originalError": {
            "status": 401,
            "response": {
                "req": {
                    "method": "GET",
                    "url": "",
                    "headers": {
                        "content-type": "application/json",
                        "user-agent": "node.js/18.16.1",
                        "auth0-client": "eyJuYW1lIjoibm9kZS1hdXRoMCIsInZlcnNpb24iOiIzLjYuMCIsImVudiI6eyJub2RlIjoiMTguMTYuMSJ9fQ",
                        "authorization": "[REDACTED]",
                        "accept": "application/json"
                "header": {
                    "date": "Tue, 01 Aug 2023 06:51:00 GMT",
                    "content-type": "application/json; charset=utf-8",
                    "content-length": "106",
                    "connection": "close",
                    "cf-ray": "7efc2669a9ac4ad4-HYD",
                    "cf-cache-status": "DYNAMIC",
                    "cache-control": "no-cache",
                    "strict-transport-security": "max-age=31536000",
                    "vary": "origin, Accept-Encoding",
                    "www-authenticate": "Bearer error=\"Invalid token\"",
                    "access-control-expose-headers": "WWW-Authenticate,Server-Authorization",
                    "ot-baggage-auth0-request-id": "7efc2669a9ac4ad4",
                    "ot-tracer-sampled": "true",
                    "ot-tracer-spanid": "1ac1e404795ebcc4",
                    "ot-tracer-traceid": "1a534d0a01d9f0ea",
                    "traceparent": "00-00000000000000001a534d0a01d9f0ea-1ac1e404795ebcc4-01",
                    "tracestate": "auth0-request-id=7efc2669a9ac4ad4,auth0=true",
                    "x-content-type-options": "nosniff",
                    "server": "cloudflare",
                    "alt-svc": "h3=\":443\"; ma=86400"
                "status": 401,
                "text": "{\"statusCode\":401,\"error\":\"Unauthorized\",\"message\":\"Invalid token\",\"attributes\":{\"error\":\"Invalid token\"}}"

Actual implementation is below.

const express = require('express');
const router = express.Router();
const dotenv = require('dotenv');
const { AuthenticationClient, ManagementClient } = require('auth0');


const auth0 = new AuthenticationClient({
  domain: process.env.DOMAIL,
  clientSecret:  process.env.SECRET,

const management = new ManagementClient({
  domain: process.env.DOMAIL,
  clientId: process.env.CLIENT_ID,
  clientSecret: process.env.SECRET,
  audience: process.env.AUDIENCE,
});'/login', async (req, res) => {
  const { username, password } = req.body;

  try {
    // Attempt to authenticate the user with Auth0's Resource Owner Password Grant
    const response = await auth0.passwordGrant({
      username: username, // Allow login with either email or username
      audience: "",
      scope: 'openid profile email', // Add any additional scopes as needed

    // Fetch user data including roles using the Management API
    const user = await management.getUser({ id:"auth0|64c888b07f18450dc24cb099"})


    // Return the access token and user information
    res.status(200).json({ accessToken: response.access_token, user: response });
  } catch (error) {
    console.error('Error during login:', error.message);
    res.status(401).json({ error: error });

module.exports = router;

Hi @AMIR1998,

Welcome to the Auth0 Community!

That error suggests you are sending an invalid token. Can you confirm you have a valid token? see


I have confirmed that i am sending right token which i am receiving as from auth0, also i verified the token at
But still receiving same issue.

same token i passed to custom function like below then it give m the user details but when i am calling it with auth0.getUser method i am receiving the error.

const getUser = async (token) => {
  try {
    const response = await axios.get("https://<here passed auth0 tenant>", {
      headers: {
        Authorization: `Bearer ${token}`,
  } catch (error) {
    console.error('Error making API request:', error.message);
    const user = await getUser(response.access_token)
1 Like

Could you please provide an example of the token payload you are seeing? Please omit any sensitive data.


  "alg": "RS256",
  "typ": "JWT",
  "kid": "IoKT3XjVrrI9kHgqz3RQS"
  "iss": "",
  "sub": "yUYhvhQlroQXNun3CVTw8ZGj6oAeKxAY@clients",
  "aud": "",
  "iat": 1691552362,
  "exp": 1694144362,
  "azp": "yUYhvhQlroQXNun3CVTw8ZGj6oAeKxAY",
  "gty": "client-credentials"
1 Like

Hi @AMIR1998,

That is not a user access token (it’s a machine to machine token), and can’t be exchanged for a user profile via the /userinfo endpoint.

You should be using the access token you get from the request to log in.

I have obtained an access_token after a successful login, which I am currently using. However, I’m encountering an error. To resolve this issue, I need a user access token to retrieve user details. Unfortunately, I’m facing difficulty in finding a method to obtain the user access token. Please guide me on how to obtain the user access token.

1 Like

It looks like you are using the token from the managementClient. That is a machine to machine token.

Are you sure you’re using the access token returned from the passwordGrant method? I just tested it and the current version of the SDK is working as expected for me.

The token returned by the passwordGrant method should look something like this:

  "iss": "",
  "sub": "auth0|xxx",
  "aud": [
  "iat": 1691761570,
  "exp": 1691847970,
  "azp": "xxx",
  "scope": "openid profile email address phone",
  "gty": "password",
  "permissions": [
1 Like

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