简体   繁体   English

ASP.NET Core 2.0资源access_token

[英]ASP.NET Core 2.0 resource access_token

How do I acquire a OpenIdConnectParameterNames.AccessToken for a given resource (ex/ Power BI)? 如何获取给定资源(ex / Power BI)的OpenIdConnectParameterNames.AccessToken

I created a new ASP.NET Core 2.0 MVC project in VS2017 that uses AAD for authentication. 我在VS2017中创建了一个新的ASP.NET Core 2.0 MVC项目,该项目使用AAD进行身份验证。 Given an authenticated user, I need to get a resource access_token so that I can then make web api calls to said resource. 给定一个经过身份验证的用户,我需要获取一个资源access_token,以便随后可以对该资源进行Web api调用。

For my specific case, I'm trying to access Power BI content but this also applies to other resources such as graphQL. 对于我的特定情况,我尝试访问Power BI内容,但这也适用于其他资源,例如graphQL。

So far I've managed to get an idtoken which unfortunately doesn't seem to authenticate against the resource. 到目前为止,我设法获得了一个idtoken,不幸的是,该idtoken似乎并未针对该资源进行身份验证。 My attempts to fetch the access_token result in null . 我尝试获取access_token的结果为null

You should use ADAL/MSAL to get the access token in OnAuthorizationCodeReceived event of OpenID Connect OWIN middleware . 您应该使用ADAL / MSAL在OpenID Connect OWIN中间件的OnAuthorizationCodeReceived事件中获取访问令牌。 And ensure you have set the response type of OpenIdConnect Options to "code id_token" to implement Hybrid flow . 并确保将OpenIdConnect Options的响应类型设置为“ code id_token”以实现Hybrid flow。 With ADAL library , specify the resource(PowerBi rest endpoint in your scenario) in AcquireTokenByAuthorizationCodeAsync function . 随着ADAL库,指定资源在(PowerBi休息的情况下端点) AcquireTokenByAuthorizationCodeAsync功能。

Please refer to article : ASP.NET Core 2.0 Azure AD Authentication .@juunas provides the explanation and code sample in this article . 请参考文章: ASP.NET Core 2.0 Azure AD身份验证 。@ juunas在本文中提供了说明和代码示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM