각도로 Azure Active Directory를 사용하여 멀티 테넌트 응용 프로그램을 구현했습니다. 4. 사용자가 내 응용 프로그램에 로그인하면 사용자 정보를 얻을 수 있습니다. Active Directory에서 점점 그 아래에 스 니펫처럼 그래프 API를 구현하지 못했습니다. 내가 401 (Unauthorized)
오류가있어이 그래프 API를 호출하는 동안멀티 테넌트 응용 프로그램의 Active Directory 사용자 이미지에서 401 (권한없는) 오류 받기
public Task<UserDto> getPhoto(TenantDto tenantDto)
{
var client = new HttpClient();
client.BaseAddress = new Uri(String.Format("https://graph.windows.net/{0}/users/{1}/thumbnailPhoto?api-version=1.6", tenantDto.tenantKey, tenantDto.email));
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("image/jpeg"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", tenantDto.token);
HttpResponseMessage response = client.GetAsync("").Result;
if (response.IsSuccessStatusCode)
{
return null;
//Status status = response.Content.ReadAsAsync<Status>().Result;
//if (status.Code == 200)
// InBoundResponse = JsonConvert.DeserializeObject<InBoundCallResponse>(status.Data.ToString());
//return InBoundResponse;
}
else
{
return null;
}
}
여기 tenantDto.token
은 로그인 한 사용자의 "토큰"에 불과하다. 나는 아무 쓸데없이 노력했다. Active Directory의 APP에서 내가 변경 한 그래프 API 설정들도 내가 그것을 하나의 세입자
[Route("AdUserImage"), HttpGet]
public async Task<HttpResponseMessage> userImage()
{
var authContext = new AuthenticationContext("https://login.windows.net/sampletest.onmicrosoft.com/oauth2/token");
var credential = new ClientCredential(clientID, clientSecret);
ActiveDirectoryClient directoryClient = new ActiveDirectoryClient(serviceRoot, async() =>
{
var result = await authContext.AcquireTokenAsync("https://graph.windows.net/", credential);
return result.AccessToken;
});
var user = await directoryClient.Users.Where(x => x.UserPrincipalName == "[email protected]").ExecuteSingleAsync();
DataServiceStreamResponse photo = await user.ThumbnailPhoto.DownloadAsync();
using (MemoryStream s = new MemoryStream())
{
photo.Stream.CopyTo(s);
var encodedImage = Convert.ToBase64String(s.ToArray());
}
//string token = await HttpAppAuthenticationAsync();
Status status = new Status("OK");
status = new Status("Found", null, "User exists.");
return Request.CreateResponse(HttpStatusCode.OK, status, _jsonMediaTypeFormatter);
}
첨부 아래 좋아하지만 난 멀티 테넌트 구현해야 앱.
아무 답변 감사합니다.
미리 감사드립니다 ........!
은 여러 가지'401' 오류 (있습니다 참조 [여기] (https://msdn.microsoft. 404/en-us/library/azure/ad/graph/howto/azure-ad-graph-api-error-codes-and-error-handling))'401'에 대한 자세한 오류 메시지는 무엇입니까? –
{ "odata.error": { "코드": "Authentication_MissingOrMalformed" "메시지": { "LANG" "엉" "값": "액세스 토큰이 없거나 잘못된." }, "날짜": "2017-10-11T07 : 02 : 15", "RequestID가": "4f112369-931d-4a24-8f61-e303b0acb9c1", "값"널 (null) } } 오류 메시지 동안 그래프 API를 호출하지만 사용자가 직접 내 응용 프로그램에 로그인 한 후 그래프 API를 호출하기 때문에 토큰이 유효합니다.감사합니다 –
액세스 토큰, 대리인 토큰 또는 응용 프로그램 토큰에 대해 획득 한 흐름은 무엇입니까? –