3
這是我自己編寫的代碼,並試圖讓輸出EX = {「AADSTS70002:請求體中必須包含下列參數:‘client_secret或client_assertion’
請求體必須包含以下。參數:
client_secret
或client_assertion
static async Task<AuthenticationResult> getAccessToken()
{
string hardcodedUsername = "";
string hardcodedPassword = "";
string tenantName = "projectwidgets.com";
string authString = "https://login.microsoftonline.com/" + tenantName;
AuthenticationContext authenticationContext = new AuthenticationContext(authString, false);
//Config for OAuth client credentials
string clientId = "as";
string key = "kk";
string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenantName);
var authContext = new AuthenticationContext(authority);
AuthenticationResult result = null;
try
{
result = await authContext.AcquireTokenAsync("https://pwsnapitazure.azurewebsites.net", clientId, new UserPasswordCredential(hardcodedUsername, hardcodedPassword));
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
System.Diagnostics.Debug.WriteLine(ex.Message);
}
return result;
}