Я пытаюсь получить токен, используя Oauth2. Проблема, с которой я сталкиваюсь, состоит в том, что я не получаю результат аутентификации или исключение. он просто попадает в строку AuthenticationResult result = await app.AcquireTokenByUsernamePassword(new[] { "Mail.Send" }, "somebody@test.com", pass)
и останавливается. Есть идеи?
static void Main(string[] args)
{
SampleConfiguration config = SampleConfiguration.ReadFromJsonFile("appsettings.json");
var appConfig = config.PublicClientApplicationOptions;
var app = PublicClientApplicationBuilder.CreateWithApplicationOptions(appConfig)
.Build();
SecureString pass = new SecureString();
string password = "******";
foreach (char c in password)
{
pass.AppendChar(c);
}
var test = SendRequest(app, pass);
}
private static async Task<bool> SendRequest(IPublicClientApplication app, SecureString pass)
{
try
{
AuthenticationResult result = await app.AcquireTokenByUsernamePassword(new[] { "Mail.Send" }, "somebody@test.com", pass)
.ExecuteAsync();
}
catch (Exception ex)
{
throw;
}
return true;
}
Json Файл
{
"Authentication": {
// Azure Cloud instance among:
// - AzurePublic (see https://aka.ms/aaddevv2). This is the default value
// - AzureUsGovernment (see https://docs.microsoft.com/azure/azure-government/documentation-government-developer-guide)
// - AzureChina (see https://docs.microsoft.com/azure/china/china-get-started-developer-guide)
// - AzureGermany (See https://docs.microsoft.com/azure/germany/germany-developer-guide)
"AzureCloudInstance": "AzurePublic",
// Azure AD Audience among:
// - AzureAdMyOrg (single tenant: you need to also provide the TenantId
// - AzureAdMultipleOrgs (multi-tenant): Any work and school accounts
// - AzureAdAndPersonalMicrosoftAccount (any work and school account or Microsoft personal account)
// - PersonalMicrosoftAccount (Microsoft personal account only)
"AadAuthorityAudience": "AzureAdMultipleOrgs",
// ClientId (ApplicationId) as copied from the application registration (which depends on the cloud instance)
// See docs referenced in the AzureCloudInstance section above
"ClientId": "xxx-xxx-xxx-xxxxxxxx"
},
// Web API. Here Microsoft Graph. The endpoint is different depending on the cloud instance
// (See docs referenced in the "AzureCloudInstance" section above.
"WebAPI": {
"MicrosoftGraphBaseEndpoint": "https://graph.microsoft.com"
}