public virtual TService BuildRefitClient <TService>(TokenResponse token = null) { return(RestService.For <TService>(BuildHttpClient(token), new RefitSettings { ContentSerializer = new JsonContentSerializer(DefaultJsonContentFormatter.SerializeSettings()) })); }
protected virtual JsonSerializerSettings GetSettings() { if (_settingsCache == null) { _settingsCache = DefaultJsonContentFormatter.SerializeSettings(); _settingsCache.TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple; _settingsCache.TypeNameHandling = TypeNameHandling.All; _settingsCache.Converters = new List <JsonConverter> { new ThrowExceptionForDateTimeOffsetValues() }; } return(_settingsCache); }
public virtual void Configure(IAppBuilder owinApp) { if (owinApp == null) { throw new ArgumentNullException(nameof(owinApp)); } _webApiConfig = new HttpConfiguration(); _webApiConfig.SuppressHostPrincipal(); _webApiConfig.IncludeErrorDetailPolicy = AppEnvironment.DebugMode ? IncludeErrorDetailPolicy.LocalOnly : IncludeErrorDetailPolicy.Never; _webApiConfig.DependencyResolver = WebApiDependencyResolver; _webApiConfig.Formatters.JsonFormatter.SerializerSettings = DefaultJsonContentFormatter.SerializeSettings(); WebApiConfigurationCustomizers.ToList() .ForEach(webApiConfigurationCustomizer => { webApiConfigurationCustomizer.CustomizeWebApiConfiguration(_webApiConfig); }); _server = new HttpServer(_webApiConfig); DefaultInlineConstraintResolver constraintResolver = new DefaultInlineConstraintResolver() { ConstraintMap = { ["apiVersion"] = typeof(ApiVersionRouteConstraint) } }; _webApiConfig.AddApiVersioning(apiVerOptions => { apiVerOptions.ReportApiVersions = true; apiVerOptions.AssumeDefaultVersionWhenUnspecified = true; }); _webApiConfig.MapHttpAttributeRoutes(constraintResolver); if (_webApiConfig.Properties.TryGetValue("MultiVersionSwaggerConfiguration", out object actionObj)) { ((Action)actionObj).Invoke(); } _webApiConfig.Routes.MapHttpRoute(name: "default", routeTemplate: "{controller}/{action}", defaults: new { action = RouteParameter.Optional }); owinApp.UseAutofacWebApi(_webApiConfig); WebApiOwinPipelineInjector.UseWebApi(owinApp, _server, _webApiConfig); _webApiConfig.EnsureInitialized(); }
public static async Task ExecuteTest(this RemoteWebDriver driver, string testScript, params object[] args) { if (driver == null) { throw new ArgumentNullException(nameof(driver)); } if (testScript == null) { throw new ArgumentNullException(nameof(testScript)); } if (args == null) { throw new ArgumentNullException(nameof(args)); } IWebElement testsConsole = driver.GetElementById("testsConsole"); const string success = "Success"; string consoleValue = testsConsole.GetAttribute("value"); string arguments = JsonConvert.SerializeObject(args, DefaultJsonContentFormatter.SerializeSettings()); string finalTestScript = $"executeTest({testScript},'{arguments}');"; driver.ExecuteScript(finalTestScript); string value = consoleValue; await driver.WaitForCondition(d => testsConsole.GetAttribute("value") != value).ConfigureAwait(false); consoleValue = testsConsole.GetAttribute("value"); bool testIsPassed = consoleValue == success; Console.WriteLine("Test console value: " + consoleValue); Console.WriteLine("Url: " + driver.Url); Console.WriteLine("Final test script: " + finalTestScript); if (testIsPassed != true) { throw new InvalidOperationException(consoleValue); } }
public virtual async Task <Stream> Login(LoginViewModel model, SignInMessage message) { JsonSerializerSettings jsonSerSettings = DefaultJsonContentFormatter.SerializeSettings(); jsonSerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); if (model.Custom == null && message.ReturnUrl != null) { try { dynamic custom = model.Custom = UrlStateProvider.GetState(new Uri(message.ReturnUrl)); string signInType = null; try { signInType = custom.SignInType; } catch { } if (signInType != null && model.ExternalProviders.Any(extProvider => extProvider.Type == signInType)) { string redirectUri = model.ExternalProviders.Single(extProvider => extProvider.Type == signInType).Href; return(await ReturnHtmlAsync(model, $@"<!DOCTYPE html> <html> <head> <meta http-equiv='refresh' content='0;{redirectUri}'> </head> <body></body> </html>", OwinContext.Request.CallCancelled).ConfigureAwait(false)); } } catch { model.Custom = new { }; } } string json = JsonConvert.SerializeObject(new { model.AdditionalLinks, model.AllowRememberMe, model.AntiForgery, model.ClientLogoUrl, model.ClientName, model.ClientUrl, model.CurrentUser, model.Custom, model.ErrorMessage, model.ExternalProviders, model.LoginUrl, model.LogoutUrl, model.RememberMe, model.RequestId, model.SiteName, model.SiteUrl, model.Username, ReturnUrl = message.ReturnUrl == null ? "" : new Uri(message.ReturnUrl).ParseQueryString()["redirect_uri"] }, Formatting.None, jsonSerSettings); string loginPageHtmlInitialHtml = File.ReadAllText(PathProvider.MapStaticFilePath(AppEnvironment.GetConfig("LoginPagePath", "loginPage.html"))); string loginPageHtmlFinalHtml = (await HtmlPageProvider.GetHtmlPageAsync(loginPageHtmlInitialHtml, OwinContext.Request.CallCancelled).ConfigureAwait(false)) .Replace("{{model.LoginModel.toJson()}}", Microsoft.Security.Application.Encoder.HtmlEncode(json), StringComparison.InvariantCultureIgnoreCase); return(await ReturnHtmlAsync(model, loginPageHtmlFinalHtml, OwinContext.Request.CallCancelled).ConfigureAwait(false)); }
public BitRefitJsonContentSerializer() : this(DefaultJsonContentFormatter.SerializeSettings(), DefaultJsonContentFormatter.DeserializeSettings()) { }
public virtual async Task <Stream> Login(LoginViewModel model, SignInMessage message) { JsonSerializerSettings jsonSerSettings = DefaultJsonContentFormatter.SerializeSettings(); jsonSerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); if (model.Custom == null && message.ReturnUrl != null) { string state = new Uri(message.ReturnUrl).ParseQueryString()["state"] ?? "{}"; try { dynamic custom = model.Custom = CustomLoginDataProvider.GetCustomData(message); string signInType = null; try { signInType = custom.SignInType; } catch { } if (signInType != null && model.ExternalProviders.Any(extProvider => extProvider.Type == signInType)) { string redirectUri = model.ExternalProviders.Single(extProvider => extProvider.Type == signInType).Href; return(await ReturnHtmlAsync(model, $@"<!DOCTYPE html> <html> <head> <meta http-equiv='refresh' content='0;{redirectUri}'> </head> <body></body> </html>", CancellationToken.None).ConfigureAwait(false)); } } catch { model.Custom = new { }; } } string json = JsonConvert.SerializeObject(new { model.AdditionalLinks, model.AllowRememberMe, model.AntiForgery, model.ClientLogoUrl, model.ClientName, model.ClientUrl, model.CurrentUser, model.Custom, model.ErrorMessage, model.ExternalProviders, model.LoginUrl, model.LogoutUrl, model.RememberMe, model.RequestId, model.SiteName, model.SiteUrl, model.Username, ReturnUrl = message.ReturnUrl == null ? "" : new Uri(message.ReturnUrl).ParseQueryString()["redirect_uri"] }, Formatting.None, jsonSerSettings); string loginPageHtml = (await SsoHtmlPageProvider.GetSsoPageAsync(CancellationToken.None).ConfigureAwait(false)) .Replace("{model}", Microsoft.Security.Application.Encoder.HtmlEncode(json)); return(await ReturnHtmlAsync(model, loginPageHtml, CancellationToken.None).ConfigureAwait(false)); }