public async Task ShouldSetBearerToken() { // Arrange var tokenStore = A.Fake <ITokenStore>(); A.CallTo(() => tokenStore.GetToken("tokenid")).Returns(new TokenCredential { AccessToken = "access_token" }); var handler = new OAuthHttpClientHandler("tokenid", tokenStore, null) { InnerHandler = new TestHandler((r, c) => TestHandler.ReturnOk()) }; var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "http://test/"); var client = new HttpClient(handler); // Act await client.SendAsync(httpRequestMessage); // Assert httpRequestMessage.Headers.Authorization.Should().Be(new AuthenticationHeaderValue("Bearer", "access_token")); }
public TestingOAuth2Client(string accessToken, string refreshToken) : base(new Uri("http://test/"), new TestHandler((r, c) => TestHandler.ReturnOk(new StringContent(JsonConvert.SerializeObject(new { access_token = accessToken, refresh_token = refreshToken }))))) { }
public TestingOAuth2Client(string error) : base(new Uri("http://test/"), new TestHandler((r, c) => TestHandler.ReturnUnauthorized(new StringContent(JsonConvert.SerializeObject(new { error }))))) { }
public void ShouldNotRefreshTokenWhenUnauthorized() { ShouldNotRefreshToken((r, c) => TestHandler.ReturnUnauthorized()); }
public async Task ShouldRefreshTokenWhenNonAuthoritativeInformation() { await ShouldRefreshToken((r, c) => TestHandler.ReturnNonAuthoritativeInformation()); }
public async Task ShouldRefreshTokenWhenUnauthorized() { await ShouldRefreshToken((r, c) => TestHandler.ReturnUnauthorized()); }
public void ShouldNotRefreshTokenWhenNonAuthoritativeInformation() { ShouldNotRefreshToken((r, c) => TestHandler.ReturnNonAuthoritativeInformation()); }