2016-02-24 107 views
1

我试图在另一个服务(作为数据源)和Microsoft Power BI之间创建一个桥梁。但是,我无法使REST API正常工作。Power BI REST身份验证和权限

到目前为止,我已经成功地在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 
+0

嗨onik,你有没有得到任何解决方案获得访问令牌。我面临类似的问题。 –

+0

不,我没有进一步调查,我们决定使用Azure SQL将数据导入Power BI。 – onik

回答

1

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

+0

即使它不完全没有用户交互,我也接受了这个答案,但这是目前最好的解决方案。我听说MS正在改进他们的身份验证以允许纯粹的服务到服务身份验证,但它尚未发布。 – onik