Azure AD 시스템에서 인증 토큰을 검색하려고합니다. await 명령과 함께 async 메서드를 구성하는 여러 가지 방법을 시도했지만 "작업이 취소되었습니다."라는 오류가 발생할 때마다 시도했습니다.웹 응용 프로그램의 Azure 비동기 인증 토큰
aspx 페이지에 async = "true"가 있습니다.
성공적인 요청을 받고 토큰을 검색하기 위해 다르게해야 할 아이디어가 있습니다.
동일한 코드가 콘솔 응용 프로그램에서 작동하므로 문제는 비동기 작업이 발생하는 방식과 관련이 있다고 가정합니다. 다음과 같이
내 코드는 다음과 같습니다
protected async void Login_click(object sender, EventArgs e)
{
response1.Text = "Started";
var tentantID = ConfigurationManager.AppSettings["tenantID"];
var clientId = ConfigurationManager.AppSettings["applicationID"];
var secret = ConfigurationManager.AppSettings["secret"];
await Authorize(tentantID , clientId, secret);
}
private async Task<AuthenticationResult> GetToken(string clientId, string tenantDomain, string clientSecret)
{
AuthenticationResult result = null;
var context = new AuthenticationContext("https://login.microsoftonline.com/" + tenantDomain);
try
{
ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);
return result = await context.AcquireTokenAsync("https://management.core.windows.net/", clientCredential).ConfigureAwait(false);
}
catch (AdalException ae)
{
//Error code
return null;
}
catch (Exception e)
{
//Error code
return null;
}
}
private async Task Authorize(string tenant, string clientId, string clientSecret)
{
var authenticationResult = await GetToken(clientId, tenant, clientSecret).ConfigureAwait(false);
string token = authenticationResult.AccessToken;
}
편집이 ... 내 업데이트 된 코드 : ASP.NET에서
protected void Login_click(object sender, EventArgs e)
{
response1.Text = "Started";
RegisterAsyncTask(new PageAsyncTask(Authorize));
}
public async Task Authorize()
{
var tentantID = ConfigurationManager.AppSettings["tenantID"];
var clientId = ConfigurationManager.AppSettings["applicationID"];
string myKey = ConfigurationManager.AppSettings["myKey"];
var tenantDomain = ConfigurationManager.AppSettings["tenantDomain"];
var context = new AuthenticationContext("https://login.microsoftonline.com/" + tenantDomain, false);
try
{
ClientCredential clientCredential = new ClientCredential(clientId, myKey);
var result = context.AcquireTokenAsync("https://management.core.windows.net/", clientCredential).ConfigureAwait(false);
AuthenticationResult resVal = await result;
token = resVal.AccessToken;
}
catch (AdalException ae)
{
//error code
token = ae.InnerException.Message;
}
}
다음 중 어떤 줄이 오류입니까? 'GetToken()'내부에서 디버깅 할 경우 * catch * 블록을 입력합니까? – Alisson
AcquireTokenAsync 명령은 "A Task was cancelled"라는 내부 메시지가있는 AdalException을 throw합니다. –