Skip to content

Commit 6efbf74

Browse files
Make loopback handler more flexible
Make the loopback redirect HTTP handler more flexible by allowing the parameters for the callback to be customised. This removes the need to use subclasses for certain test scenarios.
1 parent 20a5b0a commit 6efbf74

File tree

5 files changed

+14
-49
lines changed

5 files changed

+14
-49
lines changed

test/AspNet.Security.OAuth.Providers.Tests/AspNet.Security.OAuth.Providers.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
66
<IsPackable>false</IsPackable>
77
<IsTestProject>true</IsTestProject>
8-
<NoWarn>$(NoWarn);CA1707</NoWarn>
8+
<NoWarn>$(NoWarn);CA1707;CA2227</NoWarn>
99
</PropertyGroup>
1010

1111
<ItemGroup>

test/AspNet.Security.OAuth.Providers.Tests/Infrastructure/LoopbackRedirectHandler.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ namespace AspNet.Security.OAuth.Infrastructure
1616
/// <summary>
1717
/// A delegating HTTP handler that loops back HTTP requests to external login providers to the local sign-in endpoint.
1818
/// </summary>
19-
internal class LoopbackRedirectHandler : DelegatingHandler
19+
public class LoopbackRedirectHandler : DelegatingHandler
2020
{
21+
public IDictionary<string, string> LoopbackParameters { get; set; } = new Dictionary<string, string>();
22+
2123
public HttpMethod RedirectMethod { get; set; } = HttpMethod.Get;
2224

2325
public IDictionary<string, string> RedirectParameters { get; set; } = new Dictionary<string, string>();
@@ -110,6 +112,14 @@ protected virtual Uri BuildLoopbackUri(HttpResponseMessage responseMessage)
110112
queryString.Add(OAuthStateKey, oauthState);
111113
}
112114

115+
if (LoopbackParameters?.Count > 0)
116+
{
117+
foreach (var parameter in LoopbackParameters)
118+
{
119+
queryString[parameter.Key] = parameter.Value;
120+
}
121+
}
122+
113123
builder.Query = queryString.ToString();
114124

115125
return builder.Uri;

test/AspNet.Security.OAuth.Providers.Tests/OAuthTests`1.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected WebApplicationFactory<Program> CreateTestServer(Action<IServiceCollect
126126
protected HttpClient CreateBackchannel(AuthenticationBuilder builder)
127127
=> builder.Services.BuildServiceProvider().GetRequiredService<IHttpClientFactory>().CreateClient();
128128

129-
public DelegatingHandler LoopbackRedirectHandler { get; set; }
129+
public LoopbackRedirectHandler LoopbackRedirectHandler { get; set; }
130130

131131
/// <summary>
132132
/// Run the ChannelAsync for authentication

test/AspNet.Security.OAuth.Providers.Tests/Shopify/ShopifyLoopbackRedirectHandler.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

test/AspNet.Security.OAuth.Providers.Tests/Shopify/ShopifyTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ public class ShopifyTests : OAuthTests<ShopifyAuthenticationOptions>
2222
public ShopifyTests(ITestOutputHelper outputHelper)
2323
{
2424
OutputHelper = outputHelper;
25-
26-
LoopbackRedirectHandler = new ShopifyLoopbackRedirectHandler()
27-
{
28-
RedirectUri = RedirectUri,
29-
ShopName = TestShopName
30-
};
25+
LoopbackRedirectHandler.LoopbackParameters.Add("shop", "apple.myshopify.com");
3126
}
3227

3328
public override string DefaultScheme => ShopifyAuthenticationDefaults.AuthenticationScheme;

0 commit comments

Comments
 (0)