diff --git a/samples/SampleApi1/SampleApi1.csproj b/samples/SampleApi1/SampleApi1.csproj
index 7d581dc..9a77263 100644
--- a/samples/SampleApi1/SampleApi1.csproj
+++ b/samples/SampleApi1/SampleApi1.csproj
@@ -1,27 +1,25 @@
- netcoreapp1.1
+ netcoreapp2.1
true
SampleApi1
Exe
SampleApi1
- 1.0.4
- $(PackageTargetFallback);dotnet5.6;portable-net45+win8
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/SampleApi2/SampleApi2.csproj b/samples/SampleApi2/SampleApi2.csproj
index 62264c5..c1b8a37 100644
--- a/samples/SampleApi2/SampleApi2.csproj
+++ b/samples/SampleApi2/SampleApi2.csproj
@@ -1,27 +1,25 @@
- netcoreapp1.1
+ netcoreapp2.1
true
SampleApi2
Exe
SampleApi2
- 1.0.4
- $(PackageTargetFallback);dotnet5.6;portable-net45+win8
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/SampleApiAuthentication/SampleApiAuthentication.csproj b/samples/SampleApiAuthentication/SampleApiAuthentication.csproj
index 1fdb59b..900855c 100644
--- a/samples/SampleApiAuthentication/SampleApiAuthentication.csproj
+++ b/samples/SampleApiAuthentication/SampleApiAuthentication.csproj
@@ -1,29 +1,27 @@
- netcoreapp1.1
+ netcoreapp2.1
true
SampleApiAuthentication
Exe
SampleApiAuthentication
- 1.0.4
- $(PackageTargetFallback);dotnet5.6;portable-net45+win8
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/SampleWeb/Authentication/CustomJwtDataFormat.cs b/samples/SampleWeb/Authentication/CustomJwtDataFormat.cs
index dc2624a..df2aa07 100644
--- a/samples/SampleWeb/Authentication/CustomJwtDataFormat.cs
+++ b/samples/SampleWeb/Authentication/CustomJwtDataFormat.cs
@@ -5,7 +5,7 @@
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
-using Microsoft.AspNetCore.Http.Authentication;
+//using Microsoft.AspNetCore.Http.Authentication;
using Microsoft.IdentityModel.Tokens;
namespace SampleWeb.Authentication
diff --git a/samples/SampleWeb/SampleWeb.csproj b/samples/SampleWeb/SampleWeb.csproj
index da5e1d1..fae1565 100644
--- a/samples/SampleWeb/SampleWeb.csproj
+++ b/samples/SampleWeb/SampleWeb.csproj
@@ -1,24 +1,24 @@
- netcoreapp1.1
+ netcoreapp2.1
true
SampleWeb
Exe
SampleWeb
- 1.0.4
- $(PackageTargetFallback);dotnet5.6;portable-net45+win8
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/SampleWeb/Startup.cs b/samples/SampleWeb/Startup.cs
index 214f78b..c7fa530 100644
--- a/samples/SampleWeb/Startup.cs
+++ b/samples/SampleWeb/Startup.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
+using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
@@ -10,27 +11,62 @@
using SampleWeb.Authentication;
using SharpReverseProxy;
-namespace SampleWeb {
- public class Startup {
+namespace SampleWeb
+{
+ public class Startup
+ {
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
- public void ConfigureServices(IServiceCollection services) {
- services.AddAuthentication();
+ public void ConfigureServices(IServiceCollection services)
+ {
+ var secretKey = "foofoofoofoofoobar";
+ var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey));
+
+ var tokenValidationParameters = new TokenValidationParameters
+ {
+ ValidateIssuerSigningKey = true,
+ IssuerSigningKey = signingKey,
+ ValidateIssuer = true,
+ ValidIssuer = "someIssuer",
+ ValidateAudience = true,
+ ValidAudience = "Browser",
+ ValidateLifetime = true,
+ ClockSkew = TimeSpan.Zero
+ };
+ services.AddAuthentication(options =>
+ {
+ options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
+ options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
+ })
+ .AddJwtBearer(c =>
+ {
+ c.TokenValidationParameters = tokenValidationParameters;
+ })
+ .AddCookie(c =>
+ {
+ c.Cookie.Name = "access_token";
+ c.TicketDataFormat = new CustomJwtDataFormat(
+ SecurityAlgorithms.HmacSha256,
+ tokenValidationParameters);
+ });
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) {
+ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
+ {
loggerFactory.AddConsole();
loggerFactory.AddDebug(LogLevel.Debug);
var logger = loggerFactory.CreateLogger("Middleware");
- if (env.IsDevelopment()) {
+ if (env.IsDevelopment())
+ {
app.UseDeveloperExceptionPage();
}
ConfigureAuthentication(app);
- var proxyOptions = new ProxyOptions {
+ var proxyOptions = new ProxyOptions
+ {
ProxyRules = new List {
new ProxyRule {
Matcher = uri => uri.AbsoluteUri.Contains("/api1"),
@@ -63,9 +99,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
}
}
},
- Reporter = r => {
+ Reporter = r =>
+ {
logger.LogDebug($"Proxy: {r.ProxyStatus} Url: {r.OriginalUri} Time: {r.Elapsed}");
- if (r.ProxyStatus == ProxyStatus.Proxied) {
+ if (r.ProxyStatus == ProxyStatus.Proxied)
+ {
logger.LogDebug($" New Url: {r.ProxiedUri.AbsoluteUri} Status: {r.HttpStatusCode}");
}
},
@@ -74,41 +112,15 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
app.UseProxy(proxyOptions);
- app.Run(async (context) => {
+ app.Run(async (context) =>
+ {
await context.Response.WriteAsync("Hello World!");
});
}
- private static void ConfigureAuthentication(IApplicationBuilder app) {
- var secretKey = "foofoofoofoofoobar";
- var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey));
-
- var tokenValidationParameters = new TokenValidationParameters {
- ValidateIssuerSigningKey = true,
- IssuerSigningKey = signingKey,
- ValidateIssuer = true,
- ValidIssuer = "someIssuer",
- ValidateAudience = true,
- ValidAudience = "Browser",
- ValidateLifetime = true,
- ClockSkew = TimeSpan.Zero
- };
+ private static void ConfigureAuthentication(IApplicationBuilder app)
+ {
- app.UseJwtBearerAuthentication(new JwtBearerOptions {
- AutomaticAuthenticate = true,
- AutomaticChallenge = true,
- TokenValidationParameters = tokenValidationParameters
- });
-
- app.UseCookieAuthentication(new CookieAuthenticationOptions {
- AutomaticAuthenticate = true,
- AutomaticChallenge = true,
- AuthenticationScheme = "Cookie",
- CookieName = "access_token",
- TicketDataFormat = new CustomJwtDataFormat(
- SecurityAlgorithms.HmacSha256,
- tokenValidationParameters)
- });
}
}
}
diff --git a/src/SharpReverseProxy/SharpReverseProxy.csproj b/src/SharpReverseProxy/SharpReverseProxy.csproj
index e38f238..c9701ea 100644
--- a/src/SharpReverseProxy/SharpReverseProxy.csproj
+++ b/src/SharpReverseProxy/SharpReverseProxy.csproj
@@ -4,13 +4,12 @@
Powerful Reverse Proxy written as OWIN Middleware. Perfect for asp.net, web.api, microservices, etc.
1.3.0
Andre Carlucci
- netstandard1.6
+ netstandard2.0
SharpReverseProxy
SharpReverseProxy
aspnetcore;microservices;proxy;apigateway
git
https://github.com/SharpTools/SharpReverseProxy
- $(PackageTargetFallback);dnxcore50
false
false
false
@@ -20,8 +19,8 @@
-
-
+
+
diff --git a/test/SharpReverseProxy.Tests/HttpContextFakes/HeaderDictionaryFake.cs b/test/SharpReverseProxy.Tests/HttpContextFakes/HeaderDictionaryFake.cs
index c6708df..bc339c3 100644
--- a/test/SharpReverseProxy.Tests/HttpContextFakes/HeaderDictionaryFake.cs
+++ b/test/SharpReverseProxy.Tests/HttpContextFakes/HeaderDictionaryFake.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Primitives;
+using System.Linq;
namespace SharpReverseProxy.Tests.HttpContextFakes {
public class HeaderDictionaryFake : IHeaderDictionary {
@@ -27,6 +28,10 @@ public StringValues this[string key] {
public int Count => _headers.Count;
+ public long? ContentLength { get => _headers["Content-Length"].ToArray().Select(s => (long?)long.Parse(s)).FirstOrDefault();
+ set => _headers["Content-Length"] = value.Value.ToString();
+ }
+
public void Add(string key, StringValues value) {
if(_parentResponse.HasStarted) {
ThrowReponseAlreadyStartedException();
diff --git a/test/SharpReverseProxy.Tests/SharpReverseProxy.Tests.csproj b/test/SharpReverseProxy.Tests/SharpReverseProxy.Tests.csproj
index 11c7f63..ed50f38 100644
--- a/test/SharpReverseProxy.Tests/SharpReverseProxy.Tests.csproj
+++ b/test/SharpReverseProxy.Tests/SharpReverseProxy.Tests.csproj
@@ -1,10 +1,9 @@
-
+
- netcoreapp1.1
+ netcoreapp2.1
SharpReverseProxy.Tests
SharpReverseProxy.Tests
true
- $(PackageTargetFallback);netcoreapp1.0;portable-net45+win8
false
false
false
@@ -16,12 +15,12 @@
-
-
-
-
-
-
+
+
+
+
+
+