public static IServiceCollection AddCustomTypes(this IServiceCollection serviceCollection) { serviceCollection.AddMemoryCache(); serviceCollection.AddScoped <EnvironmentSettings>(); serviceCollection.AddTransient <AddBearerTokenHeaderHandler>(); serviceCollection.AddTransient <UserApiTokenHandler>(); serviceCollection.AddTransient <BookingsApiTokenHandler>(); serviceCollection.AddScoped <ITokenProvider, TokenProvider>(); serviceCollection.AddScoped <SecuritySettings>(); // Build the hearings api client using a reusable HttpClient factory and predefined base url var container = serviceCollection.BuildServiceProvider(); var serviceSettings = container.GetService <IOptions <ServiceSettings> >().Value; var customTokenSettings = container.GetService <CustomTokenSettings>(); var customJwtTokenProvider = new CustomJwtTokenProvider ( customTokenSettings.Secret, customTokenSettings.Audience, customTokenSettings.Issuer, customTokenSettings.ThirdPartySecret ); serviceCollection.AddSingleton <ICustomJwtTokenProvider>(customJwtTokenProvider); serviceCollection.AddHttpClient <IUserApiClient, UserApiClient>() .AddHttpMessageHandler(() => container.GetService <UserApiTokenHandler>()) .AddTypedClient(httpClient => BuildUserApiClient(httpClient, serviceSettings)); serviceCollection.AddHttpClient <IBookingsApiClient, BookingsApiClient>() .AddHttpMessageHandler(() => container.GetService <BookingsApiTokenHandler>()) .AddTypedClient(httpClient => BuildBookingsApiClient(httpClient, serviceSettings)); serviceCollection.AddTransient <IParticipantService, ParticipantService>(); serviceCollection.AddTransient <IHearingsService, HearingsService>(); serviceCollection.AddTransient <IHearingSuitabilityService, HearingSuitabilityService>(); serviceCollection.AddScoped <IHashGenerator>(x => new HashGenerator(customTokenSettings.Secret)); serviceCollection.AddTransient <IKinlyPlatformService>(x => new KinlyPlatformService(customJwtTokenProvider, serviceSettings.KinlySelfTestScoreEndpointUrl)); serviceCollection.AddSwaggerToApi(); return(serviceCollection); }
public static string SetCustomJwTokenForCallback(KinlyConfiguration kinlyConfiguration) { var generateTokenWithAsciiKey = new CustomJwtTokenProvider(kinlyConfiguration).GenerateTokenForCallbackEndpoint("VhVideoApi", TokenExpiresInMinutes); return(generateTokenWithAsciiKey); }