我可以使用这些参数获得不记名令牌
Get-MsalToken -ClientId '' -TenantId '' -Scopes ''
我正在尝试将其转换为使用 C# 而不是 PowerShell:
var clientId = "xyz";
var tenantId = "xyz";
// We intend to obtain a token for Graph for the following scopes (permissions)
string[] scopes = { $"{clientId}/.default" };
string authority = $"https://login.microsoftonline.com/{tenantId}";
IPublicClientApplication app = PublicClientApplicationBuilder.Create(clientId)
.WithAuthority(new Uri(authority))
.WithRedirectUri("http://localhost")
.Build();
AuthenticationResult result = await app.AcquireTokenInteractive(scopes).ExecuteAsync();
var token = result.AccessToken;
但是我收到一条错误消息:“请求中指定的重定向 URI 'http://localhost' 与为应用程序配置的重定向 URI 不匹配”
发生这种情况是因为 Azure 中的应用程序未配置为重定向到
localhost
。您需要在 Azure 门户中更新它。请参阅:https://learn.microsoft.com/en-us/troubleshoot/azure/active-directory/error-code-aadsts50011-redirect-uri-mismatch