2017-06-12 14 views
1

My MVC WebAppがAzure Paasにデプロイされ、Azure ADを使用して保護されます。認証設定では、以下のサンプルコードをベースとして使用し、IISExpressまたはIISのいずれかを使用してlocalhostで作業しています。OpenIdConnectAuthenticationNotifications.AutureCureReceivedイベントがAzure WebAppで呼び出されないAzure Active Directoryによって保護される

https://github.com/Azure-Samples/active-directory-dotnet-webapp-webapi-openidconnect

しかし、それはアズールに展開した後に動作していません。ユーザーは正しく認証されますが、AuthorizationCodeReceivedデリゲートは呼び出されません。ここで

void ConfigureAuth(IAppBuilder app, Container container) { 
     _log.Debug("Configuring Azure Authentication"); 

     AzureActiveDirectoryAppSetting setting = container.GetInstance<IAzureActiveDirectoryAppSettingFactory>().Get(); 
     app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); 
     app.UseCookieAuthentication(new CookieAuthenticationOptions()); 
     app.UseOpenIdConnectAuthentication(
      new OpenIdConnectAuthenticationOptions() { 
       ClientId = setting.ClientID, 
       Authority = setting.Authority, 
       PostLogoutRedirectUri = setting.PostLogoutRedirectUrl, 
       RedirectUri = setting.ReplyUrl, 
       Notifications = new OpenIdConnectAuthenticationNotifications() { 
        AuthorizationCodeReceived = new Func<Microsoft.Owin.Security.Notifications.AuthorizationCodeReceivedNotification, System.Threading.Tasks.Task>(args => OnAuthorizationCodeReceived(args, container)), 
        AuthenticationFailed = new Func<Microsoft.Owin.Security.Notifications.AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions>, System.Threading.Tasks.Task>(OnAuthorizationFailed), 
       } 
      } 
     ); 
    } 

    System.Threading.Tasks.Task OnAuthorizationFailed(Microsoft.Owin.Security.Notifications.AuthenticationFailedNotification<OpenIdConnectMessage, OpenIdConnectAuthenticationOptions> args) { 
     _log.Error("Authorization Failed"); 
     return System.Threading.Tasks.Task.FromResult<string>(null); 
    } 
    System.Threading.Tasks.Task OnAuthorizationCodeReceived(Microsoft.Owin.Security.Notifications.AuthorizationCodeReceivedNotification args, Container container) { 
     _log.Debug("Authorization Code Received"); 
     var auth = container.GetInstance<IClaimsBasedAuthentication>(); 
     return auth.ReceiveSecurityClaim(args.Code, args.AuthenticationTicket.Identity, HttpContext.Current); 
    } 

アズールからのトレースです:

これは、認証がセットアップコードを起動しています。ご覧のとおり、認証は成功しましたが、「認証に失敗しました」または「認証コードが受信されました」というトレースは検出されません。最初のエラーは、AcquireTokenSilentAsync呼び出しのエラーです。トークンが最初にキャッシュされなかったために失敗しました。

何か助けていただければ幸いです。ありがとう!マークされた答えの明確化のため

- 2017-06-10T22:18:59 PID[7692] Verbose  Albatross.Security.AzureADOpenIDAuthentication:AzureADOpenIDAuthentication Created 
- 2017-06-10T22:18:59 PID[7692] Information Albatross.Web.App_Start.Startup:Web App Configuration 
- 2017-06-10T22:18:59 PID[7692] Information Albatross.Web.App_Start.Startup:All areas registered 
- 2017-06-10T22:18:59 PID[7692] Information Albatross.Web.App_Start.Startup:Routes registered 
- 2017-06-10T22:18:59 PID[7692] Information Albatross.Web.App_Start.Startup:Bundles registered 
- 2017-06-10T22:18:59 PID[7692] Verbose  Albatross.Web.App_Start.Startup:Configuring Azure Authentication 
- 2017-06-10T22:18:59 PID[7692] Verbose  Albatross.Web.App_Start.Startup:ClientID:xxx 
- 2017-06-10T22:18:59 PID[7692] Verbose  Albatross.Web.App_Start.Startup:Authority:https://login.microsoftonline.com/rushuioutlook.onmicrosoft.com 
- 2017-06-10T22:18:59 PID[7692] Verbose  Albatross.Web.App_Start.Startup:PostLogoutRedirectUrl:https://albatrossweb.azurewebsites.net/.auth/login/aad/callback/ 
- 2017-06-10T22:18:59 PID[7692] Verbose  Albatross.Web.App_Start.Startup:ReplyUrl:https://albatrossweb.azurewebsites.net/.auth/login/aad/callback/ 
- 2017-06-10T22:18:59 PID[7692] Verbose  Albatross.Web.App_Start.Startup:Tenant:rushuioutlook.onmicrosoft.com 
- 2017-06-10T22:19:00 PID[7692] Verbose  Received request: GET http://albatrossweb.azurewebsites.net/ 
- 2017-06-10T22:19:00 PID[7692] Information Redirecting: https://albatrossweb.azurewebsites.net/ 
- 2017-06-10T22:19:00 PID[7692] Verbose  Received request: GET https://albatrossweb.azurewebsites.net/ 
- 2017-06-10T22:19:00 PID[7692] Information Redirecting: https://login.windows.net/25dd3578-72e5-4b70-a97b-3cc94f9d69cc/oauth2/authorize?response_type=code+id_token&redirect_uri=https%3A%2F%2Falbatrossweb.azurewebsites.net%2F.auth%2Flogin%2Faad%2Fcallback&client_id=40ca9b08-b857-4307-9ba3-5815031e9ddf&scope=openid+profile+email&response_mode=form_post&nonce=4a0abda18cf6448fb5b8095efb546871_- 20170610222400&state=redir%3D%252F 
- 2017-06-10T22:19:29 PID[7692] Verbose  Received request: POST https://albatrossweb.azurewebsites.net/.auth/login/aad/callback 
- 2017-06-10T22:19:29 PID[7692] Verbose  JWT validation succeeded. Subject: 'iit96kJ_mJn8Qt0f3kKAZm3qFKMGR2BMjVEnI45JBRc', Issuer: 'https://sts.windows.net/25dd3578-72e5-4b70-a97b-3cc94f9d69cc/'. 
- 2017-06-10T22:19:29 PID[7692] Verbose  Calling into external HTTP endpoint POST https://login.windows.net/25dd3578-72e5-4b70-a97b-3cc94f9d69cc/oauth2/token. 
- 2017-06-10T22:19:29 PID[7692] Information Login completed for '[email protected]'. Provider: 'aad'. 
- 2017-06-10T22:19:29 PID[7692] Verbose  Writing 'AppServiceAuthSession' cookie for site 'albatrossweb.azurewebsites.net'. Length: 940. 
- 2017-06-10T22:19:29 PID[7692] Information Redirecting: https://albatrossweb.azurewebsites.net/ 
- 2017-06-10T22:19:31 PID[7692] Verbose  Received request: GET https://albatrossweb.azurewebsites.net/ 
- 2017-06-10T22:19:31 PID[7692] Verbose  Found 'AppServiceAuthSession' cookie for site 'albatrossweb.azurewebsites.net'. Length: 940. 
- 2017-06-10T22:19:31 PID[7692] Verbose  Authenticated [email protected] successfully using 'Session Cookie' authentication. 
- 2017-06-10T22:19:31 PID[7692] Verbose  [Routes(Preview)] No authorization configuration was found. 
- 2017-06-10T22:19:33 PID[7692] Error  Albatross.Web.Controllers.ServiceController:Microsoft.IdentityModel.Clients.ActiveDirectory.AdalSilentTokenAcquisitionException: Failed to acquire token silently as no token was found in the cache. Call method AcquireToken 

編集:ナンゆうが述べたように、「認証/承認」機能が有効になっている場合に

、この問題を複製することができます。作業設定は下の図のとおりです。匿名を要求(アクションなし) これは、月の私が捕まってしまったものですが許可:

  1. は、必ず「アプリケーションサービスの認証」を作る要求が認証されていない場合に取るように
  2. アクションです。私はこれを「Azure Active Directoryでログイン」しました
  3. Azure Active Directoryを正しく設定してください。この情報はチュートリアルで見つけることができます。 URLを返信するよる Azure Active Directory Setup
+0

Open ID Connectオプションで 'ResponseType =" code id_token "を設定してみてください。私はそれを指定する必要はなく、まだコードがありますが、それはかなり奇妙です。 – juunas

答えて

4

https://albatrossweb.azurewebsites.net/.auth/login/aad/callback/は、あなたが紺碧のアプリサービスの「認証/承認」機能を有効にしているようです。私は "認証/許可"機能を有効にした場合、そのシナリオで簡単な認証が認証プロセスを引き継ぐことを再現できます。アプリサービスの「認証/許可」を有効にした場合は、無効にしてからもう一度お試しください。

関連する問題