2015-01-25 1 views
2

프로젝트 시작일 때 실제 등록이 필요하지 않은 곳에서 OpenID를 사용할 수있게되었습니다 .. 이제이 프로젝트가 종료되었으며 프로젝트를 포팅했습니다. 새로운 메쉬로 ..하지만 사용자는 새로운 보안 토큰을 얻을 것이므로 그 사용자를 새로운 사용자로 봅니다.WebApi 2 Google 인증 OpenID -> oAuth2 - 변경 보안 핸들

모든 사용자에게 새 계정을 만들지 말고 기존 계정을 새 계정에 연결하도록 요청할 필요가 없습니까?

+0

이 질문은 실제로 개선되어야하지만 https://developers.google.com/accounts/docs/OpenID에 도움이 될 수 있습니다. 기존에 열린 토큰을 Oauth2 토큰으로 마이그레이션 할 수 있어야합니다. – DaImTo

답변

2

Google 이메일이 기존 사용자와 링크 될 수 있다고 판단했습니다. ASP.NET/WEBAPI에서 Identity의 표준 구현을 사용하는 경우 다음을 변경하십시오. AccountControler.cs - ExternalLoginCallback

Google 사용자가없는 경우 전자 메일을 조회하고 기존과 같이 사용자 :

 // Sign in the user with this external login provider if the user already has a login 
     var user = await UserManager.FindAsync(loginInfo.Login); 

삽입 :

 //Google Migration. If not existing then check if the Google email exists and if it does the change the LoginProvider key and try to login again 
     if (user == null && loginInfo.Login.LoginProvider == "Google" && email != "") 
     { 
      xxxEntities db = new xxxEntities(); 
      var existingUser = db.user_profiles.Where(e => e.eMail == (string)email).Where(p => p.created_from == "Google"); 
      if (existingUser.Count() > 0) 
      { 
       var existingID = existingUser.Single().userFK; 
       var result = await UserManager.AddLoginAsync(existingID, loginInfo.Login); 
       if (result.Succeeded) 
       { 
        //Now retry the check if the user with this external login provider if the user already has a login 
        user = await UserManager.FindAsync(loginInfo.Login); 
       } 
      } 
     } 

여기까지 :

 //Now for the normal Check 
     if (user != null) 
     { 

조회는 내가 가지고있는 내부 객체입니다. UserManager에 전자 메일 조회를 추가하여 OOTB 구현에서 수행 할 수 있습니다. 또는 사용자 관리 객체에서 직접 찾아서 조회 할 수 있습니다.