public virtual void ProcessRequest(HttpContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var state = ReadStateQueryParameter(context); if (!(GetValue(context, state, AuthServiceProvider.ProviderParameter) is string providerName)) { return; } AuthenticationElement authenticationElement = GetAuthenticationElement(); AuthServiceProvider provider = GetServiceProvider(providerName); if (provider == null) { return; } AuthLoginOptions loginOptions = ConvertUtilities.ChangeType(GetValue(context, state, AuthServiceProvider.OptionsParameter), AuthLoginOptions.None); int attempt = 0; UserData userData = null; while (attempt < authenticationElement.MaximumRetryCount) { try { userData = provider.GetUserData(context); break; } catch (Exception ex) { if (!OnGetUserDataError(context, ex, attempt)) { break; } attempt++; if (authenticationElement.RetryInterval > 0) { Thread.Sleep(authenticationElement.RetryInterval); } } } if (userData == null) { Authenticate(context, provider, loginOptions); } else { Authenticate(context, provider, loginOptions, userData); } }
/// <summary> /// Initialises a new instance of the <see cref="WebTestService"/> class. /// </summary> /// <param name="settings"><see cref="IWebTestSettingsElement"/> instance.</param> /// <param name="authenticationContext"><see cref="IAuthenticationContextWrapper"/> instance.</param> public WebTestService(IWebTestSettingsElement settings, IAuthenticationContextWrapper authenticationContext) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } this._auth = settings.Authentication.Clone(); this._appInsights = settings.ApplicationInsight.Clone(); this._webTests = settings.WebTests.Clone().OfType <WebTestElement>().ToList(); if (authenticationContext == null) { throw new ArgumentNullException(nameof(authenticationContext)); } this._authenticationContext = authenticationContext; }
protected virtual void RedirectSuccess(HttpContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } string url = null; var state = ReadStateQueryParameter(context); if (state != null && state.ContainsKey(AuthServiceProvider.UrlParameter)) { url = state[AuthServiceProvider.UrlParameter] as string; } else { url = context.Request[AuthServiceProvider.UrlParameter].Nullify(trim: true); } if (string.IsNullOrEmpty(url)) { string providerName = GetValue(context, state, AuthServiceProvider.ProviderParameter) as string; if (providerName != null) { AuthenticationElement authenticationElement = GetAuthenticationElement(); AuthServiceProvider provider = GetServiceProvider(providerName); if (provider != null) { url = provider.SuccessUrl; } } } if (string.IsNullOrEmpty(url)) { url = AuthServiceProvider.GetAbsoluteApplicationPath(); } url = HttpUtility.UrlDecode(url); context.Response.Redirect(url, false); }
/// <summary> /// Initialises a new instance of the <see cref="WebTestSettingsElementTest"/> class. /// </summary> /// <param name="fixture"><see cref="WebTestSettingsElementFixture"/> instance.</param> public WebTestSettingsElementTest(WebTestSettingsElementFixture fixture) { this._auth = fixture.WebTestSettingsElement.Authentication; this._insights = fixture.WebTestSettingsElement.ApplicationInsight; this._webTests = fixture.WebTestSettingsElement.WebTests.OfType <WebTestElement>().ToList(); }
public static string ToFormRequest <T>(this AuthenticationElement authentication) where T : AuthenticationElement { string str = ""; return(string.Join("&", JsonSerializer.Deserialize <Dictionary <string, string> >(JsonSerializer.Serialize(authentication as T)).Select(x => $"{HttpUtility.UrlEncode(x.Key)}={HttpUtility.UrlEncode(x.Value)}"))); }