首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用adal4j +登录/密码的ClientCredential身份验证

使用adal4j +登录/密码的ClientCredential身份验证
EN

Stack Overflow用户
提问于 2017-12-04 14:25:03
回答 1查看 917关注 0票数 0

我用Adal4j连接到Azure广告,让本地应用程序访问。

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

代码语言:javascript
复制
AuthenticationContext : public Future<AuthenticationResult> acquireToken(
    final String resource, final String clientId,
    final String username, final String password,
    final AuthenticationCallback callback)

现在,我打算在web应用程序中使用相同的代码。因此,我在Azure中注册了一个Web应用程序,并检查了“代理权限”和“组织使用的在线访问CRM”。

我首先尝试进行任何更改,并收到了以下错误:

{"error_description":"AADSTS70002:请求主体必须包含以下参数:'client_secret或客户端_断言‘。\r\n跟踪ID:

为了进行测试,我更新了ClientAuthenticationPost.toParameters()方法以强制使用client_secret,它可以工作:

代码语言:javascript
复制
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;
}

我的问题是,为什么没有这样的方法'clientCredential +登录/密码‘:

代码语言:javascript
复制
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)

应该加进去吗?或者我认证的方式是错误的?

诚挚的问候。

EN

回答 1

Stack Overflow用户

发布于 2017-12-06 08:31:41

下面是我添加的AuthenticationContext类的助手方法:

代码语言:javascript
复制
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应用程序的委托权限。

为什么这个不见了?这种联系方式确实有意义还是没有意义?

诚挚的问候。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47635496

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档