2014-05-21 3 views
8

Owin에서 MVC 5를 사용하는 외부 인증에 대한 가이드 - External login providers with owinkatana. 도전 점에서 지금owin 및 Nancy와의 Oauth 인증

app.Properties["Microsoft.Owin.Security.Constants.DefaultSignInAsAuthenticationType"] = "ExternalCookie"; 
app.UseCookieAuthentication(new CookieAuthenticationOptions 
{ 
    AuthenticationType = "ExternalCookie", 
    AuthenticationMode = Microsoft.Owin.Security.AuthenticationMode.Passive, 
}); 

app.UseTwitterAuthentication(new TwitterAuthenticationOptions 
{ 
    ConsumerKey = "mykey", 
    ConsumerSecret = "mypass" 
}); 

LoginModule.cs (낸시 모듈)

Post["ExternalLogin"] = _ => 
{ 
    var provider = Request.Form.name; 
    var auth = Context.GetAuthenticationManager(); 
    auth.Challenge(new AuthenticationProperties 
    { 
     RedirectUri = String.Format("/?provder={0}", provider) 
    }, provider); 
    return HttpStatusCode.Unauthorized; 
}; 

-

나는 내 Owin 낸시 응용 프로그램

Startup.cs에 다음을 추가 한 여기서 아무 일도 일어나지 않습니다. 그냥 리디렉션의 URL이있는 빈 페이지를 보여줍니다. MVC의 예제를 따라 작동하도록 할 수 있음을 확인했습니다. 누구나이 섹션에 올바른 Nancy 코드를 알고 있습니까?

+0

이 문제에 대해서는 어떤 식 으로든지나 갔습니까? Nancy에서 "/ login"경로를 만들고 UseOpenIdConnectAuthentication (...) 미들웨어를 통해 구성된 로그인 프로세스를 트리거 할 동일한 보트를 실행 중입니다. –

+0

불행히도 아닙니다. 나는 정상 Asp.net owin으로 전환한다. –

답변

4

나는 내가 떠날 뻔했던 내용을 펼치겠다. 대답을 낸다. I asked a similar question, 그리고 GitHub의에 다음 코드 예제 지적했다 :

https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server/tree/dev/samples/Nancy/Nancy.Client

당신이 당신의 OIDC가 Startup.cs에 제대로 유선 가정, 다음 코드는 내가를 실행하는 데 낸시 모듈을 얻기 위해 필요한 것입니다 내 로그인 절차/signout 노선에 대한 인증 :

namespace Nancy.Client.Modules { 
    public class AuthenticationModule : NancyModule { 
     public AuthenticationModule() { 
      Get["/signin"] = parameters => { 
       var manager = Context.GetAuthenticationManager(); 
       if (manager == null) { 
        throw new NotSupportedException("An OWIN authentication manager cannot be extracted from NancyContext"); 
       } 

       var properties = new AuthenticationProperties { 
        RedirectUri = "/" 
       }; 

       // Instruct the OIDC client middleware to redirect the user agent to the identity provider. 
       // Note: the authenticationType parameter must match the value configured in Startup.cs 
       manager.Challenge(properties, OpenIdConnectAuthenticationDefaults.AuthenticationType); 

       return HttpStatusCode.Unauthorized; 
      }; 

      Get["/signout"] = Post["/signout"] = parameters => { 
       var manager = Context.GetAuthenticationManager(); 
       if (manager == null) { 
        throw new NotSupportedException("An OWIN authentication manager cannot be extracted from NancyContext"); 
       } 

       // Instruct the cookies middleware to delete the local cookie created when the user agent 
       // is redirected from the identity provider after a successful authorization flow. 
       manager.SignOut("ClientCookie"); 

       // Instruct the OpenID Connect middleware to redirect 
       // the user agent to the identity provider to sign out. 
       manager.SignOut(OpenIdConnectAuthenticationDefaults.AuthenticationType); 

       return HttpStatusCode.OK; 
      }; 
     } 
    } 
} 

코드 소스 : 도움이 https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server/blob/dev/samples/Nancy/Nancy.Client/Modules/AuthenticationModule.cs

희망!