在 Owin 中针对 Power Bi 进行身份验证

Authentication against Power Bi in Owin

我有一个使用 ASP MVC 使用 Azure AD 身份验证开发的应用程序。此应用程序应该 post 数据到 Power BI。我尝试按照本教程进行操作:https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-register-a-client-app/,它有效并且几乎正是我所需要的。

问题是它使用了Native App认证,而我的应用程序是一个网络应用程序。此外,我的应用程序已经针对 Azure AD 进行了身份验证,我不想再次询问用户凭据。

我假设我可以以某种方式从当前的 Owin 上下文中获取不记名令牌,并使用它对 Power BI 进行身份验证。这是正确的吗?我该怎么做?

我的应用是使用 VS 模板生成的简单应用,并启用了 AD 身份验证,因此 post 任何代码都没有意义。

已更新 啊,好的,只是一些细节(如果您需要更多,请告诉我): 登录(由 VS 生成)是:

if (!Request.IsAuthenticated)
            {
                HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" },
                    OpenIdConnectAuthenticationDefaults.AuthenticationType);
            }

身份验证类型是 "OpenIdConnect"

Startup.Auth.cs 是:

 app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

 app.UseCookieAuthentication(new CookieAuthenticationOptions());

 app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = clientId,
                    Authority = authority,
                    PostLogoutRedirectUri = postLogoutRedirectUri
                });

还有一点,我不确定post是否清楚。我的目标是使用当前登录的用户凭据对 PowerBi 进行身份验证。我系统中的每个用户都会有自己的报告显示在网络应用程序中

您应该选择 Authenticate your web appAzure Active Directory tenant 而不是使用 Power BI 注册客户端应用程序。

教程

Authenticate your web app

Azure Active Directory tenant

示例应用程序

https://github.com/Microsoft/PowerBI-CSharp/tree/master/samples/webforms/get-started-web-app-asp.net