Token Endpoint Returning HTML

AdamHiatt-6223 21 Reputation points
2022-10-24T19:15:28.487+00:00

I am trying to get a bearer token from the https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token endpoint. This works fine in postman, but when I try to run it from my node js app, it returns the Sign In html page instead of the bearer token. See code below for implementation:

const tokenUrl = 'https://login.microsoftonline.com/<tenant>/oauth2/v2.0/token';  
const clientId = '<id>';  
const clientSecret = '<secret>';  
  
const form = FormData();  
form.append('client_id', clientId);  
form.append('scope', 'https://graph.microsoft.com/.default');  
form.append('client_secret',clientSecret);  
form.append('grant_type', 'client_credentials');  
  
const getToken = () => {  
  axios.get(tokenUrl, form, {  
    headers: {  
      'Content-Type': 'application/x-www-form-urlencoded',  
      'Host': 'login.microsoftonline.com',  
    }  
  }).then((response) => {  
    return response.data.token;  
  }).catch(e => console.log(e));  
}  

I'm sure I am missing something simple, but I am new to Graph API, thanks in advance for the help.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph

2 answers

Sort by: Oldest
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. AdamHiatt-6223 21 Reputation points
    2022-10-25T14:39:27.253+00:00

    Thanks so much for the help! Silly mistake on my part.

    Was this answer helpful?

    0 comments No comments

Your answer

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