简体   繁体   English

Power BI REST身份验证和权限

[英]Power BI REST authentication and permissions

I'm attempting to create a bridge between another service (as a data source) and Microsoft Power BI. 我试图在另一个服务(作为数据源)和Microsoft Power BI之间建立桥梁。 However, I can't get the REST API to work properly. 但是,我无法使REST API正常工作。

So far I've succeeded in creating a web application in Azure AD, getting the Client ID and secret, receiving an access token for the API, but after this all I get is 403 Forbidden with no error message. 到目前为止,我已经成功地在Azure AD中创建了一个Web应用程序,获得了客户端ID和密码,并接收了API的访问令牌,但在此之后,我得到的是403 Forbidden ,没有错误消息。 However, if I try to access the API with an expired token, I get an error message telling me that the token is expired. 但是,如果尝试使用过期的令牌访问API,则会收到一条错误消息,告诉我令牌已过期。

I've read some posts on the subject, but they all suggest that the REST API cannot be accessed without having a user log in and access Power BI first, which isn't possible in a service-to-service application. 我已经阅读了有关该主题的一些文章,但是它们都建议在没有用户登录并首先访问Power BI的情况下无法访问REST API,这在服务到服务的应用程序中是不可能的。

How do I properly access the service without any user interaction? 如何在没有任何用户交互的情况下正确访问服务?

Here are the requests and responses, censored a little bit. 这是请求和响应,经过了一些审查。

Request 1: 要求1:

POST /[our domain].com/oauth2/token HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Cookie: flight-uxoptin=true; stsservicecookie=ests; x-ms-gateway-slice=productiona; stsservicecookie=ests
Host: login.microsoftonline.com
Connection: close
User-Agent: Paw/2.3 (Macintosh; OS X/10.11.3) GCDHTTPRequest
Content-Length: 203

grant_type=client_credentials&client_id=[client id]&client_secret=[client secret]&resource=https%3A%2F%2Fanalysis.windows.net%2Fpowerbi%2Fapi

Response 1: 回应1:

HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
x-ms-request-id: 52d6713c-d50b-4073-b030-aa10e33fdf27
client-request-id: 3aef4765-d602-46a6-a8ce-4b7792f678e5
x-ms-gateway-service-instanceid: ESTSFE_IN_209
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000; includeSubDomains
P3P: CP="DSP CUR OTPi IND OTRi ONL FIN"
Set-Cookie: x-ms-gateway-slice=productiona; path=/; secure; HttpOnly
Set-Cookie: stsservicecookie=ests; path=/
X-Powered-By: ASP.NET
Date: Wed, 24 Feb 2016 08:24:29 GMT
Connection: close
Content-Length: 1243

{"token_type":"Bearer","expires_in":"3599","expires_on":"1456305870","not_before":"1456301970","resource":"https://analysis.windows.net/powerbi/api","access_token":"[access token]"}

Request 2: 要求2:

GET /v1.0/myorg/datasets HTTP/1.1
Authorization: Bearer [access token]
Content-Length: 0
Host: api.powerbi.com
Connection: close
User-Agent: Paw/2.3 (Macintosh; OS X/10.11.3) GCDHTTPRequest

Response 2: 回应2:

HTTP/1.1 403 Forbidden
Content-Length: 0
Server: Microsoft-HTTPAPI/2.0
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Frame-Options: deny
X-Content-Type-Options: nosniff
RequestId: 803cc0cb-c65d-4212-9ab8-aed4ffa9862a
Date: Wed, 24 Feb 2016 08:25:13 GMT
Connection: close

The APIs you're using require a user's access token. 您使用的API需要用户的访问令牌。 They access content in a user's account. 他们访问用户帐户中的内容。 So if you don't have the access token, you'll keep getting forbidden. 因此,如果您没有访问令牌,则会不断被禁止。 So what you need to do is get the access token with the user the first time. 因此,您需要做的是第一次与用户一起获得访问令牌。 Then store the refresh token. 然后存储刷新令牌。 Then use the refresh token to get new access tokens as needed. 然后根据需要使用刷新令牌获取新的访问令牌。 If the refresh token expires, you need to ask the user to sign in again. 如果刷新令牌过期,则需要要求用户再次登录。

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

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