从 Postman 生成 Azure 访问令牌

问题描述 投票:1回答:2

我想在我的项目中从Postman生成Azure token用于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?

azure azure-active-directory postman access-token bearer-token
2个回答
2
投票

有效格式为 client_credentials 认证流程如下。

Azure Portal凭证为App Id和Tenant Id。

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就可以被访问。请参考这个 文件

enter image description here

为了更清楚地了解情况,您可以参考 正式文件


0
投票

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

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

https:/docs.microsoft.comen-usazureapp-serviceapp-service-authentication-how-to)。

© www.soinside.com 2019 - 2024. All rights reserved.