2016-10-08 6 views
1

私はプレビュー2.0エンドポイントを使用するMVCアプリケーションを持っています。プロフィール画像がデフォルトのオブジェクトではないことに少しは残念です。私は、エンドポイントを使用してプロフィール画像を正しく取得する方法を見つけようとする際に問題を抱えています。Microsoft openid login flow pictureアクセス

すべてのアイデア?

+0

あなたはどんな流れを指していますか? OIDC、OAuth?通常、追加の情報を得るためにグラフが使用されます。 –

答えて

2

Azure AD用のOpenId connectは、あなたが言及したように現在ユーザーのプロフィール画像を取得することをサポートしていません。

ただし、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からのフィードバックを提出することができます。

関連する問題