Unable to get token form postman - returns 404

Norm Kelson 116 Reputation points
2020-07-07T14:57:49.75+00:00

I have been using postman to get token. No matter what i do , it returns 404 not found

My post command

https://login.microsoftonline.com/4e54a1c8-d98b-4f9b-8de9-bad93ae00fba/oauth2/v2.0/token HTTP/1.1 application/x-www-form-urlencoded
?client_id=96cf93dd-5c8b-41b9-a94d-aaf08e166fa5
&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
&redirect_url=https://login.microsoftonline.com/common/oauth2/nativeclient
&grant_type=client_credentials
&client_secret={...}

response is STATUS 404 not found

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Norm Kelson 116 Reputation points
    2020-07-08T18:55:42.413+00:00

    fixed. THANKS FOR YOUR EFFORTS.

    1 person found this answer helpful.
    0 comments No comments

11 additional answers

Sort by: Most helpful
  1. soumi-MSFT 11,831 Reputation points Microsoft Employee Moderator
    2020-07-07T17:01:39.397+00:00

    @NormKelson-5136, I believe the redirect_url parameter is not needed here as per the doc: https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-client-creds-grant-flow#first-case-access-token-request-with-a-shared-secret

    I tried the same and it worked for me. Please refer to the screenshot below:

    11459-client-cred.png

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.


  2. AmanpreetSingh-MSFT 56,871 Reputation points Moderator
    2020-07-07T17:26:29.583+00:00

    Hello @NormKelson-5136

    With the URL and the parameters that you have specified in your request, you should not get 404. There can be a problem connecting to internet via Postman. If you try to make a get call to any other website via postman, do you get 200 OK response?

    If you are using Proxy to connect to internet, make sure correct proxy address and credentials (if required to connect to proxy) are specified in postman settings. If you are running any application that captures network traffic like fiddler, wireshark etc., try to close those applications and make the call via Postman. I have seen Postman failing to connect to internet when fiddler is running.

    11591-capture1.jpg


    Please do not forget to "Accept the answer" wherever the information provided helps you. This will help others in the community as well.


  3. Alfredo Revilla - Upwork Top Talent | IAM SWE SWA 27,526 Reputation points Moderator
    2020-07-07T22:16:42.327+00:00

    Try doing it from powershell. Just set proper client secret value (xxx):

    $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("Content-Type", "application/x-www-form-urlencoded")
    
    $body = "client_id=96cf93dd-5c8b-41b9-a94d-aaf08e166fa5&scope=.default&redirect_url=https%3A//login.microsoftonline.com/common/oauth2/nativeclient&grant_type=client_credentials&client_secret=xxx"
    
    $response = Invoke-RestMethod 'https://login.microsoftonline.com/4e54a1c8-d98b-4f9b-8de9-bad93ae00fba/oauth2/v2.0/token' -Method 'POST' -Headers $headers -Body $body
    $response | ConvertTo-Json
    

    Or bash:
    wget --no-check-certificate --quiet \ --method POST \ --timeout=0 \ --header 'Content-Type: application/x-www-form-urlencoded' \ --header 'Cookie: buid=AQABAAEAAAAGV_bv21oQQ4ROqh0_1-tAASGdPbwjf8YEceRnN-BDOOM98nhwtQNP_1EU1zLTR5bdgk3ZrFyIXRVyrhSLWAZe9MY5_YIgwlwlj5wIx4v2maZBaseUA0H5Na0T5JWNUkEgAA; x-ms-gateway-slice=prod; \ --body-data 'client_id=96cf93dd-5c8b-41b9-a94d-aaf08e166fa5&scope=.default&redirect_url=https%3A%2F%2Flogin.microsoftonline.com%2Fcommon%2Foauth2%2Fnativeclient&grant_type=client_credentials&client_secret=xxx' \ 'https://login.microsoftonline.com/4e54a1c8-d98b-4f9b-8de9-bad93ae00fba/oauth2/v2.0/token

    0 comments No comments

  4. Norm Kelson 116 Reputation points
    2020-07-07T22:46:39.817+00:00

    I copied your powershell suggestion below. I've removed the client_secret from below. There was a syntax error. I'm not familiar with this code but the error seems to be at the beginning:

    PS C:\Users\norm.CPEI> $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("Content-Type", "application/x-www-form-urlencoded") $headers.Add("Cookie", "buid=AQABAAEAAAAGV_bv21oQQ4ROqh0_1-tAASGdPbwjf8YEceRnN-BDOOM98nhwtQNP_1EU1zLTR5bdgk3ZrFyIXRVyrhSLWAZe9MY5_YIgwlwlj5wIx4v2maZBaseUA0H5Na0T5JWNUkEgAA; x-ms-gateway-slice=prod; stsservicecookie=ests; fpc=AoMfMhLDAA1AlPY3FfU6OZLx3TTpBQAAABrqltYOAAAA") $body = "client_id=96cf93dd-5c8b-41b9-a94d-aaf08e166fa5&scope=.default&redirect_url=https%3A//login.microsoftonline.com/common/oauth2/nativeclient&grant_type=client_credentials&client_secret={..} $response = Invoke-RestMethod 'https://login.microsoftonline.com/4e54a1c8-d98b-4f9b-8de9-bad93ae00fba/oauth2/v2.0/token' -Method 'POST' -Headers $headers -Body $body $response | ConvertTo-Json

    You cannot call a method on a null-valued expression.
    At line:1 char:1

    • $headers = New-Object "System.Collections.Generic.Dictionary[[String] ...
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

    PS C:\Users\norm.CPEI>

    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.