gpt4 book ai didi

azure - 如何在不注册或登录网络应用程序的情况下获取访问 token ?

转载 作者:行者123 更新时间:2023-12-02 03:15:02 24 4
gpt4 key购买 nike

我在 Web API 上使用 azure Graph API 创建了 b2c 用户,因为我必须在服务器端而不是客户端(例如 Web 应用程序或移动应用程序)创建用户。我在链接( https://learn.microsoft.com/en-us/previous-versions/azure/ad/graph/api/users-operations#CreateLocalAccountUser )中执行了步骤。我的问题是我无法获取用于访问 protected Web API 的访问 token 。如何获取访问 token ?

最佳答案

@Md Farid Uddin Kiron 是正确的,但您也可以在没有 AD B2C 用户的情况下获得访问 token 。

https://learn.microsoft.com/en-us/graph/auth-v2-service?view=graph-rest-1.0#4-get-an-access-token

token 请求的构建如下:

POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded

client_id=535fb089-9ff3-47b6-9bfb-4f1264799865
&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default
&client_secret=qWgdYAmab0YSkuL1qKv5bPX
&grant_type=client_credentials

广告 B2C 示例:

https://login.microsoftonline.com/contosob2c.onmicrosoft.com/oauth2/v2.0/token

client_id 来自您的应用注册:

enter image description here

scope 是来自公开 API应用程序 ID URI,后跟 /.default。如果没有/.default,您将收到如下错误:

"error": "invalid_scope", "error_description": "AADSTS1002012: Theprovided value for scopehttps://contosob2c.onmicrosoft.com/11111111-1111-1111-1111-111111111111is not valid. Client credential flows must have a scope value with/.default suffixed to the resource identifier (application IDURI)...", "error_codes": [1002012],

enter image description here

如果您想从 Microsoft Graph 访问某些内容,请将范围设置为https://graph.microsoft.com/.default

enter image description here

client_secret 来自证书和 secret

完整请求:

enter image description here

关于azure - 如何在不注册或登录网络应用程序的情况下获取访问 token ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56393182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com