【Azure Developer】使用 adal4j(Azure Active Directory authentication library for Java)如何来获取

本文档详细解答了使用adal4j在Azure中国区获取Token时遇到的问题,包括AUTHORITY的含义与获取Tenant ID的方法,以及如何找到正确的Resource URL和Client ID。并提供了完成参考实例代码。
摘要由CSDN通过智能技术生成

问题描述

使用中国区的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 有以下四个值。

  1. AzureChina :The host of the Azure Active Directory authority for tenants in the Azure China Cloud.  AZURE_CHINA  =  "login.chinacloudapi.cn"
  2. AzureGermany : The host of the Azure Active Directory authority for tenants in the Azure German Cloud.  AZURE_GERMANY  =  "login.microsoftonline.de"
  3. AzureGovernment : The host of the Azure Active Directory authority for tenants in the Azure US Government Cloud.  AZURE_GOVERNMENT  =  "login.microsoftonline.us"
  4. AzurePublicCloud : The host of the Azure Active Directory authority for tenants in the Azure Public Cloud. AZURE_PUBLIC_CLOUD  =  "login.microsoftonline.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值