从 Postman 生成 Azure 访问令牌

Lea*_*ner 4 azure access-token azure-active-directory postman bearer-token

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

端点#

https://login.microsoftonline.com/:tenant_id/oauth2/token 
Run Code Online (Sandbox Code Playgroud)

参数#

tenant_id:As per id generation by azure.
Run Code Online (Sandbox Code Playgroud)

正文#(表单数据)

grant_type:client_credentials
client_id:As per id generation by azure.
client_secret:As per id generation by azure.
resource:Required URL
Run Code Online (Sandbox Code Playgroud)

回复#

    "token_type": "Bearer",
    "expires_in": "foo",
    "ext_expires_in": "foo",
    "expires_on": "foo",
    "not_before": "foo",
    "resource": "foo",
    "access_token":foo
Run Code Online (Sandbox Code Playgroud)

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

您能否帮助我在响应中还需要发送哪些内容才能获取有效的令牌 ID?

Md *_*ron 5

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

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

在此输入图像描述

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

在此输入图像描述

令牌端点或 URL:

https://login.microsoftonline.com/YourTenantName.onmicrosoft.com/oauth2/token
Run Code Online (Sandbox Code Playgroud)

请求参数:

grant_type:client_credentials
client_id:b603c7be_Your_App_ID_e6921e61f925
client_secret:Vxf1Sl_Your_App_Secret_2XDSeZ8wL/Yp8ns4sc=
resource:https://graph.microsoft.com 
Run Code Online (Sandbox Code Playgroud)

邮递员示例:

在此输入图像描述

令牌响应:

在此输入图像描述

公开您自己的 API:

当您想要授权您自己的 API 时,您可以在此处添加它。这样你的token就会包含这个权限并且可以访问这个API。参考这个文档

在此输入图像描述

为了更清楚,您可以参考官方文档