[英]Authenticate guest user in Azure AD using graph api
我正在尝试使用 Azure AD 存储用户记录对我的 Web 应用程序中的用户进行身份验证。 为了对用户进行身份验证,我使用的是 ADAL4J API ( https://github.com/AzureAD/azure-activedirectory-library-for-java )。 我正在使用 AuthenticationContext.acquireToken() 方法来获取用户的令牌。 这适用于我目录中的本地用户,但不适用于受邀加入该目录的来宾用户。
在对来宾用户进行身份验证时,我收到一个错误:“要登录此应用程序,必须将帐户添加到目录中”。 但是,我确信用户已成功添加到通过 Azure 门户看到的目录中。 此外,我已经使用图形 API 进行了验证,我可以在其中看到目录中用户列表中的来宾用户。
所以问题是我如何通过代码(而不是通过重定向到 Azure UI)在我的 Web 应用程序中对来宾用户进行身份验证?
编辑:这是我将用户名和密码传递给的方法:
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;
}
根据您提供的信息,我觉得这里的问题与登录端点有关。 请记住,公共端点使用登录用户来帮助“猜测”要向哪个租户端点进行身份验证。 如果您正在做更棘手的事情,例如来宾帐户,则公共端点很可能无法找出所有正确的细节。
我建议您在整个过程中专门调用租户的登录端点,看看是否能解决您的问题。
让我知道这是否有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.