Unable to get a Microsoft Graph Token

Suberri, Moshe [GTSUS] 0 Reputation points
2024-09-19T12:06:13.2466667+00:00

I am a user in the Azure tenant directory, trying to get a Token to send a message to a Teams channel.
I can do that via Microsoft Graph Explorer. When I use a Token that Microsoft Graph generates I can send a message to Teams channel via curl and Postman.

However, when I try to get a token I get an error:
Here is the Curl request and response:

curl -X POST https://login.microsoftonline.com/{tenant}/v2.0/token \
     -H "Content-Type: application/x-www-form-urlencoded" \
     -d "client_id={client id}" \
     -d "client_secret={secret}" \
     -d "scope=Channel.ReadBasic.All TeamMember.Read.All ChannelMessage.Read.All" \
     -d "username={username}" \
     -d "password={password}" \
     -d "grant_type=password"    

Response:
{"error":"invalid_grant","error_description":"AADSTS50034:

The user account {EUII Hidden} does not exist in the {tenant id} directory.

To sign into this application, the account must be added to the directory. T

"error_codes":[50034],"

"error_uri":"https://login.microsoftonline.com/error?code=50034"}%

I am a member of the Azure Tenant users

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,886 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Patchfox 3,831 Reputation points
    2024-09-19T12:35:23.88+00:00

    Hi Suberri, Moshe [GTSUS] I want to help you with this questions.

    As I understand, you tried a POST request against EntraID endpoint to get a token.
    If you have a service principal (SPN) created and want to use that identity to receive the token, you only need the client_id and secret in the request.

    Otherwise, you remove these attributes and use only the username and password. But not both.

    I think the endpoint is not the right one here, so please check out this article: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-client-creds-grant-flow#first-case-access-token-request-with-a-shared-secret
    I think it will help you to build your POST request correctly.


    If the reply was helpful, please don’t forget to upvote or accept it as an answer, thank you!

    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.