如何使用 SSL 从 Microsoft Graph 获取访问令牌
How to use SSL to fetch access token from Microsoft Graph
我有一个从 Microsoft Graph 获取访问令牌然后使用访问令牌调用 Microsoft Graph Apis 的应用程序。
我正在使用 MSAL jar 使用客户端证书身份验证。现在我不确定该方法是否使用 SSL 来获取访问令牌(因为我直接读取 .pfx 证书作为文件输入流)。
下面是我的代码:
public String getTokenUsingGraphCertificate(String clientId, String tenantId, String certificatePath, String certificatePassword) throws Exception {
String authority = MessageFormat.format(AUTHORITY_URL, tenantId);
IClientCredential credential = ClientCredentialFactory.createFromCertificate(
new FileInputStream(new File(certificatePath)), certificatePassword);
ConfidentialClientApplication cca = ConfidentialClientApplication.builder(clientId, credential)
.authority(authority)
// .setTokenCacheAccessAspect(tokenCacheAspect)
.build();
IAuthenticationResult result;
try {
SilentParameters silentParameters = SilentParameters.builder(SCOPE).build();
result = cca.acquireTokenSilently(silentParameters).join();
} catch (Exception ex) {
if (ex.getCause() instanceof MsalException) {
ClientCredentialParameters parameters = ClientCredentialParameters.builder(SCOPE).build();
result = cca.acquireToken(parameters).join();
} else {
log.error("Exception occurred while fetching access token using getTokenUsingGraphCertificate. ERROR is : {}",ex);
throw ex;
}
}
return result.accessToken();
}
现在,我如何使用 SSL 从使用客户端证书的 Microsoft Graph 获取访问令牌?
请帮忙。提前致谢
MSAL 使用 SSL 从身份验证端点获取令牌。可以用Fiddler之类的工具看流量验证一下。
我有一个从 Microsoft Graph 获取访问令牌然后使用访问令牌调用 Microsoft Graph Apis 的应用程序。
我正在使用 MSAL jar 使用客户端证书身份验证。现在我不确定该方法是否使用 SSL 来获取访问令牌(因为我直接读取 .pfx 证书作为文件输入流)。
下面是我的代码:
public String getTokenUsingGraphCertificate(String clientId, String tenantId, String certificatePath, String certificatePassword) throws Exception {
String authority = MessageFormat.format(AUTHORITY_URL, tenantId);
IClientCredential credential = ClientCredentialFactory.createFromCertificate(
new FileInputStream(new File(certificatePath)), certificatePassword);
ConfidentialClientApplication cca = ConfidentialClientApplication.builder(clientId, credential)
.authority(authority)
// .setTokenCacheAccessAspect(tokenCacheAspect)
.build();
IAuthenticationResult result;
try {
SilentParameters silentParameters = SilentParameters.builder(SCOPE).build();
result = cca.acquireTokenSilently(silentParameters).join();
} catch (Exception ex) {
if (ex.getCause() instanceof MsalException) {
ClientCredentialParameters parameters = ClientCredentialParameters.builder(SCOPE).build();
result = cca.acquireToken(parameters).join();
} else {
log.error("Exception occurred while fetching access token using getTokenUsingGraphCertificate. ERROR is : {}",ex);
throw ex;
}
}
return result.accessToken();
}
现在,我如何使用 SSL 从使用客户端证书的 Microsoft Graph 获取访问令牌? 请帮忙。提前致谢
MSAL 使用 SSL 从身份验证端点获取令牌。可以用Fiddler之类的工具看流量验证一下。