2016-07-27 6 views
8

VS2015, C#을 사용합니다.게시 후 Google 로그인이 작동하지 않습니다.

Google 로그인에 문제가 있습니다. 내 디버그 구성 (localhost)에서 잘 작동합니다. 서버에 게시 한 후 Google 로그인 창이 열리지 않습니다. 그리고 예외는 발생하지 않습니다.

[AllowAnonymous] 
public async Task LoginWithGoogle() 
{ 
    HttpRequest request = System.Web.HttpContext.Current.Request; 
    string redirectUri = ConfigurationReaderHelper.GetGoogleRedirectUri(); 

    try 
    {    
     ClientSecrets secrets = new ClientSecrets 
     { 
      ClientId = "***", 
      ClientSecret = "***" 
     }; 

     IEnumerable<string> scopes = new[] { PlusService.Scope.UserinfoEmail, PlusService.Scope.UserinfoProfile }; 

     GoogleStorageCredentials storage = new GoogleStorageCredentials(); 

     dsAuthorizationBroker.RedirectUri = redirectUri; 
     UserCredential credential = await dsAuthorizationBroker.AuthorizeAsync(secrets, 
      scopes, "", CancellationToken.None, storage); 
    } 
    catch(Exception ex) 
    { 
     throw ex; 
    }    
} 


//just getting value from applicationSettings - web.config 
      public static string GetGoogleRedirectUri() 
      { 
    #if DEBUG 
       return GetValueFromApplicationSettings("RedirectUriDEBUG"); 
    #elif PRODUKCIJA 
       return GetValueFromApplicationSettings("RedirectUriSERVER");    
    #endif 
      } 

내가 원래 URI에 또한 개발자를위한 구글 콘솔에서 승인 된 리디렉션 URI에 서버의 주소를 추가 물론 : 다음은 내 코드입니다. (마치 내가 localhost를 위해했던 것처럼). 나는 왜 그것이 잘못되었는지, 왜 로그인 창이 열리지 않는지 이해하지 못합니까?

편집 :

추가 클래스 dsAuthorizationBroker (내 첫 번째 게시물에서 누락 된 - 그 하나에 미안) : 당신이 경우

namespace Notes 
{ 
    public class dsAuthorizationBroker : GoogleWebAuthorizationBroker 
    { 
     public static string RedirectUri; 

     public static async Task<UserCredential> AuthorizeAsync(
      ClientSecrets clientSecrets, 
      IEnumerable<string> scopes, 
      string user, 
      CancellationToken taskCancellationToken, 
      IDataStore dataStore = null) 
     { 
      var initializer = new GoogleAuthorizationCodeFlow.Initializer 
      { 
       ClientSecrets = clientSecrets, 
      }; 
      return await AuthorizeAsyncCore(initializer, scopes, user, 
       taskCancellationToken, dataStore).ConfigureAwait(false); 
     } 

     private static async Task<UserCredential> AuthorizeAsyncCore(
      GoogleAuthorizationCodeFlow.Initializer initializer, 
      IEnumerable<string> scopes, 
      string user, 
      CancellationToken taskCancellationToken, 
      IDataStore dataStore) 
     { 
      initializer.Scopes = scopes; 
      initializer.DataStore = dataStore ?? new FileDataStore(Folder); 
      var flow = new dsAuthorizationCodeFlow(initializer); 
      return await new AuthorizationCodeInstalledApp(flow, 
       new LocalServerCodeReceiver()) 
       .AuthorizeAsync(user, taskCancellationToken).ConfigureAwait(false); 
     } 
    } 


    public class dsAuthorizationCodeFlow : GoogleAuthorizationCodeFlow 
    {   
     public dsAuthorizationCodeFlow(Initializer initializer) 
      : base(initializer) { } 

     public override AuthorizationCodeRequestUrl 
         CreateAuthorizationCodeRequest(string redirectUri) 
     {    
      return base.CreateAuthorizationCodeRequest(dsAuthorizationBroker.RedirectUri);    
     } 
    } 
} 
+1

일부 마지막 디버깅 코드를 실행하여 마지막 행이 무엇인지 확인합니다. 근본 원인을 제로로 만드는 데 도움이 될 것입니다. AppSettings –

+0

에서 적절한 값을 얻지 못했다고 생각합니다. 이벤트 뷰어의 오류를 보려고 시도하는 것보다 가상 컴퓨터에 게시 한 경우 – Lakhtey

+0

@JohnPeters - 로깅을 추가했습니다. 나는 successfuly 전에 UserCredential 자격 증명 = .... 하나의 라인을 로그 (로그에서) 리디렉션 uri 내가 URI를 Google 콘솔에서 URI를 가지고 uri입니다. – FrenkyB

답변

3
public static async Task<UserCredential> AuthorizeAsync 

이 방법은 이미 때문에 GoogleWebAuthorizationBroker에 선언하고 이 함수를 기본 구현보다 우선 적용하려면 new 키워드를 사용해야합니다. 난 당신이 로그인 가정 할 이유가

public new static async Task<UserCredential> AuthorizeAsync 

는 기본 구현을 호출,이 시점에서

UserCredential credential = await dsAuthorizationBroker.AuthorizeAsync 

전에 라인을 중지합니다. 이것을 제외하고

, 나는 일반적으로 구글 상호 작용 DotNetOpenAuth를 사용하는 경향이 herehere처럼 따라하는 간단한 예제 많이 있습니다 ...하지만 당신이 정말로 단지 다음 구글 API를 사용하여 자신의 롤하려면이입니다 가장 좋음 place to start

+0

주셔서 감사합니다. 나는 당신의 대답과 DotNetOpenAuth를 모두 시험해 볼 것입니다. 내가 물어볼지도 모르겠다 - 아마도 당신은 Twitter/Facebook에서 DotNetOpenAuth를 사용한 실제 예제를 알고있을 것입니까? – FrenkyB

+0

며칠 동안 코드를 추가 할 수 있지만 사용 사례가 무엇인지 물어볼 수 있습니까? 전자 메일 등을 승인하거나 필요로 할 뿐인가? 그렇다면 트위터로 뛰어 넘기위한 몇 가지 농구가 있습니다. DotNetOpenAuth를 시작하기 위해 [샘플 코드/예제] (https://github.com/DotNetOpenAuth/DotNetOpenAuth.Samples)가 있는데 여기에는 트위터 예제가 있습니다. – timkly

+0

내가 필요한 것은 로그인 - 사용자 이메일을받는 것입니다. 소셜 로그인에 대한 테스트 사례가 더 있으면 대단히 환영합니다. – FrenkyB

관련 문제