/// <summary> /// Adds an Authentication header to the default request headers of the <see cref="HttpClient"/>. /// Uses the provided claims and "TestServer" as authentication scheme. /// </summary> /// <param name="httpClient">The httpClient instance</param> /// <param name="claims">The claims collection that represents the user identity</param> /// <returns></returns> public static HttpClient WithDefaultIdentity(this HttpClient httpClient, IEnumerable <Claim> claims) { var headerName = AuthenticationHeaderHelper.GetHeaderName(TestServerDefaults.AuthenticationScheme); httpClient.DefaultRequestHeaders.Add( name: headerName, value: $"{TestServerDefaults.AuthenticationScheme} {DefautClaimsEncoder.Encode(claims)}"); return(httpClient); }
/// <summary> /// Adds an Authentication header to the <see cref="RequestBuilder"/> with the provided claims using /// "TestServer" as authentication scheme. /// </summary> /// <param name="requestBuilder">The requestBuilder instance</param> /// <param name="claims">The claims collection that represents the user identity</param> /// <returns></returns> public static RequestBuilder WithIdentity(this RequestBuilder requestBuilder, IEnumerable <Claim> claims) { var headerName = AuthenticationHeaderHelper.GetHeaderName(TestServerAuthenticationDefaults.AuthenticationScheme); requestBuilder.AddHeader( headerName, $"{TestServerAuthenticationDefaults.AuthenticationScheme} {DefautClaimsEncoder.Encode(claims)}"); return(requestBuilder); }
/// <summary> /// Get the header string for the provided claims /// </summary> /// <param name="httpClient">The httpClient instance</param> /// <param name="claims">The claims collection that represents the user identity</param> /// <param name="scheme">The authentication scheme</param> /// <returns></returns> public static string GetHeaderForIdentity(this HttpClient httpClient, IEnumerable <Claim> claims, string scheme) { if (string.IsNullOrWhiteSpace(scheme)) { throw new ArgumentNullException(nameof(scheme)); } var headerName = AuthenticationHeaderHelper.GetHeaderName(scheme); var header = new NameValueHeaderValue( headerName, $"{TestServerDefaults.AuthenticationScheme} {DefautClaimsEncoder.Encode(claims)}"); return(header.ToString()); }
/// <summary> /// Adds an Authentication header to the <see cref="RequestBuilder"/> with the provided claims /// and authentication scheme. /// </summary> /// <param name="requestBuilder">The requestBuilder instance</param> /// <param name="claims">The claims collection that represents the user identity</param> /// <param name="scheme">The authentication scheme</param> /// <returns></returns> public static RequestBuilder WithIdentity(this RequestBuilder requestBuilder, IEnumerable <Claim> claims, string scheme) { if (string.IsNullOrWhiteSpace(scheme)) { throw new ArgumentNullException(nameof(scheme)); } var headerName = AuthenticationHeaderHelper.GetHeaderName(scheme); requestBuilder.AddHeader( headerName, $"{scheme} {DefautClaimsEncoder.Encode(claims)}"); return(requestBuilder); }
/// <summary> /// Adds an Authentication header to the default request headers of the <see cref="HttpClient"/>. /// Uses the provided claims and authentication scheme. /// </summary> /// <param name="httpClient">The httpClient instance</param> /// <param name="claims">The claims collection that represents the user identity</param> /// <param name="scheme">The authentication scheme</param> /// <returns></returns> public static HttpClient WithDefaultIdentity(this HttpClient httpClient, IEnumerable <Claim> claims, string scheme) { if (string.IsNullOrWhiteSpace(scheme)) { throw new ArgumentNullException(nameof(scheme)); } var headerName = AuthenticationHeaderHelper.GetHeaderName(scheme); httpClient.DefaultRequestHeaders.Add( name: headerName, value: $"{scheme} {DefautClaimsEncoder.Encode(claims)}"); return(httpClient); }