/// <summary> /// Initialises a new instance of the <see cref="AuthenticationController"/> class with the given dependencies. /// </summary> /// <param name="logger">A generic logger</param> /// <param name="generalSettings">Configuration for the authentication scope.</param> /// <param name="cookieDecryptionService">A service that can decrypt a .ASPXAUTH cookie.</param> /// <param name="organisationRepository">the repository object that holds valid organisations</param> /// <param name="certificateProvider">Service that can obtain a list of certificates that can be used to generate JSON Web Tokens.</param> /// <param name="signingKeysRetriever">The class to use to obtain the signing keys.</param> public AuthenticationController( ILogger <AuthenticationController> logger, IOptions <GeneralSettings> generalSettings, ISigningKeysRetriever signingKeysRetriever, IJwtSigningCertificateProvider certificateProvider, ISblCookieDecryptionService cookieDecryptionService, IOrganisationRepository organisationRepository) { _logger = logger; _generalSettings = generalSettings.Value; _signingKeysRetriever = signingKeysRetriever; _certificateProvider = certificateProvider; _cookieDecryptionService = cookieDecryptionService; _organisationRepository = organisationRepository; }
/// <summary> /// Initialises a new instance of the <see cref="AuthenticationController"/> class with the given dependencies. /// </summary> /// <param name="logger">A generic logger</param> /// <param name="generalSettings">Configuration for the authentication scope.</param> /// <param name="cookieDecryptionService">A service that can decrypt a .ASPXAUTH cookie.</param> /// <param name="organisationRepository">the repository object that holds valid organisations</param> /// <param name="certificateProvider">Service that can obtain a list of certificates that can be used to generate JSON Web Tokens.</param> /// <param name="userProfileService">Service that can retrieve user profiles.</param> /// <param name="signingKeysRetriever">The class to use to obtain the signing keys.</param> public AuthenticationController( ILogger <AuthenticationController> logger, IOptions <GeneralSettings> generalSettings, ISigningKeysRetriever signingKeysRetriever, IJwtSigningCertificateProvider certificateProvider, ISblCookieDecryptionService cookieDecryptionService, IUserProfileService userProfileService, IOrganisationRepository organisationRepository) { _logger = logger; _generalSettings = generalSettings.Value; _signingKeysRetriever = signingKeysRetriever; _certificateProvider = certificateProvider; _cookieDecryptionService = cookieDecryptionService; _organisationRepository = organisationRepository; _userProfileService = userProfileService; _validator = new JwtSecurityTokenHandler(); }
private HttpClient GetTestClient(ISblCookieDecryptionService cookieDecryptionService, IUserProfileService userProfileService) { Program.ConfigureSetupLogging(); HttpClient client = _factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { services.AddSingleton(cookieDecryptionService); services.AddSingleton(userProfileService); services.AddSingleton <ISigningKeysRetriever, SigningKeysRetrieverStub>(); services.AddSingleton <IJwtSigningCertificateProvider, JwtSigningCertificateProviderStub>(); services.AddSingleton <IPostConfigureOptions <JwtCookieOptions>, JwtCookiePostConfigureOptionsStub>(); services.AddSingleton <ISigningKeysResolver, SigningKeyResolverStub>(); }); }).CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); return(client); }
private HttpClient GetTestClient(ISblCookieDecryptionService cookieDecryptionService) { string projectDir = Directory.GetCurrentDirectory(); string configPath = Path.Combine(projectDir, "appsettings.json"); HttpClient client = _factory.WithWebHostBuilder(builder => { builder.ConfigureTestServices(services => { services.AddSingleton(cookieDecryptionService); services.AddSingleton <ISigningKeysRetriever, SigningKeysRetrieverStub>(); services.AddSingleton <IJwtSigningCertificateProvider, JwtSigningCertificateProviderStub>(); services.AddSingleton <IPostConfigureOptions <JwtCookieOptions>, JwtCookiePostConfigureOptionsStub>(); }); builder.ConfigureAppConfiguration((context, conf) => { conf.AddJsonFile(configPath); }); }).CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); return(client); }
private HttpClient GetTestClient(ISblCookieDecryptionService cookieDecryptionService, IUserProfileService userProfileService, bool enableOidc = false, bool forceOidc = false, string defaultOidc = "altinn") { HttpClient client = _factory.WithWebHostBuilder(builder => { string configPath = GetConfigPath(); builder.ConfigureAppConfiguration((context, conf) => { conf.AddJsonFile(configPath); }); var configuration = new ConfigurationBuilder() .AddJsonFile(configPath) .Build(); configuration.GetSection("GeneralSettings:EnableOidc").Value = enableOidc.ToString(); configuration.GetSection("GeneralSettings:ForceOidc").Value = forceOidc.ToString(); configuration.GetSection("GeneralSettings:DefaultOidcProvider").Value = defaultOidc; IConfigurationSection generalSettingSection = configuration.GetSection("GeneralSettings"); builder.ConfigureTestServices(services => { services.Configure <GeneralSettings>(generalSettingSection); services.AddSingleton(cookieDecryptionService); services.AddSingleton(userProfileService); services.AddSingleton <IOrganisationsService, OrganisationsServiceMock>(); services.AddSingleton <ISigningKeysRetriever, SigningKeysRetrieverStub>(); services.AddSingleton <IJwtSigningCertificateProvider, JwtSigningCertificateProviderStub>(); services.AddSingleton <IPostConfigureOptions <JwtCookieOptions>, JwtCookiePostConfigureOptionsStub>(); services.AddSingleton <ISigningKeysResolver, SigningKeyResolverStub>(); services.AddSingleton <IEnterpriseUserAuthenticationService, EnterpriseUserAuthenticationServiceMock>(); services.AddSingleton <IOidcProvider, OidcProviderServiceMock>(); }); }).CreateClient(new WebApplicationFactoryClientOptions { AllowAutoRedirect = false }); return(client); }