Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public AuthorizationHeaderProviderOptions(AuthorizationHeaderProviderOptions oth
AcquireTokenOptions = other.AcquireTokenOptions.Clone();
HttpMethod = other.HttpMethod.ToString();
CustomizeHttpRequestMessage = other.CustomizeHttpRequestMessage;
OnBeforeAuthHeaderCreation = other.OnBeforeAuthHeaderCreation;
OnAfterAuthHeaderCreation = other.OnAfterAuthHeaderCreation;
ProtocolScheme = other.ProtocolScheme;
RequestAppToken = other.RequestAppToken;
}
Expand Down Expand Up @@ -75,6 +77,28 @@ public string HttpMethod
/// </summary>
public Action<HttpRequestMessage>? CustomizeHttpRequestMessage { get; set; }

/// <summary>
/// Provides an opportunity for the caller app to customize the <see cref="HttpRequestMessage"/> <b>before</b>
/// the authorization header is created. At this point the <c>Authorization</c> header is not yet present.
/// Use this to shape the request that a request-binding protocol signs — for example a SignedHttpRequest
/// (SHR) that binds the query, headers, or body (the <c>q</c>/<c>h</c>/<c>b</c> claims) to the token — so the
/// signature covers the finalized request. To observe or adjust the request <b>after</b> the header has been
/// created, use <see cref="OnAfterAuthHeaderCreation"/> (or <see cref="CustomizeHttpRequestMessage"/>).
/// </summary>
public Action<HttpRequestMessage>? OnBeforeAuthHeaderCreation { get; set; }

/// <summary>
/// Provides an opportunity for the caller app to customize the <see cref="HttpRequestMessage"/> <b>after</b>
/// the authorization header (including the <c>Authorization</c> header) has been set, and just before the
/// message is sent — the point at which the finalized request can be read or adjusted. Provided for naming
/// symmetry with <see cref="OnBeforeAuthHeaderCreation"/>; it shares this timing with the pre-existing
Comment thread
neha-bhargava marked this conversation as resolved.
/// <see cref="CustomizeHttpRequestMessage"/>, which continues to be invoked for backwards compatibility. When
/// both are set they run at the same point, so callers should not depend on their relative order. Do
/// not modify material bound by a request-binding protocol (SHR <c>q</c>/<c>h</c>/<c>b</c>) here, since it
/// runs after signing; use <see cref="OnBeforeAuthHeaderCreation"/> for that.
/// </summary>
public Action<HttpRequestMessage>? OnAfterAuthHeaderCreation { get; set; }

/// <summary>
/// Options related to token acquisition.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#nullable enable
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.set -> void
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.set -> void
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#nullable enable
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.set -> void
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.set -> void
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#nullable enable
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.set -> void
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.set -> void
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#nullable enable
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.set -> void
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.set -> void
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#nullable enable
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.set -> void
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.set -> void
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
#nullable enable
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnAfterAuthHeaderCreation.set -> void
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.get -> System.Action<System.Net.Http.HttpRequestMessage!>?
Microsoft.Identity.Abstractions.AuthorizationHeaderProviderOptions.OnBeforeAuthHeaderCreation.set -> void
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public void CloneClonesAllProperties()
},
BaseUrl = "https://apitocall.domain.com",
CustomizeHttpRequestMessage = message => message.Headers.Add("x-sku", "sku-value"),
OnBeforeAuthHeaderCreation = message => message.Headers.Add("x-before", "before-value"),
OnAfterAuthHeaderCreation = message => message.Headers.Add("x-after", "after-value"),
Deserializer = value => value,
Serializer = input => (input != null) ? new StringContent(input.ToString()!, Encoding.UTF8
#if !NETFRAMEWORK
Expand Down Expand Up @@ -75,6 +77,8 @@ public void CloneClonesAllProperties()
Assert.Equal(downstreamApiOptions.Scopes, downstreamApiClone.Scopes!);
Assert.Equal(downstreamApiOptions.BaseUrl, downstreamApiClone.BaseUrl);
Assert.Equal(downstreamApiOptions.CustomizeHttpRequestMessage, downstreamApiClone.CustomizeHttpRequestMessage);
Assert.Equal(downstreamApiOptions.OnBeforeAuthHeaderCreation, downstreamApiClone.OnBeforeAuthHeaderCreation);
Assert.Equal(downstreamApiOptions.OnAfterAuthHeaderCreation, downstreamApiClone.OnAfterAuthHeaderCreation);
Assert.Equal(downstreamApiOptions.Deserializer, downstreamApiClone.Deserializer);
Assert.Equal(downstreamApiOptions.Serializer, downstreamApiClone.Serializer);
Assert.Equal(downstreamApiOptions.HttpMethod, downstreamApiClone.HttpMethod);
Expand Down Expand Up @@ -102,7 +106,7 @@ public void CloneClonesAllProperties()
Assert.Equal(downstreamApiOptions.ExtraQueryParameters, downstreamApiClone.ExtraQueryParameters);

// If this fails, think of also adding a line to test the new property
Assert.Equal(14, typeof(DownstreamApiOptions).GetProperties().Length);
Assert.Equal(16, typeof(DownstreamApiOptions).GetProperties().Length);
Assert.Equal(15, typeof(AcquireTokenOptions).GetProperties().Length);

DownstreamApiOptionsReadOnlyHttpMethod options = new DownstreamApiOptionsReadOnlyHttpMethod(downstreamApiOptions, HttpMethod.Delete.ToString());
Expand Down
Loading