gpt4 book ai didi

azure - Postman 预请求脚本中身份验证响应的 Authorization_code

转载 作者:行者123 更新时间:2023-12-03 06:57:23 26 4
gpt4 key购买 nike

对于 Postman 中的许多集合,我们使用授权类型 =授权代码(到 Azure)。对于使用授权类型客户端凭据的请求,我可以编写自动获取 token 的预请求脚本(如果需要),并且我希望有一个用于授权代码<的脚本 也流。那里有很多与基本授权(用户名/密码)流程相关的示例,但我还没有找到任何与授权代码流程相关的示例。

以下是我必须根据 MS docs 执行的步骤):

  1. 我调用 POST 方法到 https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize包含所有必需的参数,如 redirect_uri 我使用 https://www.getpostman.com/oauth2/callback
  2. 身份验证成功后,Azure 将代码作为回调请求中的 url 参数发送到提供的 redirect_uri。在浏览器中它看起来像这样 https://www.getpostman.com/oauth2/callback/?code=authorizationCodeGeneratedByAzure
  3. 为了进一步进行,我现在需要以某种方式观察 redirect_uri,以捕获传入请求(来自 Azure 的回调)并以某种方式从请求 URL 参数中获取代码,以便在下面进一步使用请求获取 token 。这就是我不知道该怎么做。

所以我的问题是:

在 Prerequest 脚本中成功进行身份验证后,如何从发送到 redirect_uri 的 Azure 身份验证响应的 URL 中获取授权码?

最佳答案

希望您在 authorization_code 流程和应用程序中作为 WebApp 执行此操作。

因此,对于 authorization_code 流程,有 2 个步骤来获取访问 token 。

  • 首先从/authorize 端点获取代码。
  • 使用该代码从/token 端点获取访问 token 。

https://www.getpostman.com/oauth2/callback/?code=authorizationCodeGeneratedByAzure

正如您提到的,您从 redirect-uri 获取了 code,您只需提取此代码即可将 token 端点与 client_secret 一起传递 获取 token 。

After successful authentication Azure sends the code as url parameter in the callback request to provided redirect_uri.

要进行进一步的处理,请使用该code以及client_secret来获取 token 。

下面是来自 Postman 的示例 View 。

enter image description here

关于azure - Postman 预请求脚本中身份验证响应的 Authorization_code,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72787782/

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