我正尝试使用Azure AD验证我的Web应用程序中的用户以存储用户记录。为了验证用户,我正在使用ADAL4J API(https://github.com/AzureAD/azure-activedirectory-library-for-java)。我正在使用AuthenticationContext.acquireToken()方法来获取用户的令牌。这适用于我的目录中的本地用户,但不适用于邀请到目录的访客用户。使用图形API在Azure AD中验证访客用户
在对guest用户进行身份验证时,我收到一个错误消息:“要登录到此应用程序,必须将该帐户添加到目录中”。但是,我确信用户已成功添加到通过Azure门户看到的目录中。另外,我使用图API验证了相同的功能,我可以在目录中的用户列表中看到访客用户。
所以问题是我如何通过代码在我的web应用程序中对来宾用户进行身份验证(而不是通过重定向到Azure用户界面)?
编辑: 这种方法到我传递的用户的用户名和密码:
private static AuthenticationResult getAccessTokenFromUserCredentials(
String username, String password) throws Exception {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext("https://login.windows.net/<tenant_name>", false, service);
Future<AuthenticationResult> future = context.acquireToken(
"https://graph.windows.net", CLIENT_ID, username, password,
null);
result = future.get();
} catch(Exception e){
e.printStackTrace();
} finally {
service.shutdown();
}
if (result == null) {
throw new ServiceUnavailableException(
"authentication result was null");
}
return result;
}
您可以分享您为用户构建的登录URL的详细信息吗?您是否在使用“通用”端点或特定于租户的端点?你是如何添加访客用户的? –
我通过Azure用户界面添加了访客用户,之后我通过电子邮件为用户收到邀请。一旦我完成邀请中的说明,用户就被添加到我的目录中。我正在使用“常用”端点。 我的验证码如下所示: context = new AuthenticationContext(“https://login.windows.net/common”,false,service); 未来 future = context.acquireToken( “https://graph.windows.net”,CLIENT_ID,用户名,密码, null); –
在这段代码片段中,什么是“服务”...也应该使用端点“login.microsoftonline.com”。还有一个具体的原因,你传递的用户名和密码来获取令牌,而不是遵循[授权代码授权流程](https://docs.microsoft.com/en-us/azure/active-directory/develop /有源目录的协议-OAuth的代码)? –