2013-11-25 3 views
0

나는 무작위로 사용자를 수락하는 웹 사이트가 있다고 가정합니다. 규칙은 간단합니다. 임의 생성기는 사용자가 로그인 할 수 있는지 여부를 알 수 있습니다.새로운 OWIN Identity API로 로그인하십시오.

이 코드는 어떻게 사용해야합니까?

private async Task SignInAsync(ApplicationUser user, bool isPersistent) 
{ 
    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); 
    var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); 
    HttpContext.GetOwinContext().SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); 
} 

저는 ApplicationUser가 없으므로 DbContext를 주입하지 않았으며 사용자 (!) 테이블이 없습니다.

주요 질문; 간단한 인증은 어디에 있습니까?

FormsAuthentication.RedirectFromLoginPage ("I_am_a_User", Persist.Checked) 

답변

0

코드는 추한 모습하지만 난 ... 해결

AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); 

     List<Claim> _claims = new List<Claim>() 
           { 
            new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", 
             Guid.NewGuid().ToString(), 
             "http://www.w3.org/2001/XMLSchema#string", "LOCAL AUTHORITY"), 

            new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", 
             "I_am_a_User", 
             "http://www.w3.org/2001/XMLSchema#string", "LOCAL AUTHORITY"), 

            new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", 
             "ASP.NET Identity", 
             "http://www.w3.org/2001/XMLSchema#string", "LOCAL AUTHORITY"),           
           }; 
     ClaimsIdentity identity = new ClaimsIdentity(_claims, DefaultAuthenticationTypes.ApplicationCookie); 

AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); 
관련 문제