1- using HwProj . AuthService . Client ;
1+ using System . IO ;
2+ using Google . Apis . Auth . OAuth2 ;
3+ using Google . Apis . Services ;
4+ using Google . Apis . Sheets . v4 ;
5+ using HwProj . AuthService . Client ;
26using HwProj . CoursesService . Client ;
37using HwProj . NotificationsService . Client ;
48using HwProj . SolutionsService . Client ;
@@ -26,7 +30,7 @@ public void ConfigureServices(IServiceCollection services)
2630 services . ConfigureHwProjServices ( "API Gateway" ) ;
2731
2832 const string authenticationProviderKey = "GatewayKey" ;
29-
33+
3034 services . AddAuthentication ( )
3135 . AddJwtBearer ( authenticationProviderKey , x =>
3236 {
@@ -44,6 +48,7 @@ public void ConfigureServices(IServiceCollection services)
4448
4549 services . AddHttpClient ( ) ;
4650 services . AddHttpContextAccessor ( ) ;
51+ services . AddScoped ( _ => ConfigureGoogleSheets ( ) ) ;
4752
4853 services . AddAuthServiceClient ( ) ;
4954 services . AddCoursesServiceClient ( ) ;
@@ -55,5 +60,17 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
5560 {
5661 app . ConfigureHwProj ( env , "API Gateway" ) ;
5762 }
63+
64+ private static SheetsService ConfigureGoogleSheets ( )
65+ {
66+ using var stream = new FileStream ( "googlesheets_credentials.json" , FileMode . Open , FileAccess . ReadWrite ) ;
67+ var credential = GoogleCredential . FromStream ( stream ) . CreateScoped ( SheetsService . Scope . Spreadsheets ) ;
68+
69+ return new SheetsService ( new BaseClientService . Initializer
70+ {
71+ HttpClientInitializer = credential ,
72+ ApplicationName = "HwProjSheets"
73+ } ) ;
74+ }
5875 }
5976}
0 commit comments