使用 SPA 针对 Microsoft Graph 进行身份验证,然后在 Web 中使用令牌 API
Authenticating against Microsoft Graph with SPA and then using token in Web API
我有一个使用 msal.js, against an app registrered at the Application Registration Portal 对用户进行身份验证的 SPA。它成功检索到令牌,到目前为止一切正常。
然后我有一个 ASP.NET Web API 设置,它应该使用来自 SPA 的令牌代表用户向 Microsoft Graph 发出请求,这就是我 运行陷入困境。
到目前为止,我已经在 API 上设置了一个 OWIN 中间件,它应该在向图形发出请求之前验证令牌,但无论我尝试什么,它总是无效的。我尝试了 UseOpenIdConnectAuthentication
、UseOAuthBearerAuthentication
和 UseJwtBearerAuthentication
但仍然没有成功。 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 flow"正好解决了这个问题。这是针对 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.
我有一个使用 msal.js, against an app registrered at the Application Registration Portal 对用户进行身份验证的 SPA。它成功检索到令牌,到目前为止一切正常。
然后我有一个 ASP.NET Web API 设置,它应该使用来自 SPA 的令牌代表用户向 Microsoft Graph 发出请求,这就是我 运行陷入困境。
到目前为止,我已经在 API 上设置了一个 OWIN 中间件,它应该在向图形发出请求之前验证令牌,但无论我尝试什么,它总是无效的。我尝试了 UseOpenIdConnectAuthentication
、UseOAuthBearerAuthentication
和 UseJwtBearerAuthentication
但仍然没有成功。 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 flow"正好解决了这个问题。这是针对 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.