gpt4 book ai didi

javascript - 使用 SPA 对 Microsoft Graph 进行身份验证,然后在 Web API 中使用 token

转载 作者:行者123 更新时间:2023-11-30 21:17:52 24 4
gpt4 key购买 nike

我有一个使用 msal.js 对用户进行身份验证的 SPA , 针对在 Application Registration Portal 注册的应用程序.它成功检索到 token ,到目前为止一切正常。

然后我有一个 ASP.NET Web API 设置,它应该使用来自 SPA 的 token 代表用户向 Microsoft Graph 发出请求,这就是我遇到麻烦的地方。

到目前为止,我已经在 API 上设置了一个 OWIN 中间件,它应该在向图形发出请求之前验证 token ,但无论我尝试什么,它总是无效的。我尝试了 UseOpenIdConnectAuthenticationUseOAuthBearerAuthenticationUseJwtBearerAuthentication 但仍然没有成功。 SPA 和 API 使用相同的客户端 ID,颁发者设置为 https://login.microsoftonline.com/common/v2.0

我已经阅读了很多来自 MS 的 SO 问题和示例,但似乎没有任何内容可以解决此特定设置。根据this至少我认为这是可能的?

这是我正在使用的 nuget 包:

  <package id="Owin" version="1.0" targetFramework="net452" />
<package id="Microsoft.Owin" version="3.1.0" targetFramework="net452" />
<package id="Microsoft.Owin.Security" version="3.1.0" targetFramework="net452" />
<package id="Microsoft.Owin.Security.Jwt" version="3.1.0" targetFramework="net452" />
<package id="Microsoft.Owin.Security.OAuth" version="3.1.0" targetFramework="net452" />
<package id="Microsoft.Owin.Security.OpenIdConnect" version="3.1.0" targetFramework="net452" />

我使用的包是否正确,甚至可以这样设置吗?会喜欢一些关于我做错了什么的指示。

提前致谢!

最佳答案

“OAuth 2 On-Behalf-Of 流程”正是解决了这个问题。这是为 AAD V2 应用程序模型记录的 here .

The OAuth 2.0 On-Behalf-Of flow serves the use case where an application invokes a service/web API, which in turn needs to call another service/web API. The idea is to propagate the delegated user identity and permissions through the request chain. For the middle-tier service to make authenticated requests to the downstream service, it needs to secure an access token from Azure Active Directory (Azure AD), on behalf of the user.

关于javascript - 使用 SPA 对 Microsoft Graph 进行身份验证,然后在 Web API 中使用 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45488185/

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