3

ASP.Net MVC 로그인 클라이언트를 토큰 운반자를 사용하고 모든 인증 비즈니스 논리를 포함하는 인증 서버에서 분리하려고합니다. 그 2 가지는 2 개의 다른 webroles에 앉아ASP.NET MVC 로그인 클라이언트/ASP.NET WebAPI 인증/권한 부여 서버 분리

나는 Identity 2.0의 현재 구현을 사용하여 거의 완성되었다.

UserManager와 UserStore는 AuthServer에 있고 로그인 클라이언트는 userId에 대해 아무것도 모릅니다. UserName 만. 지금은

, 클라이언트 프로젝트에서 사용자의 요구를 생성하기 위해,이 구현 사용 : 당신이 볼 수 있듯이

public async Task<ClaimsIdentity> GenerateUserIdentityAsync() 
    { 
     // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 
     var claims = new List<Claim>() 
     { 
      new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", this.UserName), 
      new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", this.UserName), 
      new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "ASP.NET Identity"), 
     }; 
     var claimsIdentity = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); 

     //var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); 

     // Add custom user claims here 

     return claimsIdentity; 
    } 

, 내가 여기에 관리자의 지웠어을하지만 난 내가 '두려워 사용자의 SecurityStamp를 사용하는 Startup.Auth.cs의 CookieAuthenticationProvider와 같은 보안 기능이 누락되었습니다.

Provider = new CookieAuthenticationProvider 
      { 
       OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
        validateInterval: TimeSpan.FromMinutes(30), 
        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync()) 
      } 

나는 manager.CreateIdentityAsync (이, DefaultAuthenticationTypes.ApplicationCookie) 함수를 호출하는 AuthServer의하여 GenerateUserIdentityAsync 전화를 시도하지만 클라이언트가 모르는 그 ... 일에 대한 사용자 ID가 필요합니다.

아이디어가 있으십니까? CreateIdentityAsync의 코드는 오픈 소스가 아닌 것 같습니다.

긴 게시물을 보내 주셔서 감사 드리며 죄송합니다.

+0

아, 여기에 언급 된 내용을 기반으로합니다. http://stackoverflow.com/questions/23814356/manually-validating-a-password-reset-token-in-asp-net-identity –

답변

0

인증 헤더 Api가 인증 헤더의 토큰 전달자에 의해 인증되고 있습니다. AuthServerProxy가 쿠키에서 가져온 무기명 토큰을 전달했습니다.

public async Task<ClaimsIdentity> GenerateUserIdentityAsync() 
{ 
// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType 

     var userIdentity = await AuthServerProxy.CreateIdentityAsync(DefaultAuthenticationTypes.ApplicationCookie); 

     // Add custom user claims here 

     return userIdentity; 
    }  

본인은 인증 헤더 (베어러 토큰)와 인증 서버

[Route("CreateIdentity")] 
public async Task<IHttpActionResult> CreateIdentity([FromBody] string authenticationType) 
    { 
     ApplicationUser user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); 
     ClaimsIdentity userIdentity = await user.GenerateUserIdentityAsync(UserManager, authenticationType); 
     return Ok(userIdentity); 
    } 

따라서, 로그인 클라이언트 웹 역할에서 더 이상 UserManager가없는 전화. 이것은 더 많이 정리 될 수 있지만 최소한 SoC는 존중되고 EF는 클라이언트에서 사라집니다.