private void ConfigureIdServer(IServiceCollection services) { services.AddSingleton(new SmsAuthenticationOptions()); services.AddTransient <IEventPublisher, DefaultEventPublisher>(); services.AddSingleton <ITwilioClient>(_context.TwilioClient.Object); services.AddTransient <ISmsAuthenticationOperation, SmsAuthenticationOperation>(); services.AddTransient <IGenerateAndSendSmsCodeOperation, GenerateAndSendSmsCodeOperation>(); services.AddTransient <IAuthenticateResourceOwnerService, CustomAuthenticateResourceOwnerService>(); services.AddTransient <IAuthenticateResourceOwnerService, SmsAuthenticateResourceOwnerService>(); services.AddHostIdentityServer(_options) .AddSimpleIdentityServerCore(null, null, DefaultStores.Clients(_context), DefaultStores.Consents(), DefaultStores.JsonWebKeys(_context), null, DefaultStores.Users(), DefaultStores.Scopes(), credentialSettings: DefaultStores.GetCredentialSettings(), acrLst: DefaultStores.GetAcrs()) .AddDefaultTokenStore() .AddStorage(o => o.UseInMemoryStorage()) .AddSimpleIdentityServerJwt() .AddTechnicalLogging() .AddOpenidLogging() .AddOAuthLogging() .AddLogging() .AddTransient <IAccountFilter, AccountFilter.Basic.AccountFilter>() .AddSingleton <IFilterRepository>(new DefaultFilterRepository(null)) .AddSingleton <IHttpClientFactory>(_context.HttpClientFactory); services.AddSingleton <IConfirmationCodeStore>(_context.ConfirmationCodeStore.Object); }
public void ConfigureServices(IServiceCollection services) { services.AddHttpClient(); services.AddCors( options => options.AddPolicy("AllowAll", p => p.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader())); services.AddAuthentication( opts => { opts.DefaultAuthenticateScheme = DefaultSchema; opts.DefaultChallengeScheme = DefaultSchema; }) .AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, _ => { }) .AddFakeCustomAuth(_ => { }); var symmetricAlgorithm = Aes.Create(); symmetricAlgorithm.GenerateIV(); symmetricAlgorithm.GenerateKey(); services.AddTransient <IAuthenticateResourceOwnerService, SmsAuthenticateResourceOwnerService>() .AddSimpleAuth( options => { options.DataProtector = _ => new SymmetricDataProtector(symmetricAlgorithm); options.AdministratorRoleDefinition = default; options.Clients = sp => new InMemoryClientRepository( sp.GetRequiredService <IHttpClientFactory>(), sp.GetRequiredService <IScopeStore>(), new Mock <ILogger <InMemoryClientRepository> >().Object, DefaultStores.Clients(_context)); options.Consents = _ => new InMemoryConsentRepository(DefaultStores.Consents()); options.Users = sp => new InMemoryResourceOwnerRepository(string.Empty, DefaultStores.Users()); }, new[] { JwtBearerDefaults.AuthenticationScheme }) .AddSmsAuthentication(_context.TwilioClient.Object) .AddLogging(b => b.AddXunit(_testOutputHelper)) .AddAccountFilter() .AddSingleton(_context.ConfirmationCodeStore.Object) .AddSingleton( sp => { var server = sp.GetRequiredService <IServer>() as TestServer; return(server.CreateClient()); }); services.ConfigureOptions <JwtBearerPostConfigureOptions>(); }
public void Background() { "Given loaded configuration values".x( () => { var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json", false, false) .Build(); ConnectionString = configuration["Db:ConnectionString"]; OutputHelper.WriteLine(ConnectionString); Assert.NotNull(ConnectionString); }); "Given a configured database".x( async() => { ConnectionString = await DbInitializer.Init( OutputHelper, ConnectionString, DefaultStores.Consents(), DefaultStores.Users(), DefaultStores.Clients(SharedContext.Instance), DefaultStores.Scopes()) .ConfigureAwait(false); var builder = new NpgsqlConnectionStringBuilder(ConnectionString); Assert.False(string.IsNullOrWhiteSpace(builder.SearchPath)); OutputHelper.WriteLine(ConnectionString); }) .Teardown(async() => { await DbInitializer.Drop(ConnectionString, OutputHelper).ConfigureAwait(false); }); "and a running auth server" .x(() => Fixture = new TestServerFixture(OutputHelper, ConnectionString, BaseUrl)) .Teardown(() => Fixture.Dispose()); "And the server signing keys".x( async() => { var keysJson = await Fixture.Client().GetStringAsync(BaseUrl + "/jwks").ConfigureAwait(false); Jwks = new JsonWebKeySet(keysJson); Assert.NotEmpty(Jwks.Keys); }); }
public void Background() { "Given loaded configuration values".x( () => { var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json", false, false).Build(); _connectionString = configuration["Db:ConnectionString"]; Assert.NotNull(_connectionString); }); "Given a configured database".x( async() => { _connectionString = await DbInitializer.Init( _output, _connectionString, DefaultStores.Consents(), DefaultStores.Users(), DefaultStores.Clients(SharedContext.Instance), DefaultStores.Scopes()) .ConfigureAwait(false); }) .Teardown(async() => { await DbInitializer.Drop(_connectionString).ConfigureAwait(false); }); "and a running auth server".x(() => _fixture = new TestServerFixture(_output, _connectionString, BaseUrl)) .Teardown(() => _fixture.Dispose()); "And the server signing keys".x( async() => { var keysJson = await _fixture.Client().GetStringAsync(BaseUrl + "/jwks").ConfigureAwait(false); _jwks = new JsonWebKeySet(keysJson); Assert.NotEmpty(_jwks.Keys); }); }