Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting access tokens from Postman: Tokens issued for the 'Single-Page Application' client-type may only be redeemed via cross-origin requests

We recently made a switch from Implicit Grant Flow to Authorization Code Flow with PKCE for our application, and now we're having some trouble getting access tokens from Azure AD from Postman. The app is registered in Azure AD and we're basically using the Postman procedure described here: https://developer.mypurecloud.com/api/rest/postman/index.html#enable_authorization. Calling the https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize endpoint works ok, but it hits an error when calling https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token:

"Error: Cound not complete OAuth 2.0 token request: "AADSTS9002327: Tokens issued for the 'Single-Page Application' client-type may only be redeemed via cross-origin requests.\r\nTrace ID: 8253f622-3425-4d0a-817c-281f86097300\r\nCorrelation ID: 9d84460f-ec02-4ace-af03-14d948e3d4ad\r\nTimestamp: 2020-04-15 14:02:03Z"

This is the access token request: enter image description here

How can we get access tokens from Azure AD using Postman with this authorization flow?

like image 954
PalBo Avatar asked Apr 15 '20 14:04

PalBo


People also ask

How can I get authorization token from browser postman?

To request an access token, fill out the fields in the Configure New Token section, and select Get New Access Token. You can save both the token and the details to generate a token with your request or collection. Once you have a token value generated and added, it will appear in the request Headers.

How do I give my postman OAuth?

In PostmanUnder the Authorization tab of any request, select OAuth 2.0 . Click Get New Access Token. From there, select a Grant Type of Authorization Code (With PKCE) . Input your data like in the previous request.


3 Answers

Apparently this is a problem as the documentation is confusing.

Over the Azure Active Directory App Registration. Make sure you add the redirect url over the "Mobile and desktop applications" category.

When you read the documentation looks like you need to add the Redirect URL under the Single Page Apps. It even shows confirmation message saying "Your Redirect URI is eligible for the Authorization Code Flow with PKCE." but is not true.

like image 61
user2096577 Avatar answered Oct 09 '22 16:10

user2096577


This error can occur when the "Origin" header is missing from the request (see: GitHub comment).

Try adding the header:

Origin: http://localhost
like image 23
Kim Avatar answered Oct 09 '22 16:10

Kim


If you're experiencing this failure whilst trying to authenticate using Postman, ensure that you have a platform authentication for Web.

Go to Azure AD > App Registrations > {your app reg} > Authentication > Add a platform. Redirect URI should be https://oauth.pstmn.io/v1/callback when using the browser.

like image 1
Ian Avatar answered Oct 09 '22 18:10

Ian