get Access Token From Refresh Token

INAMALI PALASANIYA 0 Reputation points
2023-10-17T06:55:44.5066667+00:00

we want to trying get access token from refresh token in nodejs by msal-node library
but will get error
Our code and Error is listed bellow

import { PublicClientApplication } from "@azure/msal-node";

const config = {
  auth: {
    clientSecret: "CLIENT_SECRET",
    clientId: "CLIENT_ID",
    redirectUri: "http://localhost:3000/setting",
    authority: "https://login.microsoftonline.com/consumers",
  },
};
const pca = new PublicClientApplication(config);

export async function getAccessTokenFromRefreshTokenTest(refreshToken) {
  const tokenRequest = {
    refreshToken: refreshToken,
    scopes: ["User.Read"], // Add the required scopes for your API
	clientSecret:"CLIENT_SECRET"
  };

  try {
    const response = await pca.acquireTokenByRefreshToken(tokenRequest);
    console.log(response.accessToken);
    return response.accessToken;
  } catch (error) {
    console.error("Error refreshing access token:", error);
    throw error;
  }
}
ServerError: invalid_client: 70002 - [2023-10-17 06:45:16Z]: AADSTS70002: The provided request must include a 'client_secret' input parameter.
Trace ID: 9ec8ba68-c2be-41fd-9503-9587c1746d00
Correlation ID: f7dfdc97-60e5-40c9-88c2-9c4bf76735c9
Timestamp: 2023-10-17 06:45:16Z - Correlation ID: f7dfdc97-60e5-40c9-88c2-9c4bf76735c9 - Trace ID: 9ec8ba68-c2be-41fd-9503-9587c1746d00
    at ResponseHandler.validateTokenResponse (file:///Users/aincoders/Documents/GitHub/wms-node-js/node_modules/@azure/msal-common/dist/response/ResponseHandler.mjs:93:33)
    at RefreshTokenClient.acquireToken (file:///Users/aincoders/Documents/GitHub/wms-node-js/node_modules/@azure/msal-common/dist/client/RefreshTokenClient.mjs:43:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async getAccessTokenFromRefreshTokenTest (file:///Users/aincoders/Documents/GitHub/wms-node-js/api/libraries/microsoft/microsoft.library.js:125:26)
    at async create (file:///Users/aincoders/Documents/GitHub/wms-node-js/api/controllers/v1/microsoft.controller.js:30:9) {
  errorCode: 'invalid_client',
  errorMessage: "70002 - [2023-10-17 06:45:16Z]: AADSTS70002: The provided request must include a 'client_secret' input parameter.\r\n" +
    'Trace ID: 9ec8ba68-c2be-41fd-9503-9587c1746d00\r\n' +
    'Correlation ID: f7dfdc97-60e5-40c9-88c2-9c4bf76735c9\r\n' +
    'Timestamp: 2023-10-17 06:45:16Z - Correlation ID: f7dfdc97-60e5-40c9-88c2-9c4bf76735c9 - Trace ID: 9ec8ba68-c2be-41fd-9503-9587c1746d00',
  subError: ''
}
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

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.