使用图 api 在 Azure AD 中对来宾用户进行身份验证
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() 方法为用户获取令牌。这适用于我目录中的本地用户,但不适用于受邀访问该目录的来宾用户。
在对来宾用户进行身份验证时出现错误:"To sign into this application the account must be added to the directory"。但是,我确信用户已成功添加到通过 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;
}
根据您提供的信息,我觉得这里的问题与登录端点有关。请记住,公共端点使用登录用户来帮助 'guess' 向哪个租户端点进行身份验证。如果您正在做更棘手的事情,例如来宾帐户,那么公共端点很可能无法找出所有正确的细节。
我建议您在整个过程中专门调用租户的登录端点,看看是否能解决您的问题。
如果有帮助请告诉我!
我正在尝试使用 Azure AD 对我的 Web 应用程序中的用户进行身份验证以存储用户记录。为了验证用户身份,我使用 ADAL4J API (https://github.com/AzureAD/azure-activedirectory-library-for-java)。我正在使用 AuthenticationContext.acquireToken() 方法为用户获取令牌。这适用于我目录中的本地用户,但不适用于受邀访问该目录的来宾用户。
在对来宾用户进行身份验证时出现错误:"To sign into this application the account must be added to the directory"。但是,我确信用户已成功添加到通过 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;
}
根据您提供的信息,我觉得这里的问题与登录端点有关。请记住,公共端点使用登录用户来帮助 'guess' 向哪个租户端点进行身份验证。如果您正在做更棘手的事情,例如来宾帐户,那么公共端点很可能无法找出所有正确的细节。
我建议您在整个过程中专门调用租户的登录端点,看看是否能解决您的问题。
如果有帮助请告诉我!