2017-03-16 7 views
1

나는이 코드 샘플을 사용합니다 : https://github.com/Azure-Samples/active-directory-dotnet-graphapi-web,이 코드 샘플은 클라이언트 라이브러리를 사용하고 있지만, (httpclient를 사용하여) perfmon 쿼리를 사용하려면 api 호출을 직접 사용하려면 아래 코드를 사용하여 액세스 토큰을 얻습니다. 캐시 :캐시에서 토큰을 찾을 수 없으므로 토큰을 자동으로 획득하지 못했습니다. 호출 메서드 AcquireToken

string userObjectID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value; 
AuthenticationContext authContext = new AuthenticationContext(Startup.Authority, new NaiveSessionCache(userObjectID)); 
ClientCredential credential = new ClientCredential(clientId, appKey); 
var result = await authContext.AcquireTokenSilentAsync(resource, credential, new UserIdentifier(userObjectID, UserIdentifierType.UniqueId)); 

하지만 난 항상 오류 던졌다 발견 : 더 토큰이 캐시에서 발견되지 않았다으로 토큰을 자동으로 획득하는 데 실패합니다. 통화 방법 AcquireToken

+0

이 시나리오를 테스트하려면 로그 아웃하고 다시 로그인 해 보셨습니까? –

답변

1

나는 당신의 오류를 재현 할 수 있었다. this link에 따르면 AcquireTokenSilentAsync (NaiveSessionCache 사용)를 사용할 때 코드 샘플이 작동하지 않는 것 같습니다. NaiveSessionCache.cs를 this으로 수정하십시오.

도움이되는지 알려주세요.

+0

이 코드 샘플과 관련된 새로운 질문이 있으시면 http://stackoverflow.com/questions/42920678/how-can-i-get-refresh-token을 참조하십시오. – Phoenix