【发布时间】:2022-02-09 09:49:17
【问题描述】:
我正在使用this 指南为 Snowflake 中的外部 OAuth 配置 Microsoft Azure AD。 我很确定我遵循了所有步骤,因为我在三个 Azure 订阅上进行了细致的尝试并得到了相同的结果。
每次我卡在testing procedure 部分时,我都应该向 Azure AD 发送请求以获取访问令牌:
curl -X POST -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" \
--data-urlencode "client_id=<OAUTH_CLIENT_ID>" \
--data-urlencode "client_secret=<OAUTH_CLIENT_SECRET>" \
--data-urlencode "username=<AZURE_AD_USER>" \
--data-urlencode "password=<AZURE_AD_USER_PASSWORD>" \
--data-urlencode "grant_type=password" \
--data-urlencode "scope=session:role:analyst" \
'<AZURE_AD_OAUTH_TOKEN_ENDPOINT>'
我是订阅所有者,并且绝对授予对 session:role:analyst 范围的管理员访问权限:
但是,我得到的不是访问令牌,而是以下响应:
{
"error": "invalid_grant",
"error_description": "AADSTS65001: The user or administrator has not consented to use the application with ID '...' named 'Snowflake OAuth Client'. Send an interactive authorization request for this user and resource.\r\nTrace ID: ...\r\nCorrelation ID: ...\r\nTimestamp: ...",
"error_codes": [
65001
],
"timestamp": "...",
"trace_id": "...",
"correlation_id": "...",
"suberror": "consent_required"
}
试图通过到达https://login.microsoftonline.com/{{tenant_id}}/adminconsent?client_id={{client_id}} 来授予同意,在授予同意后,得到一个错误:AADSTS500113: No reply address is registered for the application.
找到this 并添加了返回URL http://localhost/ (不清楚为什么)。再次同意并被重定向到 http://localhost/?admin_consent=True&tenant={{tenant_id}}#,我想这很好。
但我仍然收到AADSTS65001: The user or administrator has not consented to use the application。
查阅了 Microsoft 文档并发现使用 grant_type=password is not recommended - 是有道理的。
已尝试grant_type=client 凭据:
curl --location --request GET 'https://login.microsoftonline.com/{{tenant_id}}/oauth2/v2.0/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id={{client_id}}' \
--data-urlencode 'scope=https://graph.microsoft.com/.default' \
--data-urlencode 'client_secret={{client_secret}}'
获得访问令牌,但尝试使用如下连接字符串连接到 Snowflake:
connection.ConnectionString = $"account={account};host={host};authenticator=oauth;user={oauthUser};token={token};";
抛出Snowflake.Data.Client.SnowflakeDbException: 'Invalid OAuth access token.。
我怀疑这是因为scope=https://graph.microsoft.com/.default,但是用session:scope:analyst 替换它会带来这个:
{
"error": "invalid_scope",
"error_description": "AADSTS1002012: The provided value for scope session:scope:analyst is not valid. Client credential flows must have a scope value with /.default suffixed to the resource identifier (application ID URI).\r\nTrace ID: ...\r\nCorrelation ID: ...\r\nTimestamp: ...",
"error_codes": [
1002012
],
"timestamp": "...",
"trace_id": "...",
"correlation_id": "..."
}
由于我已经偏离了官方的 Snowflake 指南,因此我正在向社区寻求有关此问题的帮助。提前谢谢你!
【问题讨论】:
标签: oauth-2.0 azure-active-directory snowflake-cloud-data-platform