简体   繁体   English

如何解决 Azure ADFS 设置中的 Power BI API 令牌问题?

[英]How to resolve the Power BI API token issue in the Azure ADFS Setup?

The code was working fine until we have setup the federated Azure AD (SSO).在我们设置联合 Azure AD (SSO) 之前,代码运行良好。 More info on this link.有关此链接的更多信息。 https://blogs.msdn.microsoft.com/azuredev/2018/01/22/accessing-the-power-bi-apis-in-a-federated-azure-ad-setup/ https://blogs.msdn.microsoft.com/azuredev/2018/01/22/accessing-the-power-bi-apis-in-a-federated-azure-ad-setup/

The source code is developed in python.源代码是用python开发的。

def token():

    username,password = login() #get login
    data = {
        'grant_type': 'password',
        'scope': 'openid',
        'resource': 'https://analysis.windows.net/powerbi/api',
        'client_id': '******',
        'username': username,
        'password': password
    }
    endpoint = 'https://login.microsoftonline.com/common/oauth2/token'
    r = requests.post(endpoint, data=data)
    data = r.json()
    access_token = data['access_token']
    headers = {'Content-Type': "application/json",
        'Authorization': 'Bearer ' +access_token}
    return headers

Error:
    access_token = data['access_token']
    KeyError: 'access_token'

Does anyone had this issue and resolved it?有没有人遇到过这个问题并解决了它?

Thanks in advance提前致谢

The reason this is not working is by default Azure AD will block ROPC flow for a Federated account.这不起作用的原因是默认情况下 Azure AD 将阻止联合帐户的 ROPC 流。 This flow only works if you are using a cloud account (onmicrosoft.com domain) for security reasons.此流程仅适用于出于安全原因使用云帐户(onmicrosoft.com 域)的情况。 If you need to authenticate with a Federated account, it's better if you use the ADAL library.如果您需要使用联合帐户进行身份验证,最好使用 ADAL 库。 We have an ADAL Java library here.我们这里有一个 ADAL Java 库。 https://github.com/AzureAD/azure-activedirectory-library-for-java/wiki/Acquiring-Tokens-with-username-and-password https://github.com/AzureAD/azure-activedirectory-library-for-java/wiki/Acquiring-Tokens-with-username-and-password

Also, please note that:另外,请注意:

Microsoft recommends you do not use the ROPC flow. Microsoft 建议您不要使用 ROPC 流。 In most scenarios, more secure alternatives are available and recommended.在大多数情况下,可以使用并推荐更安全的替代方案。 This flow requires a very high degree of trust in the application, and carries risks which are not present in other flows.此流程需要对应用程序具有非常高的信任度,并且会带来其他流程中不存在的风险。 You should only use this flow when other more secure flows can't be used.仅当无法使用其他更安全的流程时,才应使用此流程。

Reference:参考:

https://github.com/MicrosoftDocs/azure-docs/issues/34108 https://github.com/MicrosoftDocs/azure-docs/issues/34108

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

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