gpt4 book ai didi

azure - 使用 id_token 对 Azure 广告保护应用程序进行身份验证

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

我有两个应用服务,均使用从 Azure 门户配置的 Azure 广告身份验证进行保护。

前端应用程序服务是有角度的。我遵循的身份验证方法如下。

  1. 加载角度应用程序。向 .auth/me 发送 get 请求,该请求返回我 id_token,据我所知,这是我的身份验证 token 。
  2. 我存储此 token ,然后将 header 中的此 token 作为 Authorization: Bearer *** 转发到我的第二个应用服务 API

但是我观察到,也许第二个应用服务广告允许 token 首次加载。它不一致并且总是给出 401 未经授权的错误。即使在使用 2-3 分钟内。

我不确定这是否是使用 id_token 的正确方法,或者需要使用其他 token 。

最佳答案

你混淆了 ID token 的目的和 access token .

这里应该使用访问 token 。

在此场景中,您的后端应用程序 protected Web API。

根据adp的建议,您需要遵循specific information :

Your app registration must expose at least one scope or oneapplication role. Scopes are exposed by web APIs that are called onbehalf of a user.

Application roles are exposed by web APIs called by daemonapplications (that calls your web API on their own behalf).

If you create a new web API app registration, choose the access tokenversion accepted by your web API to 2. For legacy web APIs, theaccepted token version can be null, but this value restricts thesign-in audience to organizations only, and personal Microsoftaccounts (MSA) won't be supported.

The code configuration for the web API must validate the token usedwhen the web API is called.

The code in the controller actions must validate the roles or scopesin the token.

有一个sample在 Github 中。

要使用 Azure AD 保护您的 API,您需要注册两个 Azure AD 应用,一个用于客户端应用(前端),另一个用于 API 应用(后端)。

在 API 应用程序中,您需要 expose API 。通过执行步骤 7 和步骤 8,您可以公开范围。

那么你需要configure the client app 。通过这里的步骤8,您可以将API应用程序公开的权限(范围)添加到客户端应用程序。

使用 MSAL 请求访问 token ,其中包括此权限(范围)。您可以在代码中验证它。如果权限符合您的预期,则允许客户端访问您的 API。

关于azure - 使用 id_token 对 Azure 广告保护应用程序进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64268984/

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