AxiosError: Request failed with status code 401 when accessing https://graph.microsoft.com/v1.0/me/messages

Alvin Tay 1 Reputation point
2022-07-07T09:51:31.337+00:00

Hi, I am using node.js to access Microsoft Graph APIs, following this https://learn.microsoft.com/en-us/azure/active-directory/develop/web-app-quickstart?pivots=devlang-nodejs-msal.

I am able to access https://graph.microsoft.com/v1.0/me successfully. However, https://graph.microsoft.com/v1.0/me/messages returns "AxiosError: Request failed with status code 401". The access token is not empty.

Microsoft Security | Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Alvin Tay 1 Reputation point
    2022-07-09T03:31:29.09+00:00

    Parsed Token:

    {
    "typ": "JWT",
    "nonce": "zr-Lk6jVmlbVawwvQIXOED3H7r8TCkMds_4NHVQg63Y",
    "alg": "RS256",
    "x5t": "2ZQpJ3UpbjAYXYGaXEJl8lV0TOI",
    "kid": "2ZQpJ3UpbjAYXYGaXEJl8lV0TOI"
    }.{
    "aud": "00000003-0000-0000-c000-000000000000",
    "iss": "https://sts.windows.net/ec28f648-3218-408a-946b-ea69ac045d07/",
    "iat": 1657336548,
    "nbf": 1657336548,
    "exp": 1657340495,
    "acct": 0,
    "acr": "1",
    "aio": "AWQAm/8TAAAAQoH6iRyWXZWGkGqgUdlRMDH+v3x6cCGV48cG1jTfPQ+RRpuembz925f/sZcPRfrKM5GwQlC+fU3P9yTqgeMXq8yY/IBwvj9KQCw5qHFsHFF82MFp6RpZJT0RwDQXtrQV",
    "altsecid": "1:live.com:00067FFEC2A4B412",
    "amr": [
    "pwd",
    "mfa"
    ],
    "app_displayname": "Ivory",
    "appid": "54aca30b-c63a-4773-a747-3b6515c4439f",
    "appidacr": "1",
    "email": "Alvin_Tay98@Karima ben .com",
    "family_name": "Tay",
    "given_name": "Alvin",
    "idp": "live.com",
    "idtyp": "user",
    "ipaddr": "151.192.252.4",
    "name": "Alvin Tay",
    "oid": "10dbce72-3cb5-4cf3-918a-f98fe1e8c548",
    "platf": "3",
    "puid": "100320020DF4D942",
    "rh": "0.AVUASPYo7BgyikCUa-pprARdBwMAAAAAAAAAwAAAAAAAAACIAME.",
    "scp": "Application.Read.All Application.ReadWrite.All Calendars.Read Calendars.Read.Shared Calendars.ReadWrite Calendars.ReadWrite.Shared DelegatedPermissionGrant.ReadWrite.All email Mail.Read Mail.Read.Shared Mail.ReadBasic Mail.ReadWrite Mail.ReadWrite.Shared Mail.Send Mail.Send.Shared openid Organization.Read.All Organization.ReadWrite.All PrivilegedAccess.ReadWrite.AzureAD PrivilegedAccess.ReadWrite.AzureADGroup PrivilegedAccess.ReadWrite.AzureResources profile User.Read User.Read.All User.ReadWrite.All",
    "signin_state": [
    "kmsi"
    ],
    "sub": "x49Yvth1azi6H0lGQndOQjfqSLrDXeiDAUlfKPPw7gU",
    "tenant_region_scope": "AS",
    "tid": "ec28f648-3218-408a-946b-ea69ac045d07",
    "unique_name": "live.com#Alvin_Tay98@Karima ben .com",
    "uti": "uJUTiFkTVEC7dhsR1VCDAA",
    "ver": "1.0",
    "wids": [
    "cf1c38e5-3621-4004-a7cb-879624dced7c",
    "9b895d92-2cd3-44c7-9d02-a6ac2d5ea5c3",
    "62e90394-69f5-4237-9190-012177145e10",
    "b79fbf4d-3ef9-4689-8143-76b194e85509"
    ],
    "xms_st": {
    "sub": "XMk6JvHUOk2K50ZVYmfA_XDLBz41mzSuqVa9HrcgvWw"
    },
    "xms_tcdt": 1657168928
    }.[Signature]

    The code is identical to "Step 2: Download the Project" from https://learn.microsoft.com/en-us/azure/active-directory/develop/web-app-quickstart?pivots=devlang-nodejs-msal

    The only changes are:
    .env:
    CLOUD_INSTANCE=https://login.microsoftonline.com/
    TENANT_ID=ec28f648-3218-408a-946b-ea69ac045d07
    CLIENT_ID=54aca30b-c63a-4773-a747-3b6515c4439f
    CLIENT_SECRET=rIt8Q~eO2M~xOPCbye.h7MELTAqMTapt4YqHSa4-

    REDIRECT_URI=http://localhost:3000/auth/redirect
    POST_LOGOUT_REDIRECT_URI=http://localhost:3000

    GRAPH_API_ENDPOINT=https://graph.microsoft.com/

    EXPRESS_SESSION_SECRET=1234abcd

    authConfig.js line 32:
    const GRAPH_ME_ENDPOINT = process.env.GRAPH_API_ENDPOINT + "v1.0/me/messages";

    Details of registered app on azure:
    Application (client) ID: 54aca30b-c63a-4773-a747-3b6515c4439f
    Object ID: 5f04f4c4-1573-4892-87ea-f0e50d148225
    Directory (tenant) ID: ec28f648-3218-408a-946b-ea69ac045d07
    Supported account types: All Microsoft account users

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.