【发布时间】:2021-01-26 10:55:59
【问题描述】:
我可以使用 PowerShell cmdlet MicrosoftPowerBIMgmt 通过 (1) 用户名和 (2) 密码参数输入来获取访问令牌。它完美地工作。请注意,它不需要 client_id 参数:
# PowerShell code:
Import-Module MicrosoftPowerBIMgmt
Function authenticate_powerbiserviceaccount($us, $pw)
{
# Convert plain text pw to secureString
$pw_secure = $pw | ConvertTo-SecureString -asPlainText -Force
# Authenticate
$credential = New-Object System.Management.Automation.PSCredential($us, $pw_secure)
Connect-PowerBIServiceAccount -Credential $credential
# Print access token auth_string
Get-PowerBIAccessToken -AsString
}
我找到了使用 ADAL 的身份验证 sn-ps,但它们都需要一个我没有且无法获取的 client_id 参数。
# Python code:
import adal
authority_url = 'https://login.windows.net/common'
context = adal.AuthenticationContext(
authority_url,
validate_authority=True,
api_version=None
)
token = context.acquire_token_with_username_password(
resource='https://analysis.windows.net/powerbi/api',
username=user_string,
password=pw_string,
client_id=client_id_string
)
access_token = token['accessToken']
是否可以构建一个 python 函数来获取给定用户名和密码的 auth_string 而无需 client_id?它看起来怎么样?
【问题讨论】:
标签: python python-3.x powerbi adal msal