0

OpenId 뒤에있는 마법에 대해 알지 못해 용서해야합니다. 내 흐름에; 사용자는 외부 사이트에서 지시되고 OpenId로 인증됩니다. 사용자 이름과 비밀번호를 추가로 만들기 위해 앱에 내 앱이 반환됩니다. 그들은 내 계정을 내 앱에 등록하고 로그인합니다. 외부 사이트에 등록한 후 사이트에서 내 앱을 실행하면 OpenId 자격 증명을 사용하여 자동으로 로그인해야합니다. 그리고 그 후이 함수로 리디렉션OpenId 인증 후 사용자 로그인 방법

internal class ChallengeResult : HttpUnauthorizedResult 
    { 
     public ChallengeResult(string provider, string redirectUri) 
      : this(provider, redirectUri, null) { } 

     public ChallengeResult(string provider, string redirectUri, string userId) 
     { 
      LoginProvider = provider; 
      RedirectUri = redirectUri; 
      UserId = userId; 
     } 

     public string LoginProvider { get; set; } 
     public string RedirectUri { get; set; } 
     public string UserId { get; set; } 

     public override void ExecuteResult(ControllerContext context) 
     { 
      var properties = new AuthenticationProperties { RedirectUri = RedirectUri }; 
      if (UserId != null) 
      { 
       properties.Dictionary[XSRF_KEY] = UserId; 
      } 
      context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider); 
     } 

:

나는 다음과 같은 코드를 사용하고 응답을 반환하고 OpenIdRelyingParty에서 인증 후

 var openid = new OpenIdRelyingParty(); 
     var response = openid.GetResponse(); 
     if (response == null) 
     { 
      Identifier id; 
      if (Identifier.TryParse(_identifer, out id)) 
      { 
       try 
       { 
        return openid.CreateRequest(_identifer).RedirectingResponse.AsActionResultMvc5(); 
       } catch (ProtocolException e) 
       { 
        throw new Exception(e.Message); 
       } 
      } 
      return View("Login"); 
     } 
     switch (response.Status) 
     { 
      case AuthenticationStatus.Authenticated: 
       Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay; 
       FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, false); 
       // Now I need to log in the user 
       break; 
      case AuthenticationStatus.Canceled: 
       break; 
      case AuthenticationStatus.Failed: 
       break; 
     } 

을, 나는 로그인해야 사용자. 이 기능을 사용하려면 양식 인증을 사용해야합니까? MVC ID 2.0을 사용하고 있습니다.

답변

0

이것은 내 public ActionResult ExternalLoginCallback(string returnUrl) 메서드의 일부입니다.이 메서드는 외부 OpenId 서버 (이 경우에는 Intuit의 메서드이지만, 중요하지 않습니다)에서 호출 한 메서드입니다.

//Attempt to log the user in if they've already created an account with the external login. 
if (OAuthWebSecurity.Login(result.Provider, result.ProviderUserId, createPersistentCookie: false)) 
{   
    return RedirectToLocal(returnUrl); 
}