2014-04-29 4 views
8

나는의 OAuth 2.0 인증 서버 샘플 코드 다음 http://www.asp.net/aspnet/overview/owin-and-katana/owin-oauth-20-authorization-serverOWIN 쿠키 미들웨어를 수동 인증 모드로 설정하는 올바른 방법은 무엇입니까?

뿐만 아니라 너겟 패키지에서 찾고있다 Microsoft.aspnet.identity.samples 패키지 (설치 패키지 Microsoft.aspnet.identity.samples - 전)

그리고 수동적 인 쿠키와 활성 쿠키의 미들웨어가 작동하는 방식을 고민하고 있습니다.

인증 서버 예제에서 "Application"쿠키는 수동으로 설정됩니다. ID 샘플에서 "ApplicationCookie"가 활성화되어 있습니다.

이 속성에 대해 읽으면 패시브 미들웨어가 일치하는 AuthenticationType에 의해 요청 될 때만 트리거된다는 것을 설명합니다. 나는 Microsoft.aspnet.identity.samples에서 startup.auth.cs 파일을 편집하고 수동으로 응용 프로그램 쿠키를 설정하면

후 로그인이 검증 보이지만, 나를 기록하지 않습니다.

을 (사용자 DefaultAuthenticationTypes.ApplicationCookie) CreateIdentityAsync

을 : 코드에 더 깊이 파고

, 나는 아래로 SignInHelper.SignInAsync

이 메소드의 호출에 계정 컨트롤러 종기가 전화를 인 사용자로부터 claimsidentity를 얻을 것을 볼

나는 분명히 이해하지 못하고 있습니다. 왜냐하면 내가 읽었고 말할 수있는 것에서부터 전자 쿠키는 Claim과 동일한 AuthenticationType을 가지고 있지만 Authentication.SignIn을 호출하면 쿠키가 설정되지 않은 것처럼 보이며 등록 및 로그인 옵션이있는 기본 페이지로 돌아갑니다.

이 문제를 중복 새로운 프로젝트 빈 asp.net 응용 프로그램을 시작하려면 다음 신원 샘플 패키지를 설치 한 다음에 startup.auth.cs의 app.useCookieAuthentication을 변경

app.UseCookieAuthentication(new CookieAuthenticationOptions { 
      AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
      AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive, 
      LoginPath = new PathString("/Account/Login"), 
      Provider = new CookieAuthenticationProvider { 
       // Enables the application to validate the security stamp when the user logs in. 
       // This is a security feature which is used when you change a password or add an external login to your account. 
       OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
        validateInterval: TimeSpan.FromMinutes(30), 
        regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) 
      } 
     }); 

나는 변화 시도 startup.auth.cs에 쿠키 이름을 추가하고 아무런 소용이 없다고 주장하는 코드에 "사용자 정의"이름을 추가하십시오.

나는 연구를 계속할 예정이지만, 그동안 커뮤니티에 연락 할 것이라고 생각했습니다.

답변

3

정확한 질문은 확실하지 않습니다.

OWIN은 등록 된 모든 미들웨어 모듈을 실행하는 파이프 라인입니다. 여러 인증 유형의 미들웨어를 등록 할 수 있습니다.

쿠키가 ID를 해독합니다. 인증 유형을 외부 베어러로 변경하면 쿠키의 베어러 토큰이됩니다.

나는 왜 그것이 당신을 위해 일하지 않는지 모르겠지만, 이것이 내가 사용하는 것입니다.(I 템플릿의 외부 로그인에보고하지 않은) 수동 인증 미들웨어 발생

질문 하나 대 활성

// Enable the application to use a cookie to store information for the signed in user 
    app.UseCookieAuthentication(new CookieAuthenticationOptions 
      { 
       //just to show bearer 
       AuthenticationType = DefaultAuthenticationTypes.ExternalBearer, 
       LoginPath = new PathString("/Account/Login"), 
      } 

Good explanation of active vs. passive, from Mr. Brock Allen himself.

- 새로운 템플릿을 여러 OWIN 인증 미들웨어 구성이있는 경우 , 어느 것이 실제로 사용됩니까? OWIN 인증 미들웨어는 수동 대 액티브의 개념을 가지고 있습니다. 활성 미들웨어는 항상 들어오는 모든 요청을보고 호출을 인증하려고 시도하며 성공할 경우 현재 사용자를 나타내는 주체를 만들고 해당 주체를 호스팅 환경에 할당합니다. 반대로 패시브 미들웨어는 요청시에만 요청을 검사합니다. Visual Studio 2013의 기본 템플릿의 경우 "기본"쿠키 인증 미들웨어를 제외하고 구성된 모든 미들웨어는 기본적으로 모두 패시브입니다 (일부 템플릿에서 사용되는 두 개의 쿠키 미들웨어가 있습니다. 외부 ID 제공자를위한 또 다른 ID 제공자이며이 하나는 수동적으로 표시됨).

+0

안녕하세요. William, 고마워요. 필자는 Brock Allen의 블로그와 게시물을 몇 차례 읽었으며 본질적으로이 말을 알아 내려고 노력하고 있습니다. "수동적 미들웨어는 요청이있을 때만 요청을 검사합니다." AuthenticationType, IE를 지정하는 것입니다. 인증 유형을 생성 할 때 인증 유형을 생성해야합니다. 그러나 이렇게하면 모든 인증 코드가 성공하지만 쿠키가 설정되지 않습니다. 활성 미들웨어가 자동으로 수행해야하는 작업을 수동으로 수행해야하는지 파악하려고합니다. – Steve

+0

위 코드에 추가하려면 AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Active에 대한 AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive를 제외한 모든 항목이 동일한 방식으로 작동한다는 것을 알고 있습니다. 활성 상태에서 쿠키는 인증 후 설정되고 로그인됩니다. 수동태는 모두 작동하지만 쿠키는 설정되지 않습니다. 액티브 미들웨어처럼 개발자가 쿠키 생성을 트리거하기 위해해야 ​​할 일을 결정하려고합니다. – Steve

+0

클레임 ID로 SignIn을 호출하면 쿠키 생성이 트리거되며 활성/수동 모드는 쿠키 생성에 영향을 미치지 않아야합니다. 전혀 생각하지 않습니다. –

0

페이지는 코딩 할 때 잘 동작합니다.

app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 

AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 

//LoginPath = new PathString("/Login"), 

Provider = new CookieAuthenticationProvider(), 

CookieName = "DefaultAuthenticationTypes", 

CookieHttpOnly = true,    
ExpireTimeSpan = TimeSpan.FromHours(cookieActiveTime), 

}); 

.

+0

hmmm, 아마. 그래서? – Wndrr

관련 문제