2014-02-14 4 views
7

UserManager 클래스를 사용자 지정하여 회사 구조에서 사용자를 찾아 인증 (Active Directory 인증과 다른 Oracle Authetication을 혼합)해야했습니다. FindAsyncCreateIdentityAsync을 구현했지만 사용자는 인증 된 것으로 설정되지 않습니다.OWIN - 사용자 정의 사용자

UserManager 구현 :

내 사용자가 인증 한 것으로 부족한 무엇
using System; 
using System.Collections.Generic; 
using System.Dynamic; 
using System.Security.Claims; 
using System.Web; 
using MyProject.Common; 
using MyProject.Models; 
using Microsoft.AspNet.Identity; 
using System.Threading.Tasks; 

namespace MyProject.Infrastructure 
{ 
    public class GNUserManager : UserManager<ApplicationUser> 
    { 
     public GNUserManager(IUserStore<ApplicationUser> store) : base(store) 
     { 

     }   

     public override async Task<ApplicationUser> FindAsync(string userName, string password) 
     { 
      /* Performs some logic here that returns true */ 

      if (foundUser) { 
       return await Task.Run(() => new ApplicationUser 
       { 
        UserName = userName, 
        Id = userName 
       }); 
      } 

      throw new Exception("User not found."); 
     } 

     public override async Task<ClaimsIdentity> CreateIdentityAsync(ApplicationUser user, string authenticationType) 
     { 
      IList<Claim> claimCollection = new List<Claim> 
      { 
       new Claim(ClaimTypes.Name, user.UserName), 
       new Claim(ClaimTypes.Country, "Brazil"), 
       new Claim(ClaimTypes.Email, user.UserName) 
      }; 

      var claimsIdentity = new ClaimsIdentity(claimCollection, "Company Portal"); 

      return await Task.Run(() => claimsIdentity); 
     } 
    } 
} 

?

답변

1

UserManager는 데이터베이스의 사용자 ID와 자격 증명의 유효성을 관리합니다. 요컨대 DB 조회 도구입니다. 사용자가 앱에 "로그인"하도록하려면 브라우저 응용 프로그램의 쿠키 또는 API 응용 프로그램의 토큰과 같은 토큰을 사용해야합니다. 가장 최근의 ASP.NET 접근 방식은 브라우저 응용 프로그램 용 쿠키 인증 미들웨어입니다. 쿠키 미들웨어에 대한 추가 정보를 원하시면 여기를 참조하십시오 :

http://brockallen.com/2013/10/24/a-primer-on-owin-cookie-authentication-middleware-for-the-asp-net-developer/

+0

어제이 사이트를 보았지만 찾고있는 것만 보았습니다. 그것은 바로 저에게 관심있는 쿠키 세대입니다. –

1

을하는 ASP.NET MVC 5 기본 프로젝트에 의해 생성 된 로그인의 방법을 보면 우리가이 코드를 볼 수 있습니다

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

을 우리는 무엇을 할 수 고발은 AuthenticationManager이며, 우리는 정체성을 얻은 후 AuthenticationManager으로 SignIn해야합니다. 그럼 아마도 문제는 UserManager이 아닙니다.

컨트롤러 클래스의 AuthenticationManager 인스턴스는이 코드를 검색 :

private IAuthenticationManager AuthenticationManager 
{ 
    get 
    { 
     return HttpContext.GetOwinContext().Authentication; 
    } 
} 
+0

이 줄은 :'AuthenticationManager.SignIn (새로운 AuthenticationProperties() {IsPersistent = isPersistent}, identity);'정상적으로 실행되지만 쿠키는 생성되지 않습니다. 이 코드를 디버깅하면서'public override async Task CreateIdentAsAsync (ApplicationUser user, string authenticationType)'로 들어가 보았습니다. 내가 알아 내야 할 것은 쿠키를 생성하는 방법입니다. –

+0

아마도 재정의하는 기본 메소드를 호출 할 수 있습니까? – iuristona

+0

이전에 시도했지만 결과가 없습니다. –

2

이 라인을 변경해보십시오. 즉 필요한 당신을 위해 쿠키를 생성해야이

var claimsIdentity = new ClaimsIdentity(claimCollection, DefaultAuthenticationTypes.ApplicationCookie); 

으로

var claimsIdentity = new ClaimsIdentity(claimCollection, "Company Portal"); 

.

1

Oracle Data Provider for .NET은 현재 비동기 쿼리 및 저장을 지원하지 않습니다.

관련 문제