我们有两个 RestAPI,托管在 azure Kubernetes 中。这些 API 使用 Azure 应用程序通过 SSO 对用户进行身份验证。我们计划从一个 api(连接到其自己的应用程序)获取 token ,并在另一个 API(连接到另一个应用程序)中使用它。有办法实现这个目标吗?目前,api1 中生成的 token 在 api2 中无效,反之亦然。对于 API,我们使用此配置。希望我的问题很清楚,如果需要进一步说明,请告诉我。
用户模拟和范围(更多详细信息为 here )
我们正在使用access_token和oath2 This与我的非常相似,但我们不打算访问 Azure 资源,因此不确定这个问题的答案是否仍然适用于我们的问题。
我遇到了this但不确定这是否是最好的解决方案,甚至是一个解决方案。
需要澄清的是,所有 Azure 应用程序和 API 都位于一个租户中。
最佳答案
I agree with @Jack Jiang, you can make use of On-Behalf-of flow to achieve your scenario.
我为示例 webapi1
webapi2
webapi3
创建了三个 Azure AD 应用程序。
在 webapi1
中,我添加了以下 Api 权限:
在 webapi2
中,我添加了以下 Api 权限:
我通过 Postman 使用以下参数为 webapi1
生成了访问 token :
https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
client_id:webapi1ClientId
scope:api://webapi2ID/webapi2.read
grant_type:authorization_code
redirect_uri:https://jwt.ms
code:code
client_secret:ClientSecret
使用上面生成的访问 token ,我尝试调用 webapi3
Api,如下所示:
https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
client_id:webapi2ClientID
client_secret:ClientSecret
grant_type:urn:ietf:params:oauth:grant-type:jwt-bearer
assertion:access_token_generatedabove
requested_token_use:on_behalf_of
scope:api://webapi3ID/webapi3.read
否则,您可以使用 Client Credential flow调用 API。
引用:
Microsoft identity platform and OAuth2.0 On-Behalf-Of flow - Microsoft Entra
关于azure - 多个azure应用程序如何使用相同的jwt token 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76808038/