Skip to content

Commit e97039d

Browse files
committed
Removed authentication provider from base client, resolves breaking changes
1 parent 73705ce commit e97039d

File tree

13 files changed

+46
-85
lines changed

13 files changed

+46
-85
lines changed

src/Microsoft.Graph.Core/Requests/AsyncMonitor.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ public async Task<T> PollForOperationCompletionAsync(IProgress<AsyncOperationSta
4444
{
4545
using (var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, this.monitorUrl))
4646
{
47-
await this.client.AuthenticationProvider.AuthenticateRequestAsync(httpRequestMessage).ConfigureAwait(false);
48-
4947
using (var responseMessage = await this.client.HttpProvider.SendAsync(httpRequestMessage).ConfigureAwait(false))
5048
{
5149
// The monitor service will return an Accepted status for any monitor operation that hasn't completed.

src/Microsoft.Graph.Core/Requests/BaseClient.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,9 @@ public BaseClient(
2525
IHttpProvider httpProvider = null)
2626
{
2727
this.BaseUrl = baseUrl;
28-
this.AuthenticationProvider = authenticationProvider;
29-
this.HttpProvider = httpProvider ?? new HttpProvider(this.AuthenticationProvider, new Serializer());
28+
this.HttpProvider = httpProvider ?? new HttpProvider(authenticationProvider, new Serializer());
3029
}
3130

32-
/// <summary>
33-
/// Gets the <see cref="IAuthenticationProvider"/> for authenticating requests.
34-
/// </summary>
35-
public IAuthenticationProvider AuthenticationProvider { get; set; }
36-
3731
/// <summary>
3832
/// Gets or sets the base URL for requests of the client.
3933
/// </summary>

src/Microsoft.Graph.Core/Requests/BaseRequest.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,6 @@ public async Task<HttpResponseMessage> SendMultiPartRequestAsync(
189189
});
190190
}
191191

192-
if (this.Client.AuthenticationProvider == null)
193-
{
194-
throw new ServiceException(
195-
new Error
196-
{
197-
Code = ErrorConstants.Codes.InvalidRequest,
198-
Message = ErrorConstants.Messages.AuthenticationProviderMissing,
199-
});
200-
}
201-
202192
if (multipartContent != null)
203193
{
204194
using (var request = this.GetHttpRequestMessage())
@@ -236,16 +226,6 @@ public async Task<HttpResponseMessage> SendRequestAsync(
236226
});
237227
}
238228

239-
if (this.Client.AuthenticationProvider == null)
240-
{
241-
throw new ServiceException(
242-
new Error
243-
{
244-
Code = ErrorConstants.Codes.InvalidRequest,
245-
Message = ErrorConstants.Messages.AuthenticationProviderMissing,
246-
});
247-
}
248-
249229
using (var request = this.GetHttpRequestMessage())
250230
{
251231
if (serializableObject != null)

src/Microsoft.Graph.Core/Requests/HttpProvider.cs

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public class HttpProvider : IHttpProvider
2424

2525
internal HttpMessageHandler httpMessageHandler;
2626

27+
/// <summary>
28+
/// Constructs a new <see cref="HttpProvider"/>.
29+
/// </summary>
30+
/// <param name="serializer">A serializer for serializing and deserializing JSON objects.</param>
31+
public HttpProvider(ISerializer serializer = null)
32+
: this(null, (HttpMessageHandler)null, true, serializer)
33+
{
34+
}
35+
2736
/// <summary>
2837
/// Constructs a new <see cref="HttpProvider"/>.
2938
/// </summary>
@@ -39,15 +48,14 @@ public HttpProvider(IAuthenticationProvider authenticationProvider, ISerializer
3948
/// </summary>
4049
/// <param name="httpClientHandler">An HTTP client handler to pass to the <see cref="HttpClient"/> for sending requests.</param>
4150
/// <param name="disposeHandler">Whether or not to dispose the client handler on Dispose().</param>
42-
/// <param name="authenticationProvider">The <see cref="IAuthenticationProvider"/> for authenticating request messages.</param>
4351
/// <param name="serializer">A serializer for serializing and deserializing JSON objects.</param>
4452
/// <remarks>
4553
/// By default, HttpProvider disables automatic redirects and handles redirects to preserve authentication headers. If providing
4654
/// an <see cref="HttpClientHandler"/> to the constructor and enabling automatic redirects this could cause issues with authentication
4755
/// over the redirect.
4856
/// </remarks>
49-
public HttpProvider(IAuthenticationProvider authenticationProvider, HttpClientHandler httpClientHandler, bool disposeHandler, ISerializer serializer = null)
50-
: this(authenticationProvider, (HttpMessageHandler)httpClientHandler, disposeHandler, serializer)
57+
public HttpProvider(HttpClientHandler httpClientHandler, bool disposeHandler, ISerializer serializer = null)
58+
: this(null, (HttpMessageHandler)httpClientHandler, disposeHandler, serializer)
5159
{
5260
}
5361

@@ -74,6 +82,35 @@ public HttpProvider(IAuthenticationProvider authenticationProvider, HttpMessageH
7482
this.httpClient = GraphClientFactory.CreateClient(this.httpMessageHandler, handlers);
7583
}
7684

85+
/// <summary>
86+
/// Gets or sets the overall request timeout.
87+
/// </summary>
88+
public TimeSpan OverallTimeout
89+
{
90+
get
91+
{
92+
return this.httpClient.Timeout;
93+
}
94+
95+
set
96+
{
97+
try
98+
{
99+
this.httpClient.Timeout = value;
100+
}
101+
catch (InvalidOperationException exception)
102+
{
103+
throw new ServiceException(
104+
new Error
105+
{
106+
Code = ErrorConstants.Codes.NotAllowed,
107+
Message = ErrorConstants.Messages.OverallTimeoutCannotBeSet,
108+
},
109+
exception);
110+
}
111+
}
112+
}
113+
77114
/// <summary>
78115
/// Gets a serializer for serializing and deserializing JSON objects.
79116
/// </summary>

src/Microsoft.Graph.Core/Requests/IBaseClient.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ namespace Microsoft.Graph
99
/// </summary>
1010
public interface IBaseClient
1111
{
12-
/// <summary>
13-
/// Gets the <see cref="IAuthenticationProvider"/> for authenticating HTTP requests.
14-
/// </summary>
15-
IAuthenticationProvider AuthenticationProvider { get; }
16-
1712
/// <summary>
1813
/// Gets the base URL for requests of the client.
1914
/// </summary>

src/Microsoft.Graph.Core/Requests/IHttpProvider.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public interface IHttpProvider : IDisposable
1919
/// </summary>
2020
ISerializer Serializer { get; }
2121

22+
/// <summary>
23+
/// Gets or sets the timeout interval. The default value is 100 seconds.
24+
/// </summary>
25+
TimeSpan OverallTimeout { get; set; }
26+
2227
/// <summary>
2328
/// Sends the request.
2429
/// </summary>

src/Microsoft.Graph/Requests/UploadChunkRequest.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ private async Task<HttpResponseMessage> SendRequestAsync(
153153
throw new ArgumentNullException(nameof(this.RequestUrl), "Session Upload URL cannot be null or empty.");
154154
}
155155

156-
if (this.Client.AuthenticationProvider == null)
157-
{
158-
throw new ArgumentNullException(nameof(this.Client.AuthenticationProvider), "Client.AuthenticationProvider must not be null.");
159-
}
160-
161156
using (var request = this.GetHttpRequestMessage())
162157
{
163158
request.Content = new StreamContent(stream);

tests/Microsoft.Graph.Core.Test/Requests/AsyncMonitorTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public void Setup()
4343

4444
this.client = new Mock<IBaseClient>(MockBehavior.Strict);
4545
this.client.SetupAllProperties();
46-
this.client.SetupGet(client => client.AuthenticationProvider).Returns(this.authenticationProvider.Object);
4746
this.client.SetupGet(client => client.HttpProvider).Returns(this.httpProvider.Object);
4847

4948
this.progress = new MockProgress();
@@ -94,16 +93,6 @@ public async Task PollForOperationCompletionAsync_OperationCompleted()
9493
Assert.IsTrue(called, "Progress not called");
9594
Assert.IsNotNull(item, "No item returned.");
9695
Assert.AreEqual("id", item.Id, "Unexpected item returned.");
97-
98-
this.authenticationProvider.Verify(
99-
provider => provider.AuthenticateRequestAsync(
100-
It.Is<HttpRequestMessage>(message => message.RequestUri.ToString().Equals(AsyncMonitorTests.monitorUrl))),
101-
Times.Once);
102-
103-
this.authenticationProvider.Verify(
104-
provider => provider.AuthenticateRequestAsync(
105-
It.Is<HttpRequestMessage>(message => message.RequestUri.ToString().Equals(AsyncMonitorTests.itemUrl))),
106-
Times.Once);
10796
}
10897
}
10998

tests/Microsoft.Graph.DotnetCore.Core.Test/Requests/AsyncMonitorTests.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public AsyncMonitorTests()
4242

4343
this.client = new Mock<IBaseClient>(MockBehavior.Strict);
4444
this.client.SetupAllProperties();
45-
this.client.SetupGet(client => client.AuthenticationProvider).Returns(this.authenticationProvider.Object);
4645
this.client.SetupGet(client => client.HttpProvider).Returns(this.httpProvider.Object);
4746

4847
this.progress = new MockProgress();
@@ -92,16 +91,6 @@ public async Task PollForOperationCompletionAsync_OperationCompleted()
9291
Assert.True(called);
9392
Assert.NotNull(item);
9493
Assert.Equal("id", item.Id);
95-
96-
this.authenticationProvider.Verify(
97-
provider => provider.AuthenticateRequestAsync(
98-
It.Is<HttpRequestMessage>(message => message.RequestUri.ToString().Equals(AsyncMonitorTests.monitorUrl))),
99-
Times.Once);
100-
101-
this.authenticationProvider.Verify(
102-
provider => provider.AuthenticateRequestAsync(
103-
It.Is<HttpRequestMessage>(message => message.RequestUri.ToString().Equals(AsyncMonitorTests.itemUrl))),
104-
Times.Once);
10594
}
10695
}
10796

tests/Microsoft.Graph.Test/Requests/Functional/ExcelTests.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,6 @@ public async Task ExcelGetImageFromChart()
502502

503503
HttpRequestMessage hrm = new HttpRequestMessage(HttpMethod.Get, urlToGetImageFromChart);
504504

505-
// Authenticate (add access token) our HttpRequestMessage
506-
await graphClient.AuthenticationProvider.AuthenticateRequestAsync(hrm);
507-
508505
// Send the request and get the response.
509506
HttpResponseMessage response = await graphClient.HttpProvider.SendAsync(hrm);
510507

0 commit comments

Comments
 (0)