public void TestJwtOrKeyWhenJwtAvailable() { HttpClient httpClient = new HttpClient(); RequestContext requestContext = new RequestContext(); var testOptions = new TestOptions(); testOptions.ApiKey = new ApiKeyParameters { Value = "12312321" }; testOptions.Token = new JwtTokenParameters { Audience = "local", Issuer = "local", Key = "8768747658765975758758758746" }; var apiOperationBuilder = new ApiOperationBuilder <TestOptions> ( httpClient, requestContext, testOptions ); var claimsIdentity = new ClaimsIdentity("testauth"); claimsIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "111")); requestContext.Set(new ClaimsPrincipal(claimsIdentity)); apiOperationBuilder.JwtOrKey(testOptions.ApiKey); Assert.IsTrue(httpClient.DefaultRequestHeaders.Authorization.Scheme.Contains("Bearer")); Assert.IsFalse(httpClient.DefaultRequestHeaders.Contains(testOptions.ApiKey.Name)); }
public void TestJwtOrKeyWhenJwtUnAvailable() { HttpClient httpClient = new HttpClient(); RequestContext requestContext = new RequestContext(); var testOptions = new TestOptions(); testOptions.ApiKey = new ApiKeyParameters { Value = "12312321" }; testOptions.Token = new JwtTokenParameters { Audience = "local", Issuer = "local", Key = "8768747658765975758758758746" }; var apiOperationBuilder = new ApiOperationBuilder <TestOptions> ( httpClient, requestContext, testOptions ); apiOperationBuilder.JwtOrKey(testOptions.ApiKey); Assert.IsTrue(httpClient.DefaultRequestHeaders.Contains(testOptions.ApiKey.Name)); Assert.IsNull(httpClient.DefaultRequestHeaders.Authorization); }