2016-12-28 3 views
2

이전 응용 프로그램을 ASP.NET 코어/MVC으로 마이그레이션하려고합니다. 이 응용 프로그램은 OWIN 미들웨어를 사용하여 인증을 관리합니다.ASP.NET Core, MVC 및 OWIN

미들웨어는 "UseOwinAppBuilder"를 사용하여 등록 할 때 완벽하게 작동하지만 응용 프로그램의 일부 영역에서는 인증을 위해 "Owin 컨텍스트"를 가져와야합니다. 내가 ASP.NET 코어에 내가 HttpContext.Authentication.AuthenticateAsync를 사용하여 인증을 관리 할 수 ​​있다는 사실을 알고

var context = Request.GetOwinContext(); 
var authentication = context.Authentication.AuthenticateAsync("AuthScheme"); 

,하지만 난

var authentication = HttpContext.Authenticaiton.AuthenticateAsync("AuthScheme"); 

에 의해 이전 라인을 교체하면 나는 나타날 무언가 같이 "오래된"코드는 않습니다 오류 :

"어떤 인증 핸들러는 계획에 대해 인증하도록 구성되지 않은 : AuthScheme"

을 나는 의심 오류가 인증 때문에 발생 entwent middlewares는 ASP.NET Core가 아니라 OWIN을 사용하여 등록되었습니다.

"OwinEnvironment"를 만들고 "OwinFeatureCollection"에 액세스 할 수있는 개체가 있지만 "이전"Owin 컨텍스트에 액세스 할 수 있는지 여부는 확실하지 않습니다. 이 객체가 어떻게 작동하는지에 대한 자세한 문서를 찾아보십시오.)

개요 : 등록 된 미들웨어로 인증을 관리하려면 ASP.NET Core의 "오래된"Owin 컨텍스트에 액세스 할 수있는 방법이 있습니까?

답변

0

사용중인 인증 middelware에 따라 Startup.cs 파일을 검사하여 인증 체계 설정이 올바른지 확인하는 것이 좋습니다. 예를 들어

, 당신은 ASP.NET 코어에서 쿠키 인증 미들웨어를 사용하는 경우 ... 당신은 JWT 토큰 인증을 사용하는 경우,이 같은 것을 볼 것

var testOptions = new CookieAuthenticationOptions() 
{ 
    AutomaticAuthenticate = true, 
    AutomaticChallenge = false, 
    SessionStore = new CacheTicketStore(cache), 
    AuthenticationScheme = "AuthScheme" 
}; 
app.UseCookieAuthentication(testOptions); 

...

app.UseJwtBearerAuthentication(new JwtBearerOptions 
{ 
    // authority and app id settings omitted 
    AuthenticationScheme = "AuthScheme" 
}); 

인증 미들웨어는 일반적으로 잘 알려진 상수와 함께 제공되므로 해당 공급자의 기본값을 사용할 수 있습니다.

using Microsoft.AspNetCore.Authentication.Cookies; 
... 
context.Authentication.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme); 

하여 인증 미들웨어 단지 app.UseMagicAuthentication()로 설정되어있는 경우는 인수로 옵션을 걸린다면, 당신은 확인할 수 있습니다.

관련 문제