我是一位经验丰富的Java开发人员(4-5年),但是Azure AD及其功能尚属新手,因此我很抱歉提出一个潜在的基本问题。我一直在努力寻找任何微软文档或覆盖Java中的这个话题的堆栈溢出问题(绝大多数是用C#),并且从我的理解来看,C#拥有比Java更多的Azure AD库,因此C#中的解决方案不一定是解决方案Java的。验证Java中的Azure AD签名
我想完成一个基于场景的身份验证POC,其中存在一个现有的Azure AD系统,充满了用户,我想充当身份验证点。我的Java应用程序将收集用户的用户名和密码(我理解这是过时的,并且不理想,但是出于需要的原因),并使用Microsoft adal4j库调用Azure端点,以便成功返回JWC访问权限令牌(除了刷新和ID令牌)。
这是我现有的检索JWC访问令牌的代码片段。
private static AuthenticationResult getAccessTokenFromUserCredentials(String username, String password, String
AUTHORITY, String CLIENT_ID) throws Exception {
AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
service = Executors.newFixedThreadPool(1);
context = new AuthenticationContext(AUTHORITY, false, service);
Future<AuthenticationResult> future = context.acquireToken(
"https://graph.windows.net", CLIENT_ID, username, password,
null);
result = future.get();
} finally {
service.shutdown();
}
if (result == null) {
System.out.println("ex)");
}
return result;
}
public void azureAuthenticate(String authority, String clientID, String username, String password){
AuthenticationResult result = null;
try {
result = getAccessTokenFromUserCredentials(username, password, authority, clientID);
DecodedJWT accessToken = JWT.decode(result.getAccessToken());
//Want to verify the validity of this access token
} catch (Exception ex) {
ex.printStackTrace();
}
}
我的代码主要是基于这个Microsoft documentation
接收令牌后,我需要能够验证其真伪(我的理解证实其索赔的业务逻辑的一面,但我很困惑,以如何验证签名是否合法)。
非常感谢您的帮助,我很乐意提供所需的任何说明。
现在想通了,谢谢。 – dFrancisco