2016-10-07 9 views
0

私はユーザーストアとしてASP.NET IDを持つIdentityServer 3を使用しています。私はこれに続いてarticleを設定し、私のクライアントはASP MVC Webアプリケーションです。クライアントからログインできますが、クライアント側でユーザー情報を取得する方法がわかりません。IdentityServer 3とASP.NET ID:ユーザー情報を取得する方法

var scopes = new Scope[] 
      { 
       StandardScopes.OpenId, 
       StandardScopes.Email, 
       new Scope 
       { 
        Name = "roles", 
        Claims = new List<ScopeClaim> 
        { 
         new ScopeClaim("role") 
        } 
       } 

      }; 

      var clients = new Client[] 
      { 
       new Client 
       { 
        ClientId = "mvc-demo", 
        ClientName = "MVC Demo Client", 
        Flow = Flows.Implicit, 
        RedirectUris = new List<string> 
        { 
         "http://localhost:16652/" 
        }, 
        AllowedScopes = new List<string> 
        { 
         "openid", "email", "roles" 
        } 
       } 
      }; 

      var factory = new IdentityServerServiceFactory().Configure(connectionString); 
      factory.UseInMemoryClients(clients); 
      factory.UseInMemoryScopes(scopes); 

とクライアント側のを:使用して、サーバー側イムで

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
      { 
       AuthenticationType = "oidc", 
       SignInAsAuthenticationType = "cookies", 
       Authority = "https://localhost:44305/", 
       ClientId = "mvc-demo", 
       RedirectUri = "http://localhost:16652/", 
       ResponseType = "id_token token", 
       Scope = "openid email roles", 

       Notifications = new OpenIdConnectAuthenticationNotifications 
       { 
        SecurityTokenValidated = n => 
        { 
         var id = n.AuthenticationTicket.Identity; 

         var email = id.FindFirst(Constants.ClaimTypes.Email); 
         var roles = id.FindAll(Constants.ClaimTypes.Role); 

         // create new identity and set name and role claim type 
         var nid = new ClaimsIdentity(
          id.AuthenticationType, 
          Constants.ClaimTypes.Email, 
          Constants.ClaimTypes.Role); 

         nid.AddClaim(email); 
         nid.AddClaims(roles); 

         // add some other app specific claim 
         //nid.AddClaim(new Claim("app_specific", "some data")); 

         n.AuthenticationTicket = new AuthenticationTicket(
          nid, 
          n.AuthenticationTicket.Properties); 

         return Task.FromResult(0); 
        } 
       } 

しかし、私は、たとえば、ユーザーの電子メールに関する情報を取得傾けます。

答えて

0

私は私のクライアントアプリケーションにこの方法クレームを送信するために管理:

var scopes = new Scope[] 
      { 
       StandardScopes.OpenId, 
       new Scope 
       { 
        Name = "roles", 
        Type = ScopeType.Identity, 
        Claims = new List<ScopeClaim> 
        { 
         new ScopeClaim("role") 
        } 
       }, 
       new Scope 
       { 
        Name = "email", 
        Type = ScopeType.Identity, 
        Claims = new List<ScopeClaim> 
        { 
         new ScopeClaim(Constants.ClaimTypes.Email) 
        } 
       } 

      }; 

      var clients = new Client[] 
      { 
       new Client 
       { 
        ClientId = "mvc-demo", 
        ClientName = "MVC Demo Client", 
        Flow = Flows.Implicit, 
        RedirectUris = new List<string> 
        { 
         "http://localhost:16652/" 
        }, 
        AllowedScopes = new List<string> 
        { 
         "openid", "email", "roles" 
        } 
       } 
      }; 

とクライアント側では、私はこのように、それらを正しく取得するために、クレーム変換をオフにするために必要な(OWIN起動クラスで) :

AntiForgeryConfig.UniqueClaimTypeIdentifier = Constants.ClaimTypes.Subject; 
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>(); 
関連する問題