使用客户端 登录/密码的Adal4J身份验证



i连接使用Adal4j的Azure AD,让本机应用访问MS CRM Web API。

我们使用此方法获取令牌:

AuthenticationContext : public Future<AuthenticationResult> acquireToken(
    final String resource, final String clientId,
    final String username, final String password,
    final AuthenticationCallback callback)

现在,我要为Web应用程序使用相同的代码。因此,我已经在Azure AD中注册了一个具有"委托权限"one_answers" Access CRM Online"的Web应用程序。

我首先尝试了任何更改,我收到了此错误:

14:18:03Z","错误":" Invalid_client"}

只是为了进行测试,我已经更新了ClientAuthenticationPost.toParameters()强制client_secret的方法,它有效:

Map<String, String> toParameters() {
    Map<String, String> params = new HashMap<String, String>();
    params.put("client_id", getClientID().getValue());
    params.put("client_secret", "___my_client_secret___"); // added line
    return params;
}

我的问题是,为什么没有这样的方法"客户端 登录/密码":

AuthenticationContext : public Future<AuthenticationResult> acquireToken(
    final String resource, final ClientCredential clientCredential, // ClientCredential = client_id + client_secret
    final String username, final String password,
    final AuthenticationCallback callback)

应该添加吗?还是我身份验证的方式是错误的?

最好的问候。

这是我添加了AuthenticationContext类的辅助方法:

public Future<AuthenticationResult> acquireToken(final String resource,
                                                 final ClientCredential clientCredential, final String username,
                                                 final String password, final AuthenticationCallback callback) {
    if (StringHelper.isBlank(resource)) {
        throw new IllegalArgumentException("resource is null or empty");
    }
    if (clientCredential == null) {
        throw new IllegalArgumentException("client credential is null");
    }
    if (StringHelper.isBlank(username)) {
        throw new IllegalArgumentException("username is null or empty");
    }
    if (StringHelper.isBlank(password)) {
        throw new IllegalArgumentException("password is null or empty");
    }
    final ClientAuthentication clientAuth = new ClientSecretPost(
            new ClientID(clientCredential.getClientId()), new Secret(
            clientCredential.getClientSecret()));
    return this.acquireToken(new AdalAuthorizatonGrant(
                    new ResourceOwnerPasswordCredentialsGrant(username, new Secret(
                            password)), resource), clientAuth, callback);
}

它适用于我的注册Web应用程序,并具有授权权限。

为什么缺少?这种连接的方式确实具有含义,或者它是无关的?

最好的问候。

相关内容

最新更新