Azure 数据工厂 - 无法验证 invalid_grant

Azure Data Factory - Trouble authenticating invalid_grant

在尝试使用 Active Directory 进行身份验证以检索访问令牌时,我遵循了以下步骤:

1 - 按照以下说明在 Azure 中创建了一个应用程序(第 3 步): https://github.com/Azure-Samples/active-directory-java-native-headless#step-3--register-the-sample-with-your-azure-active-directory-tenant

2 - 创建了具有 "Data Factory Contributor" 权限的 "Azure Active Directory" 用户帐户。

3 - 使用下面(url)中的步骤,我按照示例代码尝试检索访问令牌: https://github.com/Azure-Samples/active-directory-java-native-headless/blob/master/src/main/java/PublicClient.java

注意:我使用的资源是... https://management.core.windows.net/

...以下面为例: https://docs.microsoft.com/en-us/azure/data-factory/quickstart-create-data-factory-rest-api#authenticate-with-azure-ad

4 - 服务器响应以下错误:

Exception in thread "main" java.util.concurrent.ExecutionException:
com.microsoft.aad.adal4j.AuthenticationException:
 {
    "error_description": "AADSTS65001: The user or administrator has not
    consented to use the application with ID '<my-app-id>' named
    '<my-app-name>'. Send an interactive authorization request for this
    user and resource.\r\nTrace ID: d0af56e6-aaa3-4d25-b23b-
    2984ed2b4400\r\nCorrelation ID: 2422cc2f-1cdd-45c5-8b7c-
    46b1eee4ffae\r\nTimestamp: 2019-03-22 04:58:16Z",

    "error": "invalid_grant"
 }

需要哪些授权才能使身份验证生效?

您应该向 Azure AD 发出授权请求,其中包括参数 prompt=admin_consent。

转到URL,例如https://login.microsoftonline.com/tenant-id/oauth2/authorize?client_id=app-client-id&redirect_uri=encoded-reply-url&response_type=code&prompt=admin_consent

使用您的管理员帐户同意权限。

然后就可以成功获取access token了