2017-02-23 3 views
0

사용자를 IWA (Windows 통합 인증)를 사용하는 페이지로 리디렉션하는 웹 응용 프로그램을 작성하려고합니다. 나는 사용자가 다음과 같은 대화C# 통합 Windows 인증 - 코드로 인증하고 로그인 프롬프트 표시 안 함

enter image description here

하지만 그 대신 나는 응용 프로그램이 사용자가 페이지로 리디렉션 인증 할로 확인 메시지를 표시하지 않으. 크게 감사

나는 정말이에 시작하는 방법에 대한 좋은 생각을 가지고 있지 않으며 어떤 도움이 될 것

**

  • UPDATE

**

내가 도달하려고하는 URL이 Active Directory에 연결되어 있지 않으므로 문자 그대로 Windows 인증 로컬 자격 증명을 사용하며 1 액세스중인 시스템의 사용자.

이 1 명의 사용자 자격 증명을 사용하여 자동으로 인증 된 내 페이지로 리디렉션되는 모든 사람을 얻으려고합니다. 자격 증명은 데이터베이스의 사용자 세션 존재에 따라 액세스됩니다.

IWA는 NTLM을 사용하도록 구성됩니다.

+0

이 ASP.Net Web Form 또는 ASP.Net MVC입니까? Active Directory를 사용하고 있습니까? – Win

+0

웹 API를 사용하려고 했습니까? 분명히 IWA가 인증에 사용하는 유일한 것입니까? –

답변

3

Active Directory로 인증한다고 가정합니다. 그렇다면 PrincipalContextOWIN 미들웨어을 사용할 수 있습니다.

GitHub에서 AspNetMvcActiveDirectoryOwin이라는 샘플 프로젝트를 만들었습니다. 그것을 포크로 달아서 실행할 수 있습니다. 원래 ASP.Net MVC 용으로 작성되었지만 ASP.Net 웹 API에도 동일한 비즈니스 로직을 사용할 수 있습니다.

따라야 할 단계가 거의 없습니다. 우선, Active Directory로 인증하려고합니다.

참고 : 다른 유형의 인증 방법을 사용하는 경우이 클래스의 논리를 수정해야합니다.

public class ActiveDirectoryService : IActiveDirectoryService 
{ 
    public bool ValidateCredentials(string domain, string userName, string password) 
    { 
     using (var context = new PrincipalContext(ContextType.Domain, domain)) 
     { 
      return context.ValidateCredentials(userName, password); 
     } 
    } 

    public User GetUser(string domain, string userName) 
    { 
     User result = null; 
     using (var context = new PrincipalContext(ContextType.Domain, domain)) 
     { 
      var user = UserPrincipal.FindByIdentity(context, userName); 
      if (user != null) 
      { 
       result = new User 
       { 
        UserName = userName, 
        FirstName = user.GivenName, 
        LastName = user.Surname 
       }; 
      } 
     } 
     return result; 
    } 
} 

둘째, 당신은 Owin 미들웨어에서 사용되는 주장을 만들려고합니다.

public class OwinAuthenticationService : IAuthenticationService 
{ 
    private readonly HttpContextBase _context; 
    private const string AuthenticationType = "ApplicationCookie"; 

    public OwinAuthenticationService(HttpContextBase context) 
    { 
     _context = context; 
    } 

    public void SignIn(User user) 
    { 
     IList<Claim> claims = new List<Claim> 
     { 
      new Claim(ClaimTypes.Name, user.UserName), 
      new Claim(ClaimTypes.GivenName, user.FirstName), 
      new Claim(ClaimTypes.Surname, user.LastName), 
     }; 

     ClaimsIdentity identity = new ClaimsIdentity(claims, AuthenticationType); 

     IOwinContext context = _context.Request.GetOwinContext(); 
     IAuthenticationManager authenticationManager = context.Authentication; 

     authenticationManager.SignIn(identity); 
    } 

    public void SignOut() 
    { 
     IOwinContext context = _context.Request.GetOwinContext(); 
     IAuthenticationManager authenticationManager = context.Authentication; 

     authenticationManager.SignOut(AuthenticationType); 
    } 
}