88using Microsoft . AspNetCore . Hosting ;
99using Microsoft . Extensions . Configuration ;
1010using Microsoft . Extensions . DependencyInjection ;
11+ using Microsoft . Extensions . Logging ;
1112
1213namespace Jp . UserManagement
1314{
1415 public class Startup
1516 {
17+ private readonly ILogger < Startup > _logger ;
1618 public IConfiguration Configuration { get ; }
1719 public IHostingEnvironment HostEnvironment { get ; }
1820
19- public Startup ( IHostingEnvironment hostEnvironment )
21+ public Startup ( IHostingEnvironment hostEnvironment , ILogger < Startup > logger )
2022 {
23+ _logger = logger ;
2124 var builder = new ConfigurationBuilder ( )
2225 . SetBasePath ( hostEnvironment . ContentRootPath )
2326 . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : true )
@@ -42,25 +45,25 @@ public void ConfigureServices(IServiceCollection services)
4245 services . AddIdentity ( Configuration ) ;
4346 services . ConfigureCors ( ) ;
4447
45-
46- //services.AddAuthentication(IdentityServerAuthenticationDefaults.AuthenticationScheme)
48+ var authorityUri = Environment . GetEnvironmentVariable ( "AUTHORITY" ) ?? "http://localhost:5000" ;
49+ _logger . LogInformation ( $ "Authority URI: { authorityUri } " ) ;
4750 services . AddAuthentication ( options =>
4851 {
4952 options . DefaultAuthenticateScheme = IdentityServerAuthenticationDefaults . AuthenticationScheme ;
5053 options . DefaultChallengeScheme = IdentityServerAuthenticationDefaults . AuthenticationScheme ;
51-
54+
5255 } )
5356 . AddIdentityServerAuthentication ( options =>
5457 {
55- options . Authority = Environment . GetEnvironmentVariable ( "AUTHORITY" ) ?? "http://localhost:5000" ;
58+ options . Authority = authorityUri ;
5659 options . RequireHttpsMetadata = false ;
5760 options . ApiSecret = "Q&tGrEQMypEk.XxPU:%bWDZMdpZeJiyMwpLv4F7d**w9x:7KuJ#fy,E8KPHpKz++" ;
5861 options . ApiName = "UserManagementApi" ;
5962
6063
6164 options . JwtBearerEvents . OnMessageReceived = ( messae ) =>
6265 {
63- messae . Options . TokenValidationParameters . ValidateIssuer = bool . TryParse ( Environment . GetEnvironmentVariable ( "VALIDATE_ISSUER" ) ?? "true" , out _ ) ;
66+ messae . Options . TokenValidationParameters . ValidateIssuer = bool . Parse ( Environment . GetEnvironmentVariable ( "VALIDATE_ISSUER" ) ?? "true" ) ;
6467 return Task . CompletedTask ;
6568 } ;
6669 } ) ;
0 commit comments