我正在将 Azure AD 登录身份验证集成到我的 Web 应用程序中。我在 azure 开发门户中创建了一个帐户并将我的应用程序注册为 Web 应用程序。在应用注册设置中,我提供了如下所示的重定向 URL,
重定向 URL:https://mdb-dev-ext.xyzcde.com/my.dashboard/azureLogin.html?
在我的 java web 应用程序中,我已经实现了在上述端点 (azureLogin.html) 中获取 azure 令牌的逻辑。我已经使用 ADAL java 库来实现以下代码逻辑
private AuthenticationResult acquireTokenByAuthorizationCode(String authCode) {
String authority = System.getProperty("dashboard.azure.authority.url", "https://login.microsoftonline.com/xxxxxxxxxxxxxxxxxxx/oauth2/token");
String clientId = System.getProperty("dashboard.azure.client.id", "xxxxxxxxxxxxxxxxxxxxxxxxx");
String clientSecret = System.getProperty("dashboard.azure.client.secret", "xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
String redirectUrl = System.getProperty("dashboard.azure.redirect.uri", "https://mdb-dev-ext.xyzcde.com/my.dashboard/azureLogin.html?");
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
AuthenticationContext context = new AuthenticationContext(authority, false, service);
ClientCredential credential = new ClientCredential(clientId, clientSecret);
Future<AuthenticationResult> future = context.acquireTokenByAuthorizationCode(authCode, URI.create(redirectUrl), credential, null);
result = future.get();
} catch (Exception e) {
LOGGER.error("Error occurred while acquiring token from Azure {}", e.getMessage());
throw new Exception(String.format("Error occurred while acquiring token from Azure. %s", e.getMessage()));
}
return result;
}
注意:我没有为“主页 URL”提供值我相信这不是强制性的
现在在执行以下步骤时,我遇到了错误
登录到portal.office.com
使用我的帐户凭据登录
登陆 office 365 主页后,我可以看到我的 web 应用程序的图标已列出
单击我的网络应用程序的图标/按钮时,我被重定向并最终抛出以下错误。我的网络应用程序的服务器日志中没有日志更新。我确定这还没有到达我的网络应用程序。
"You cannot access this application because it has been misconfigured. Contact your IT department and include the following information:
Undefined Sign-On URL for application"
如果我为主页 URL 字段提供了我的 Web 应用程序的登录 URL,如下所示,
主页网址:https ://mdb-dev-ext.xyzcde.com/my.dashboard
然后在尝试从 office 365 打开我的应用程序时,它正在打开我的网络应用程序的登录页面(它将提示输入应用程序的数据库用户名和密码)。这不是我要找的。
我想要实现的是 -> 登录到 Office 365 -> 单击我的 Web 应用程序按钮 -> 在我的应用程序注册期间应该加载 azure 门户中提到的重定向 URL -> 最终将调用在我的 Web 应用程序中编写的代码逻辑获取 azure 令牌并使用会话中存储的 azure 返回令牌登录到我的应用程序。
请让我知道我在这里想念什么。为什么我会因为应用程序错误而收到此未定义的登录 URL?在 Office 365 门户中单击我的应用程序图标时,为什么它没有重定向到配置的重定向 URL?
