我用Adal4j连接到Azure广告,让本地应用程序访问。
我们使用此方法获取令牌:
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,它可以工作:
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 +登录/密码‘:
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)应该加进去吗?或者我认证的方式是错误的?
诚挚的问候。
发布于 2017-12-06 08:31:41
下面是我添加的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应用程序的委托权限。
为什么这个不见了?这种联系方式确实有意义还是没有意义?
诚挚的问候。
https://stackoverflow.com/questions/47635496
复制相似问题