22using System . Collections . Generic ;
33using System . Linq ;
44using System . Threading . Tasks ;
5+ using IdentityServer4 . AccessTokenValidation ;
56using Microsoft . AspNetCore . Builder ;
67using Microsoft . AspNetCore . Hosting ;
78using Microsoft . AspNetCore . Http ;
89using Microsoft . Extensions . Configuration ;
910using Microsoft . Extensions . DependencyInjection ;
1011using Microsoft . Extensions . Hosting ;
12+ using Ocelot . Administration ;
1113using Ocelot . DependencyInjection ;
1214using Ocelot . Middleware ;
1315
@@ -23,21 +25,28 @@ public Startup(IConfiguration configuration, IWebHostEnvironment env)
2325 . SetBasePath ( env . ContentRootPath )
2426 . AddJsonFile ( "appsettings.json" , optional : false , reloadOnChange : true )
2527 . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true , reloadOnChange : true )
26- . AddJsonFile ( "ocelot.json" ) ;
28+ . AddJsonFile ( "ocelot.json" )
29+ . AddJsonFile ( $ "ocelot.{ env . EnvironmentName } .json", optional : true , reloadOnChange : true ) ;
2730 Configuration = builder . Build ( ) ;
2831 }
2932
3033 // This method gets called by the runtime. Use this method to add services to the container.
3134 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
3235 public void ConfigureServices ( IServiceCollection services )
3336 {
34- services . AddOcelot ( Configuration ) ;
37+ services . AddOcelot ( Configuration ) . AddAdministration ( "/administration" , options=>
38+ {
39+ options . Authority = "http://passport-test.39.net" ; ///connect/token
40+ options . ApiName = "api1" ;
41+ options . RequireHttpsMetadata = false ;
42+ options . SupportedTokens = SupportedTokens . Both ;
43+ options . ApiSecret = "secret" ;
44+ } ) ;
3545 }
3646
3747 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
3848 public void Configure ( IApplicationBuilder app , IWebHostEnvironment env )
3949 {
40- app . UseRouting ( ) ;
4150 app . UseOcelot ( ) . Wait ( ) ;
4251 }
4352 }
0 commit comments