public void ShouldLoadSettingsFromDirectoryTree() { Environment.SetEnvironmentVariable(YawatSettings.EnvironmentVariableName, string.Empty); var host = YawatSettings.Get("Host"); Assert.AreEqual(host, "localhost"); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <IISServerOptions>(options => { options.AllowSynchronousIO = true; }); services.AddDbContext <TodoContext>(opt => opt.UseInMemoryDatabase("TodoList")); services.AddScoped <IDbInitializer, DbInitializer>(); services.AddCors(options => { // The CORS policy is open for testing purposes. In a production application, you should restrict it to known origins. options.AddPolicy( "AllowAll", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader()); }); services.AddAuthentication("BasicAuthentication") .AddScheme <Microsoft.AspNetCore.Authentication.AuthenticationSchemeOptions, BasicAuthentication.BasicAuthenticationHandler>("BasicAuthentication", null); // configure DI for application services services.AddScoped <BasicAuthentication.IUserService, BasicAuthentication.UserService>(); services.AddAuthentication("IdentityServer4") .AddJwtBearer("IdentityServer4", options => { options.Authority = YawatSettings.Get("IdentityServer.IdentityServerUrl"); options.RequireHttpsMetadata = options.Authority.StartsWith("https://"); options.TokenValidationParameters = new TokenValidationParameters { ValidateAudience = false }; }); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = OktaDefaults.ApiAuthenticationScheme; options.DefaultChallengeScheme = OktaDefaults.ApiAuthenticationScheme; options.DefaultSignInScheme = OktaDefaults.ApiAuthenticationScheme; }) .AddOktaWebApi(new OktaWebApiOptions() { OktaDomain = YawatSettings.Get("Okta.Domain") }); services.AddControllers() .AddPlainTextFormatters() .AddXmlSerializerFormatters() .AddCsvSerializerFormatters() .AddProtobufFormatters() .AddBsonSerializerFormatters() ; }
public void Setup() { this.baseRoute = YawatSettings.Get("BasicAuthentication.BaseRoute"); this.userName = YawatSettings.Get("BasicAuthentication.UserName"); this.password = YawatSettings.Get("BasicAuthentication.Password"); this.options = new YawatOptions(typeof(JsonResponseData)) { Authenticator = new Yawat.Authenticator.BasicAuthenticator(this.userName, this.password), }; }
public void RunBeforeAnyTests() { Options = new Yawat.YawatOptions(typeof(JsonResponseData)) { Host = YawatSettings.Get("Host", "localhost"), Protocol = YawatSettings.Get("Protocol", "https"), Port = YawatSettings.Get("Port", "44328") }; HttpClientWithOptions = new YawatHttpClient(Options); }
public void ShouldLoadSettingsFromEnvironment() { YawatSettings.Reset(); var jsonFileName = Path.Combine(Path.GetTempPath(), YawatSettings.YawatSettingsJsonFileName); Environment.SetEnvironmentVariable(YawatSettings.EnvironmentVariableName, jsonFileName); var jsonObject = new { test = new { user = "******" } }; File.WriteAllText(jsonFileName, Newtonsoft.Json.JsonConvert.SerializeObject(jsonObject)); var testUser = YawatSettings.Get("test.user"); Assert.AreEqual(testUser, "user"); Assert.AreEqual(YawatSettings.SettingsFile, jsonFileName); Environment.SetEnvironmentVariable(YawatSettings.EnvironmentVariableName, string.Empty); File.Delete(jsonFileName); }
public async Task Setup() { this.baseRoute = YawatSettings.Get("IdentityServer.BaseRoute"); var identityServerUrl = YawatSettings.Get("IdentityServer.IdentityServerUrl"); var clientId = YawatSettings.Get("IdentityServer.ClientId"); var clientSecret = YawatSettings.Get("IdentityServer.ClientSecret"); var scope = YawatSettings.Get("IdentityServer.Scope"); this.options = new YawatOptions(typeof(JsonResponseData)) { Authenticator = new Yawat.Authenticator.IdentityServerAuthenticator(identityServerUrl, clientId, clientSecret, scope) }; var success = await this.options.Authenticator.Setup(); if (!success) { Console.WriteLine("IsAuthenticator.Setup() was not successful."); foreach (var error in this.options.Authenticator.GetErrors()) { Console.WriteLine($" {error}"); } } }