【问题标题】:Authorization_code from authentication response in the Postman prerequest script来自 Postman 预请求脚本中的身份验证响应的授权代码
【发布时间】:2022-06-29 15:51:07
【问题描述】:

对于 Postman 中的许多集合,我们使用授权类型=Authorization code(对 Azure)的授权。对于使用授权类型client credentials 的请求,我可以编写自动获取令牌的预请求脚本(如果需要),我也想为authorization code 流编写这样的脚本。那里有很多与basic authorization(用户名/密码)流程相关的示例,但我没有找到任何授权代码流程。

根据MS docs),这是我必须执行的步骤:

  1. 我使用所有必需的参数调用https://login.microsoftonline.com/{tenant}/oauth2/v2.0/authorize 的POST 方法,因为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 参数中获取代码,以便在以下获取令牌的请求中进一步使用.这就是我不知道该怎么做。

所以我的问题是:

Prerequest脚本中认证成功后,如何从发送到redirect_uri的Azure认证响应的url中获取authorization_code?​​p>

【问题讨论】:

    标签: azure oauth-2.0 postman-pre-request-script


    【解决方案1】:

    希望您在authorization_code 流程和应用程序中使用WebApp

    因此,对于authorization_code 流,获取访问令牌需要两个步骤。

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

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

    正如您提到的,您从redirect-uri 获得了code,您只需提取此代码以传递令牌端点以及client_secret 以获取令牌。

    身份验证成功后,Azure 将代码作为回调请求中的 url 参数发送到提供的redirect_uri

    如需进一步处理,请使用 codeclient_secret 获取令牌。

    以下是来自Postman 的示例视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-22
      • 2021-11-20
      • 1970-01-01
      相关资源
      最近更新 更多