2016-10-08 8 views
1

미리보기 2.0 끝점을 사용하는 MVC 앱이 있습니다. 프로필 이미지가 기본 개체가 아니라는 것에 조금 실망합니다. 그런 말로 끝점을 사용하여 프로필 사진을 올바르게 가져 오는 방법을 찾는 데 문제가 있습니다.Microsoft openid 로그인 흐름 그림 액세스

어떤 아이디어?

+0

어떤 흐름을 언급하고 있습니까? OIDC, OAuth? 일반적으로 그래프는 추가 정보를 얻는 데 사용됩니다. –

답변

2

Azure AD 용 OpenId 연결은 언급 한대로 현재 사용자의 프로필 사진을 얻는 것을 지원하지 않습니다.

그러나 Azure AD 계정에서만 작업하는 경우 Microsoft Graph를 사용하여 사용자 프로필 사진을 별도로 가져올 수 있습니다. 이 REST를 호출하려면, 우리는 응용 프로그램에 User.Read 범위를 부여하고 여기에 참조 용 코드 수 :

:

app.UseOpenIdConnectAuthentication(
      new OpenIdConnectAuthenticationOptions 
      { 
       // The `Authority` represents the v2.0 endpoint - https://login.microsoftonline.com/common/v2.0 
       // The `Scope` describes the initial permissions that your app will need. See https://azure.microsoft.com/documentation/articles/active-directory-v2-scopes/      
       ClientId = clientId, 
       Authority = String.Format(CultureInfo.InvariantCulture, aadInstance, "common", "/v2.0"), 
       RedirectUri = redirectUri,      
       Scope = "openid email profile offline_access Mail.Read User.Read", 
       PostLogoutRedirectUri = redirectUri, 
       TokenValidationParameters = new TokenValidationParameters 
       { 
        ValidateIssuer = false, 
        // In a real application you would use IssuerValidator for additional checks, like making sure the user's organization has signed up for your app. 
        //  IssuerValidator = (issuer, token, tvp) => 
        //  { 
        //  //if(MyCustomTenantValidation(issuer)) 
        //  return issuer; 
        //  //else 
        //  // throw new SecurityTokenInvalidIssuerException("Invalid issuer"); 
        // }, 
       }, 
       Notifications = new OpenIdConnectAuthenticationNotifications 
       { 
        // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away. 
        AuthorizationCodeReceived = async (context) => 
        { 
         var code = context.Code; 
         string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value; 
         ConfidentialClientApplication cca = new ConfidentialClientApplication(clientId, redirectUri, 
          new ClientCredential(appKey), 
          new MSALSessionCache(signedInUserID, context.OwinContext.Environment["System.Web.HttpContextBase"] as HttpContextBase)); 
         string[] scopes = { "Mail.Read User.Read" }; 
         try 
         { 
          AuthenticationResult result = await cca.AcquireTokenByAuthorizationCodeAsync(scopes, code); 
         } 
         catch (Exception eee) 
         { 

         } 
        }, 
        AuthenticationFailed = (notification) => 
        { 
         notification.HandleResponse(); 
         notification.Response.Redirect("/Error?message=" + notification.Exception.Message); 
         return Task.FromResult(0); 
        } 
       } 
      }); 

그런 다음 우리는 아래의 요구처럼 푸른의 AD 사용자의 프로필 사진을 얻을 수 있습니다

Get: https://graph.microsoft.com/v1.0/me/photo/$value 
authorization: bearer {token} 

테스트를 기반으로 Microsoft Graph는 현재 Microsoft Account의 프로필 그림을 가져 오는 것을 지원하지 않습니다. Microsoft 계정도 지원하려면 here에서 의견을 제출하십시오.