我需要您的帮助,我正在使用Azure合作伙伴中心SDK(java)创建与Azure云的链接。
我正在使用以下代码来执行身份验证部分,并且它在Microsoft文档中有所提及。
IAggregatePartner partnerOperations = PartnerCredentials.getInstance().generateByApplicationCredentials(
"ApplicationId"
"ApplicationSecret",
"AccountId");
但是当我运行代码时,出现此错误:
**Exception in thread "main" PartnerException: ErrorCategory: NOT_SPECIFIED, ServiceErrorPayload: null, Context: null, Base Description: com.microsoft.store.partnercenter.exception.PartnerException: Failed to do the application AAD login
at com.microsoft.store.partnercenter.extensions.ApplicationPartnerCredentials.authenticate(ApplicationPartnerCredentials.java:172)
at com.microsoft.store.partnercenter.extensions.PartnerCredentials.generateByApplicationCredentials(PartnerCredentials.java:69)
at com.microsoft.store.partnercenter.extensions.PartnerCredentials.generateByApplicationCredentials(PartnerCredentials.java:50)
at com.contoso.PartnerApp.App.main(App.java:19)
Caused by: java.lang.IllegalArgumentException: authority Uri should have at least one segment in the path (i.e. https://<host>/<path>/...)
at com.microsoft.aad.msal4j.Authority.detectAuthorityType(Authority.java:72)
at com.microsoft.aad.msal4j.ClientApplicationBase$Builder.authority(ClientApplicationBase.java:257)
at com.microsoft.store.partnercenter.extensions.ApplicationPartnerCredentials.authenticate(ApplicationPartnerCredentials.java:155)**
... 3 more
谢谢你的帮助。
最佳答案
根据您的错误消息,您没有提供有效的权限Uri。如果要使用Azure合作伙伴中心SDK(java)完成应用程序身份验证,建议您使用以下方法
public IPartnerCredentials generateByApplicationCredentials(String clientId, String applicationSecret,
String aadApplicationDomain,
String aadAuthorityEndpoint,
String graphEndpoint
例如
更新Web应用程序并配置所需的权限。有关更多详细信息,请参阅https://docs.microsoft.com/en-us/partner-center/develop/create-apps-for-partner-center-for-microsoft-national-clouds#web-apps。
在合作伙伴中心获取所需的信息
写代码
String clientId="the applicationId of your app you create";
String applicationSecret="the app secrret";
String aadApplicationDomain ="your account id ";
String aadAuthorityEndpoint="https://login.windows.net/";
String graphEndpoint="https://graph.windows.net";
IPartnerCredentials appCred = PartnerCredentials.getInstance().generateByApplicationCredentials( clientId,applicationSecret,aadApplicationDomain,aadAuthorityEndpoint,graphEndpoint);
IAggregatePartner partnerOperations = PartnerService.getInstance().createPartnerOperations(appCred);
Customer customer = partnerOperations.getCustomers().byId("e4c9ab4e-bd27-40d5-8459-230ba2a757fb").get();
System.out.print("The custom's Commerce ID : " + customer.getCommerceId());
更新资料
关于权限的配置,请参考下图