2016-10-02 8 views
3
私は現在、アイデンティティサーバーへのAPIコール4.
マイ闊歩依存性を認証するために闊歩を使用して問題を抱えている

がIDサーバ4にswashbuckleバージョン ベータクライアントオブジェクトを使用しているがIdentity Serverの4闊歩認証

のように見えます
new Client 
{ 
    ClientId="swagger", 
    Enabled = true, 
    ClientName="Swagger", 
    AllowedGrantTypes = GrantTypes.Implicit, 
    ClientSecrets = new List<Secret> 
    { 
     new Secret("secret".Sha256()) 
    }, 
    AllowedScopes = new List<string> 
    { 
     "apil" 
    }, 
    RedirectUris = new List<string> 
    { 
     "http://localhost:15138/swagger/ui/popup.html" 
    }, 
    AllowedCorsOrigins = new List<string> 
    { 
     "http://localhost:15138", 
     "http://localhost:15138" 
    }, 
    AllowAccessTokensViaBrowser = true, 
    AllowAccessToAllScopes= true 
} 

クライアントオブジェクトは、私が使用してこの

app.UseIdentityServer(); 
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap = new Dictionary<string, string>(); 
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions 
{ 
    Authority = "http://localhost:15138/", 
    ScopeName = "apil", 
    RequireHttpsMetadata = false, 

}); 

を持っている認証のためのconfigureメソッドでIDサーバ4モデル です私のget要求がこの

GET /認可/接続?状態= 9321480892748389 &ナンス= 5279296493808222 &のclient_id =闊歩& REDIRECT_URI =のhttp%3A%2F%2Flocalhost%3A15138%2Fswagger%2Fui%2Fpopupのように見えますシオマネキ。 HTML & response_type = id_token%20token &範囲= apil HTTP/1.1

すべての必要なパラメータがあり、クライアントは、対応するクライアントIDを持っていますが、私は戻って取得応答が持つエラーページにリダイレクトされますメッセージo f無効な要求です。私はログインページに資格証明書などを渡すことを期待していました。承認されるためには、何が起こったのか、私が間違っていたのか疑問に思っていました。

答えて

3

私はこの同じ問題に遭遇し、それはいくつかの異なる事柄に関連していました。

  1. スワッガーにはセキュリティ定義が設定されている必要があります。

  2. IdentityServerAuthentication AutomaticAuthenticateがtrueである必要があります。

  3. スワッガーのクライアントIDとクライアント名をStartup.csで設定する必要があります。

は、以下を参照してください。

public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddSwaggerGen(c => { 
     c.SwaggerDoc("v1", new Info 
     { 
      Version = "v1", 
      Title = "my api title", 
      Description = "my api desc", 
      TermsOfService = "None", 
      Contact = new Contact { Name = "contact" } 
     }); 

     var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "api.xml"); 
     c.IncludeXmlComments(filePath); 

     c.AddSecurityDefinition("oauth2", new OAuth2Scheme 
     { 
      Type = "oauth2", 
      Flow = "implicit", 
      AuthorizationUrl = "https://url", 
      Scopes = new Dictionary<string, string> 
      { 
       { "api-name", "my api" } 
      } 
     }); 
    }); 
} 

public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) 
{ 
    loggerFactory.AddConsole(Configuration.GetSection("Logging")); 
    loggerFactory.AddDebug(); 

    app.UseIdentity(); 

    app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions 
    { 
     Authority = "https://url", 
     RequireHttpsMetadata = true, 
     ApiName = "api-name", 
     ApiSecret = "api-secret", 
     AllowedScopes = { "api-name", "openid", "email", "profile" }, 
     ClaimsIssuer = "https://url", 
     AutomaticAuthenticate = true, 
    }); 

    app.UseStaticFiles(); 
    app.UseMvc(); 

    // Enable middleware to serve generated Swagger as a JSON endpoint 
    app.UseSwagger(); 

    // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) 
    app.UseSwaggerUi(c => 
    { 
     c.ConfigureOAuth2("swagger-name", "swagger-secret", "swagger-realm", "Swagger"); 
    }); 
}