从 Postman 生成 Azure 访问令牌

Azure access token generation from Postman

我想从 Postman 生成 Azure 令牌以在我的项目中获得 API 授权。我能够使用以下 API 请求生成令牌,但在另一个 API 请求中使用生成的令牌时收到以下错误消息“此请求的授权被拒绝” .

端点#

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

参数#

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?

在使用生成的令牌时,您应该尝试将 "X-ZUMO-AUTH" header 添加到您的请求中。

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

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

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

来自门户的应用程序机密:

令牌端点或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 

邮差示例:

响应令牌:

公开你自己的API:

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

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