2016-09-26 16 views
1

OWINを使用してAzure Webサイトでgoogleを使用しているユーザーにログインする際に問題が発生します。すべてが正常なlocalhostと私たちのテストサーバーで動作しますが、AzureのWebサイトにデプロイするとログインに失敗します。Googleログインはlocalhostとテストサーバーで動作しますが、紺碧のWebサイト(アプリサービス)では動作しません。

私が認証を処理するためのWeb APIとOWINを使用しています、と私は、この「シンプル」の問題に絞られている:紺碧に配備するとき

await AuthenticationManager.GetExternalLoginInfoAsync(); 

はnullを返しています。

  • google api マネージャの返信URLを確認して再確認しました。
  • 私はダミーのセッションを設定し、ここで述べたようにセッション をクリアしようとしている: OWIN OpenID provider - GetExternalLoginInfo() returns null
  • 私がログにグーグルのクライアントIDとclientSecretを書き出すので、私は、彼らが

正しいことを知っている誰もが似てきました紺碧に展開するときの問題?

UPDATE:ここ

は、コードの流れは次のとおりです。 まず私たちがイベントを襲った "OnAuthenticated" Startup.Auth.csにおける当社のグーグル・プロバイダーにユーザーがログインしたとき:

public void ConfigureAuth(IAppBuilder app) 
{ 
    app.CreatePerOwinContext(ApplicationDbContext.Create); 
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); 
    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); 
    app.UseKentorOwinCookieSaver(); 
    var provider = new CookieAuthenticationProvider(); 
    var originalHandler = provider.OnApplyRedirect; 
    app.UseCookieAuthentication(new CookieAuthenticationOptions 
    { 
     AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, 
     LoginPath = new PathString("/Login"), 
     Provider = new CookieAuthenticationProvider 
     { 
      OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
       validateInterval: TimeSpan.FromMinutes(30), 
       regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)), 
      OnApplyRedirect = context => 
      { 
       if (!context.Request.Uri.LocalPath.StartsWith(VirtualPathUtility.ToAbsolute("~/api"))) 
       { 
        context.RedirectUri = new Uri(context.RedirectUri).PathAndQuery; 
        originalHandler.Invoke(context); 

       } 
      } 
     } 
    }); 
    app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); 
    app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); 
    app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); 

    var options = new GoogleOAuth2AuthenticationOptions 
    { 
     ClientId = System.Configuration.ConfigurationManager.AppSettings["googleServiceAccountWebApplicationClientId"], 
     ClientSecret = System.Configuration.ConfigurationManager.AppSettings["googleServiceAccountWebApplicationClientSecret"], 
     Provider = new GoogleOAuth2AuthenticationProvider 
     { 
      OnAuthenticated = context => 
      { 
       //.... 
       return Task.FromResult(0); 
      } 
     }, 
     AccessType = "offline", 
     SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie 
    }; 
    app.UseGoogleAuthentication(options); 
} 

このイベントが発生した後、メソッド "ExternalLoginCallback"に当たっています。まず、AuthenticationManager.GetExternalLoginInfoAsync()を呼び出すことです。ヌルを返します

[AllowAnonymous] 
public async Task<ActionResult> ExternalLoginCallback(string returnUrl) 
{ 
    var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); 
    //loginInfo is always null when published to Azure website 
    if (loginInfo == null) 
    { 
     return RedirectToAction("NoAccess", "Login"); 
    } 
    //.... 
} 
+0

私たちがテストする必要があるより多くのコードを投稿できますか?http://stackoverflow.com/help/mcve – DaImTo

答えて

0

私はようやく問題を発見しました。 "OnAuthenticated"イベントで未処理の例外でした。次の行が原因で問題を見つけるまでに時間がかかりました。

HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>(); 

時折、紺碧で失敗しました。この問題を見つけて解決するために多くのコードを変更しましたが、それはOnAuthenticatedの例外だと思います。

関連する問題