我正在尝试连接到我的Azure帐户,为此,我需要创建TokenCredentials对象,该对象需要访问令牌作为参数。但是我在获取该访问令牌时遇到了问题。
我已尝试按照此示例的指导进行操作:https://github.com/Azure-Samples/azure-batch-samples/blob/master/CSharp/AccountManagement/Program.cs
这是我要运行的代码:
public static async Task<ServiceClientCredentials> CreateTokenCredentialsAsync()
{
var clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
var redirectUri = "https://myredirecturi.com";
var authorityUri = "https://login.microsoftonline.com/common";
var resourceUri = "https://management.core.windows.net/";
var platformPrameters = new PlatformParameters(PromptBehavior.Auto);
var authContext = new AuthenticationContext(authorityUri);
AuthenticationResult authResult = await authContext.AcquireTokenAsync(
resourceUri,
clientId,
new Uri(redirectUri),
platformPrameters);
var token = authResult.AccessToken;
ServiceClientCredentials creds = new TokenCredentials(authResult.AccessToken);
return creds;
}
我收到以下异常:
Invalid resource.
The client has requested access to a resource which is not listed in the requested permissions in the client's application registration.
Client app ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx(<my registered app name>).
Resource value from request: https://management.core.windows.net/.
Resource app ID: yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyy.
List of valid resources from app registration: ...
该如何做才能获得访问令牌?
答案 0 :(得分:2)