1

IdentityServer3と外部プロバイダで異常な動作が見られました。私は誰かが私が逃した明白な何かを指摘できると思っています。IdentityServer3、Azure Active Directory外部プロバイダ、メッセージ= 'アクションが返されました' System.Web.Http.Results.Unauthorized ''

概要

まず外部ログイン要求をのみ、ロギングを通して見える下のエラーで返され、結果される要求を待っているブラウザを設定します。ブラウザで要求を取り消し、直ちにボタンを再度クリックすると、意図したとおりに動作し、ブラウザは外部ログイン画面に送られます。


私はAzureのActive Directoryを活用し、把握することができるよう私もいくつかの参照とドキュメントに従ってIDSrv3設定した

設定。

var wsFedOptions = new WsFederationPluginOptions(options); 
    wsFedOptions.Factory.Register(new Registration<IEnumerable<RelyingParty>>(RelyingParties.Get())); 
    wsFedOptions.Factory.RelyingPartyService = new Registration<IRelyingPartyService>(typeof(InMemoryRelyingPartyService)); 
    app.UseWsFederationPlugin(wsFedOptions); 



var aad = new OpenIdConnectAuthenticationOptions 
      { 
       AuthenticationType = "AzureAd", 
       Caption = "Azure AD", 
       SignInAsAuthenticationType = signInAsType, 
       PostLogoutRedirectUri = Settings.LogoutRedirect, 
       Authority = Settings.AADAuthority, 
       ClientId = Settings.AADClientId, 
       RedirectUri = Settings.AADRedirectUrl 
      }; 

      app.UseOpenIdConnectAuthentication(aad); 

[ログイン]ビューでは、上記のキャプション(Azure AD)として、[外部ログイン]ボタンが表示されます。このボタンを初めてクリックすると、ブラウザはホストの待機を待っています。

ログに次のエラーがあります。


iisexpress.exe Information: 0 : 2017-04-05 08:28:09.708 -05:00 [Information] External login requested for provider: "AzureAd" 
iisexpress.exe Information: 0 : 2017-04-05 08:28:09.714 -05:00 [Information] Triggering challenge for external identity provider 
LibLog Information: 0 : [2017-04-05T13:28:09.7176576Z] Level=Info, Kind=End, Category='System.Web.Http.Action', Id=800000ad-0002-fb00-b63f-84710c7967bb, Message='Action returned 'System.Web.Http.Results.UnauthorizedResult'', Operation=ReflectedHttpActionDescriptor.ExecuteAsync 
LibLog Information: 0 : [2017-04-05T13:28:09.7206611Z] Level=Info, Kind=End, Category='System.Web.Http.Action', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=ApiControllerActionInvoker.InvokeActionAsync, Status=401 (Unauthorized) 
LibLog Information: 0 : [2017-04-05T13:28:09.7216630Z] Level=Info, Kind=Begin, Category='System.Web.Http.Filters', Id=800000ad-0002-fb00-b63f-84710c7967bb, Message='Action filter for 'LoginExternal(String signin, String provider)'', Operation=NoCacheAttribute.OnActionExecutedAsync, Status=401 (Unauthorized) 
LibLog Information: 0 : [2017-04-05T13:28:09.7226640Z] Level=Info, Kind=End, Category='System.Web.Http.Filters', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=NoCacheAttribute.OnActionExecutedAsync, Status=401 (Unauthorized) 
LibLog Information: 0 : [2017-04-05T13:28:09.7226640Z] Level=Info, Kind=Begin, Category='System.Web.Http.Filters', Id=800000ad-0002-fb00-b63f-84710c7967bb, Message='Action filter for 'LoginExternal(String signin, String provider)'', Operation=SecurityHeadersAttribute.OnActionExecutedAsync, Status=401 (Unauthorized) 
LibLog Information: 0 : [2017-04-05T13:28:09.7236655Z] Level=Info, Kind=End, Category='System.Web.Http.Filters', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=SecurityHeadersAttribute.OnActionExecutedAsync, Status=401 (Unauthorized) 
LibLog Information: 0 : [2017-04-05T13:28:09.7246669Z] Level=Info, Kind=End, Category='System.Web.Http.Controllers', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=AuthenticationController.ExecuteAsync, Status=401 (Unauthorized) 
LibLog Information: 0 : [2017-04-05T13:28:09.7251836Z] Level=Info, Kind=End, Category='System.Web.Http.MessageHandlers', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=PassiveAuthenticationMessageHandler.SendAsync, Status=401 (Unauthorized) 
LibLog Information: 0 : [2017-04-05T13:28:09.7261856Z] Level=Info, Kind=End, Category='System.Web.Http.MessageHandlers', Id=800000ad-0002-fb00-b63f-84710c7967bb, Operation=DependencyScopeHandler.SendAsync, Status=401 (Unauthorized) 
LibLog Information: 0 : [2017-04-05T13:28:09.7271879Z] Sending response, Status=401 (Unauthorized), Method=GET, Url=https://localhost:44396/identity/external?provider=AzureAd&signin=2d92dd18a6106c9b029eb8742d4117a1, Id=800000ad-0002-fb00-b63f-84710c7967bb, Message='Content-type='none', content-length=unknown' 

ブラウザはローカルホスト上で無期限に待機します。 リクエストを停止して直ちにボタンをクリックすると、すべてが意図どおりに機能します。

+0

エラーがライン330直前context.AuthenticationでIDSrv3 AuthenticatioinController.csで何が起こっているように見えるOpenIdAuthenticationOptionsにマネージャを追加

 var manager = new SyncConfigurationManager(new ConfigurationManager < OpenIdConnectConfiguration > (Settings.AADAuthority + "/.well-known/openid-configuration")); 

OpenIdConnectConfiguration

を代入

https://github.com/IdentityServer/IdentityServer3/blob/master/source/Host.Configuration/Extensions/SyncConfigurationManager.cs

.Challenget(authProp、provider)このメソッドはすぐにUnauthorized()を返します。 –

答えて

0

この問題は、Katana OIDC MWのデッドロックのバグに関連しています。 回避策は、カスタムIConfigurationManagerを作成し、起動時にメタデータを手動で取得することです。 Thinktectureが提案したものと同様です。その後



    var aad = new OpenIdConnectAuthenticationOptions 
       { 
        AuthenticationType = "AzureAd", 
        Caption = "Marquis Azure AD", 
        SignInAsAuthenticationType = signInAsType, 
        PostLogoutRedirectUri = Settings.LogoutRedirect, 
        Authority = Settings.AADAuthority, 
        ClientId = Settings.AADClientId, 
        RedirectUri = Settings.AADRedirectUrl, 
        ConfigurationManager = manager 
       }; 

1

OpenIdConnectAuthenticationOptionsに基づいてコードが正しいようです。私はまた、IdentityServer3アズールとADアカウントにログインするには、以下のコードを使用していますし、それは私のためによく働く:

public class Startup 
{ 
    public void Configuration(IAppBuilder app) 
    { 
     Log.Logger = new LoggerConfiguration() 
      .MinimumLevel.Debug() 
      .WriteTo.Trace() 
      .CreateLogger(); 

     var users = new List<InMemoryUser>() 
     { 
      new InMemoryUser 
      { 
       Username="Jack", Password="Jack", 
       Claims= new List<Claim> 
       { 
        new Claim("name","Jack"), 
        new Claim("email","[email protected]"), 
        new Claim("role","Admin"), 
       } 
      } 
     }; 

     var clients = new Client[] 
     { 
      new Client 
      { 
       ClientId="mvc", 
       ClientName="MVC Demo Client", 
       Flow=Flows.Implicit, 
       RedirectUris=new List<string> 
       { 
        "http://localhost:9000", 
        "http://localhost:1409/" 
       }, 
       AllowedScopes=new List<string> 
       { 
        "openid","email","profile","roles" 
       } 
      } 
     }; 

     var scopes = new Scope[] 
      { 
       StandardScopes.OpenId, 
       StandardScopes.ProfileAlwaysInclude, 
       StandardScopes.EmailAlwaysInclude, 
       new Scope 
       { 
        Name="roles", 
        Claims=new List<ScopeClaim> 
        { 
         new ScopeClaim("role") 
        }, 
        Type=ScopeType.Identity 
       } 
      }; 

     var factory = new IdentityServerServiceFactory(); 
     factory.UseInMemoryClients(clients); 
     factory.UseInMemoryScopes(scopes); 
     factory.UseInMemoryUsers(users); 

     var cert = LoadCertificate(); 

     app.UseIdentityServer(new IdentityServerOptions 
     { 
      SiteName = "NDC Demo", 
      SigningCertificate = cert, 
      Factory = factory, 
      AuthenticationOptions = new AuthenticationOptions 
      { 
       IdentityProviders = ConfigureAdditionalIdentityProviders, 
       EnableAutoCallbackForFederatedSignout = true 
      } 
     }); 
    } 

    public static void ConfigureAdditionalIdentityProviders(IAppBuilder app, string signInAsType) 
    { 
     app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions 
     { 
      AuthenticationType = "aad", 
      Caption = "Azure AD", 
      SignInAsAuthenticationType = signInAsType, 

      Authority = "https://login.microsoftonline.com/04e14a2c-0e9b-42f8-8b22-3c4a2f1d8800", 
      ClientId = "eca61fd9-f491-4f03-a622-90837bbc1711", 
      RedirectUri = "https://localhost:44333/core/aadcb", 
     }); 
    } 

    static X509Certificate2 LoadCertificate() 
    { 
     var baseFolder = AppDomain.CurrentDomain.BaseDirectory; 
     string certificatePath = $"{baseFolder}\\Certificates\\mycompanyname.pfx"; 
     return new X509Certificate2(certificatePath, "", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet); 
    } 
} 

はその後、我々は以下の要求にIdentityServer3と対話することができます

https://localhost:44333/connect/authorize?response_type=id_token&client_id=mvc&redirect_uri=http://localhost:9000&scope=openid+email+profile+roles&nonce=123

してくださいそれが役に立つかどうか私に教えてください。

+0

あなたの設定で、私がlogin.windows.net/[tenantID]を使用していることを除いて、私のものではないものはありません。私が言ったように、それは動作しますが、私が最初の要求をキャンセルした場合に限ります。私はIDSrv3がここの問題の根源だと思っています。努力してくれてありがとう。 –

関連する問題