11using Microsoft . AspNetCore . Builder ;
2- using Microsoft . AspNetCore . Hosting ;
32using Microsoft . Extensions . Configuration ;
43using Microsoft . Extensions . DependencyInjection ;
54using HwProj . AuthService . API . Models ;
65using HwProj . AuthService . API . Repositories ;
76using Microsoft . AspNetCore . Identity ;
87using Microsoft . EntityFrameworkCore ;
98using HwProj . AuthService . API . Services ;
9+ using HwProj . Common . Net8 ;
1010using HwProj . EventBus . Client ;
1111using HwProj . EventBus . Client . Interfaces ;
12- using Microsoft . IdentityModel . Tokens ;
13- using Microsoft . AspNetCore . Authentication . JwtBearer ;
14- using HwProj . Utils . Configuration ;
15- using HwProj . Models . AuthService . ViewModels ;
16- using HwProj . Models . Roles ;
17- using HwProj . Utils . Auth ;
12+ using Microsoft . Extensions . Hosting ;
1813using User = HwProj . AuthService . API . Models . User ;
1914
2015namespace HwProj . AuthService . API
@@ -31,25 +26,6 @@ public Startup(IConfiguration configuration)
3126 public void ConfigureServices ( IServiceCollection services )
3227 {
3328 services . ConfigureHwProjServices ( "AuthService API" ) ;
34-
35- //var appSettingsSection = Configuration.GetSection("AppSettings");
36- //services.Configure<AppSettings>(appSettingsSection);
37-
38- services . AddAuthentication ( options => { options . DefaultScheme = JwtBearerDefaults . AuthenticationScheme ; } )
39- . AddJwtBearer ( x =>
40- {
41- x . RequireHttpsMetadata = false ; //TODO: dev env setting
42- x . TokenValidationParameters = new TokenValidationParameters
43- {
44- ValidIssuer = "AuthService" ,
45- ValidateIssuer = true ,
46- ValidateAudience = false ,
47- ValidateLifetime = true ,
48- IssuerSigningKey = AuthorizationKey . SecurityKey ,
49- ValidateIssuerSigningKey = true
50- } ;
51- } ) ;
52-
5329 services . AddHttpClient ( ) ;
5430
5531 var connectionString = ConnectionString . GetConnectionString ( Configuration ) ;
@@ -79,22 +55,19 @@ public void ConfigureServices(IServiceCollection services)
7955 . AddScoped < IExpertsRepository , ExpertsRepository > ( ) ;
8056 }
8157
82- public void Configure ( IApplicationBuilder app , IHostingEnvironment env , IdentityContext context )
58+ public void Configure ( IApplicationBuilder app , IHostEnvironment env , IdentityContext context )
8359 {
8460 app . ConfigureHwProj ( env , "AuthService API" , context ) ;
8561
86- using ( var scope = app . ApplicationServices . CreateScope ( ) )
87- {
88- var userManager = scope . ServiceProvider . GetService ( typeof ( UserManager < User > ) ) as UserManager < User > ;
62+ using var scope = app . ApplicationServices . CreateScope ( ) ;
63+ var userManager = scope . ServiceProvider . GetService < UserManager < User > > ( ) ;
8964
90- var rolesManager =
91- scope . ServiceProvider . GetService ( typeof ( RoleManager < IdentityRole > ) ) as RoleManager < IdentityRole > ;
92- var eventBus = scope . ServiceProvider . GetService < IEventBus > ( ) ;
65+ var rolesManager = scope . ServiceProvider . GetService < RoleManager < IdentityRole > > ( ) ;
66+ var eventBus = scope . ServiceProvider . GetService < IEventBus > ( ) ;
9367
94- if ( env . IsDevelopment ( ) )
95- {
96- RoleInitializer . InitializeAsync ( userManager , rolesManager , eventBus ) . Wait ( ) ;
97- }
68+ if ( env . IsDevelopment ( ) )
69+ {
70+ RoleInitializer . InitializeAsync ( userManager , rolesManager , eventBus ) . Wait ( ) ;
9871 }
9972 }
10073 }
0 commit comments