正如我提到的,如果我们想创建servicePrincipal,那么资源应该是
http://graph.windows.net
或
https://graph.microsoft.com
.
因此,我们需要添加权限来操作Azure AD Graph API或Microsoft Graph API。
Grant permission
我用azureactivedirectoryapi测试它。我这边工作正常。
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(client,
tenant,
key,
AzureEnvironment.AZURE);
Azure.Authenticated azureAuthClient = Azure.configure().authenticate(credentials);
String clusterId = "xxxxxxx";
ServicePrincipal servicePrincipal =
azureAuthClient.servicePrincipals()
.define(clusterId)
.withNewApplication("http://easycreate.azure.com/" + clusterId)
.definePasswordCredential("sppass")
.withPasswordValue("StrongPass!12")
.attach()
.create();