问题描述
使用中国区的Azure,在获取Token时候,参考了 adal4j的代码,在官方文档中,发现了如下的片段代码:
ExecutorService service = Executors.newFixedThreadPool(1);
AuthenticationContext context = new AuthenticationContext(AUTHORITY, false, service);
Future<AuthenticationResult> future = context.acquireToken(
"https://graph.windows.net", YOUR_TENANT_ID, username, password,
null);
AuthenticationResult result = future.get();
System.out.println("Access Token - " + result.getAccessToken());
System.out.println("Refresh Token - " + result.getRefreshToken());
System.out.println("ID Token - " + result.getIdToken());
以上代码中,有一些参数很不明确:
1)AUTHORITY, 是什么意思呢?
2)acquireTokne方法中的 https://graph.windows.net 是指向global azure的资源,如果是中国区azure的资源,那么resource url是多少呢?
3)YOUR_TENANT_ID,它的值是什么呢?
问题解答
第一个问题:AUTHORITY, 是什么意思,它的值是什么呢?
AUTHORITY,表示认证的主体,它是一个URL,表示可以从该主体中获取到认证Token。 它的格式为:https://<authority host>/<tenant id> ,所以在使用Azure的过程中,根据Azure环境的不同,Host 有以下四个值。
- AzureChina :The host of the Azure Active Directory authority for tenants in the Azure China Cloud. AZURE_CHINA = "login.chinacloudapi.cn"
- AzureGermany : The host of the Azure Active Directory authority for tenants in the Azure German Cloud. AZURE_GERMANY = "login.microsoftonline.de"
- AzureGovernment : The host of the Azure Active Directory authority for tenants in the Azure US Government Cloud. AZURE_GOVERNMENT = "login.microsoftonline.us"
- AzurePublicCloud : The host of the Azure Active Directory authority for tenants in the Azure Public Cloud. AZURE_PUBLIC_CLOUD = "login.microsoftonline.com"
所以,
使用adal4j在Azure中国区获取Token指南

本文档详细解答了使用adal4j在Azure中国区获取Token时遇到的问题,包括AUTHORITY的含义与获取Tenant ID的方法,以及如何找到正确的Resource URL和Client ID。并提供了完成参考实例代码。
最低0.47元/天 解锁文章
447

被折叠的 条评论
为什么被折叠?



