从邮递员生成Azure令牌

时间:2019-07-09 13:46:37

标签: azure azure-active-directory postman access-token bearer-token

我想从邮递员生成Azure令牌,以便在我的项目中进行API授权。我可以使用下面的API请求生成令牌,但是在另一个API请求中使用生成的令牌时收到以下错误消息“ 对此请求的授权被拒绝”。

端点#

https://login.microsoftonline.com/:tenant_id/oauth2/token 

Params#

tenant_id:As per id generation by azure.

身体#(表格数据)

grant_type:client_credentials
client_id:As per id generation by azure.
client_secret:As per id generation by azure.
resource:Required URL

响应#

    "token_type": "Bearer",
    "expires_in": "foo",
    "ext_expires_in": "foo",
    "expires_on": "foo",
    "not_before": "foo",
    "resource": "foo",
    "access_token":foo

由于不接受上述返回的令牌,因此我在请求正文中也传递了用户名和密码,但最终得到了相同的结果。同样,即使他们是错误的,azure也没有考虑我的凭据。

您能否协助我发送答复以获取有效的令牌ID?

2 个答案:

答案 0 :(得分:0)

使用生成的令牌时,应尝试在请求中添加“ X-ZUMO-AUTH”标头。

GET https://<appname>.azurewebsites.net/api/products/1
X-ZUMO-AUTH: <authenticationToken_value>

https://docs.microsoft.com/en-us/azure/app-service/app-service-authentication-how-to

答案 1 :(得分:0)

client_credentials身份验证流程的有效格式如下:

应用ID和租户ID的Azure门户凭据:

enter image description here

门户网站的应用程序秘密:

enter image description here

令牌端点或URL:

https://login.microsoftonline.com/YourTenantName.onmicrosoft.com/oauth2/token

请求参数:

grant_type:client_credentials
client_id:b603c7be_Your_App_ID_e6921e61f925
client_secret:Vxf1Sl_Your_App_Secret_2XDSeZ8wL/Yp8ns4sc=
resource:https://graph.microsoft.com 

PostMan示例:

enter image description here

响应令牌:

enter image description here

公开您自己的API:

当您想授权自己的API时,请在此处添加它。这样您的令牌将包含此权限,并且可以访问此API。请参阅此docs

enter image description here

为更清楚起见,您可以参考official docs