나는 this 예제 응용 프로그램을 따라 왔으며 대부분의 경우 잘 작동합니다 ... 그러나 테스트 목적으로 만든 사용자 중 한 명에게는 예외가 발생합니다. 다음 코드 블록 :Azure 광고 - AdalSilentTokenAcquisitionException
public static string LookupDisplayNameOfAADObject(string objectId)
{
string objectDisplayName = null;
string tenantId = (ClaimsPrincipal.Current).FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;
string signedInUserID = (ClaimsPrincipal.Current).FindFirst(System.IdentityModel.Claims.ClaimTypes.NameIdentifier).Value;
string userObjectID = (ClaimsPrincipal.Current).FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
ClientCredential credential = new ClientCredential(ConfigurationManager.AppSettings["ida:ClientId"], ConfigurationManager.AppSettings["ida:ClientSecret"]);
AuthenticationContext authContext = new AuthenticationContext(string.Format(ConfigurationManager.AppSettings["ida:Authority"], tenantId), new ADALTokenCache(signedInUserID));
string test = string.Format(ConfigurationManager.AppSettings["ida:Authority"], tenantId);
AuthenticationResult result = authContext.AcquireTokenSilent(ConfigurationManager.AppSettings["ida:GraphApiIdentifier"], credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId));
HttpClient client = new HttpClient();
string doQueryUrl = string.Format(
"{0}{1}/directoryObjects/{2}?api-version={3}",
ConfigurationManager.AppSettings["ida:GraphApiIdentifier"], tenantId,
objectId, ConfigurationManager.AppSettings["ida:GraphApiVersion"]);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, doQueryUrl);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
HttpResponseMessage response = client.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{
var responseContent = response.Content;
string responseString = responseContent.ReadAsStringAsync().Result;
dynamic directoryObject = System.Web.Helpers.Json.Decode(responseString);
if (directoryObject != null) objectDisplayName = string.Format("{0} ({1})", directoryObject.displayName, directoryObject.objectType);
}
return objectDisplayName;
}
- AcquireTokenSilent가 AdalSilentTokenAcquisitionException을 던졌습니다 만이 단일 사용자의 경우는 ...
- 예외 메세지를 지정하지 않고있다 "토큰을 자동으로 획득하는 데 실패 호출 방법 AcquireToken을.".
AcquireToken 메서드는 사용자에게 다시 로그인하라는 메시지를 표시하며 사용자에게 묻는 것을 방지하기 위해 노력하고 있으며 명시된 것처럼이 한 사용자의 경우에만 발생합니다. 이 상황을 어떻게 처리해야합니까?
당신이 제공 한 답은 제가 다루고있는 것에 대한 통찰력을 주었지만 해결책은 문제를 해결하지 못했습니다 ...이 사용자로 다시 로그해도 예외는 여전히 발생합니다. 이 버그에 대해 가장 많이 알고있는 사실은이 사용자에 대해서만 발생한다는 사실입니다 ... 여기 더미 데이터로 작업하고 있기 때문에 데이터베이스를 삭제하고 새로운 데이터를 시작합니다. –
Bummer : (토큰 캐시를 디버깅하고 토큰 캐시를 디버깅해야하며 토큰을 찾을 수 있어야하지만 어떤 이유로 든 수행 할 수 없습니다 .. – juunas
좋아요! – juunas