2016-06-14 1 views
0

내 웹 사이트를 로컬 로그인 페이지로 업그레이드 (또는 다운 그레이드)해야합니다. 나는 그것이 모든 토큰이 다시 올 것이다 때IdentityServer3을 사용하여 Hybrid 흐름을 ResourceOwner 흐름으로 전환하는 방법

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions(){}); 

그리고 다음 코드를 사용하여 하이브리드 흐름을 사용하여 작업을했다는 주장 ID를 설정 asp.net-에서 인증 논리를 완료하기 위해 나에게 액세스 권한을 부여 할 것, 교장 등

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions() 
      { 

       Notifications = new OpenIdConnectAuthenticationNotifications() 
       { 
        SecurityTokenValidated = async n => 
        { 
         // perform transform, etc.. 

         n.AuthenticationTicket = new AuthenticationTicket(
          identity, n.AuthenticationTicket.Properties); 

         await Task.FromResult(0); 
        } 
       } 
      }); 

이제 MVC 작업 메서드에서 사용자 이름과 암호를 수집 할 것입니다. 이 방법으로 클라이언트에서 액세스 토큰을 가져올 수 있습니다.

 [HttpPost] 
    public ActionResult Login(LoginModel model) 
    { 
     var client = new TokenClient(
      StsSettings.TokenEndpoint, 
      ClientId, 
      Secret); 

     var x = client.RequestResourceOwnerPasswordAsync(model.UserName, model.Password, "customid openid").Result; 

     return View(model); 
    } 

는하지만 가장 쉬운 방법은 내 사용자 정의 로그인 페이지 대신의 신원 서버를 가리 키도록 ASP.NET을 이야기하는 방법을 모르겠어요. 양식 인증 논리를 사용하고 일부 AuthenticationTicket을 만들까요? 또한 가장 좋은 방법은 무엇입니까 ClaimsIdentity (클레임을 다시 얻는 방법을 알고 있습니다. "후크"가 필요합니다.)

답변

0

자원 소유자 암호 흐름의 결과를 로그인 한 사용자가 원하면 새로 인증 된 사용자에 대한 클레임이 포함 된 기본 인증 쿠키를 발행해야합니다.

var claims = new Claim[] { new Claim("name", username), new Claim("sub", "4848784904"), new Claim("email", "[email protected]"), new Claim("role", "Admin"), new Claim("role", "Dev"), }; // "Cookies" is the name of your cookie middleware, // so change to match what you're actually using in Startup.cs var ci = new ClaimsIdentity(claims, "Cookies", "name", "role"); Request.GetOwinContext().Authentication.SignIn(ci); return Redirect("~/Home/Secure");

+0

매력처럼 일했습니다! 고맙습니다. 개인 메모에서 IdentityModel 및 IdentityServer 및 MembershipReboot에 대한 모든 노력에 감사드립니다. –

관련 문제