Power BI REST身份验证和权限

时间:2016-02-24 08:53:23

标签: api rest azure powerbi

我尝试在另一个服务(作为数据源)和Microsoft Power BI之间创建桥接。但是,我无法使REST API正常工作。

到目前为止,我已成功在Azure AD中创建Web应用程序,获取客户端ID和密码,接收API的访问令牌,但在此之后,我得到的只是403 Forbidden没有错误信息。但是,如果我尝试使用过期的令牌访问API,我会收到一条错误消息,告诉我该令牌已过期。

我已经阅读了有关该主题的一些帖子,但他们都建议在没有用户登录并且首先访问Power BI的情况下无法访问REST API,这在服务中是不可能的 - 服务申请。

如何在没有任何用户互动的情况下正确访问服务?

以下是请求和回复,稍微审查了一下。

请求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

回应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]"}

请求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

回应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

1 个答案:

答案 0 :(得分:1)

您正在使用的API需要用户的访问令牌。他们访问用户帐户中的内容。因此,如果您没有访问令牌,您将继续被禁止。因此,您需要做的是第一次与用户一起获取访问令牌。然后存储刷新令牌。然后根据需要使用刷新令牌获取新的访问令牌。如果刷新令牌过期,则需要让用户再次登录。

相关问题