2016-10-02 2 views
3
나는 현재 신원 서버에 API 호출 4.
내 자신감 의존성 권한을 부여하는 데 자신감을 사용하여 문제가있어

는 신원 서버 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, 

}); 

이 인증을 위해 구성 방법의 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. Swagger의 클라이언트 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"); 
    }); 
} 
관련 문제