Browse Source

proxy headers

jkotalik/newVotingSample
glennc 6 years ago
parent
commit
44c9e8ffc4
  1. 35
      samples/voting/IdentityServer/Startup.cs
  2. 2
      samples/voting/results/Pages/LoginDisplay.razor
  3. 10
      samples/voting/results/Startup.cs
  4. 8
      samples/voting/tye.yaml

35
samples/voting/IdentityServer/Startup.cs

@ -45,7 +45,6 @@ namespace IdentityServer
options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true;
options.IssuerUri = $"{publicIp}/identityserver";
// see https://identityserver4.readthedocs.io/en/latest/topics/resources.html
options.EmitStaticAudienceClaim = true;
})
@ -91,14 +90,14 @@ namespace IdentityServer
app.UseStaticFiles();
app.UseForwardedHeaders(new ForwardedHeadersOptions()
var khOptions = new ForwardedHeadersOptions()
{
ForwardedHeaders = ForwardedHeaders.All
});
var publicIp = Configuration["public-ip"];
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
};
khOptions.KnownProxies.Clear();
khOptions.KnownNetworks.Clear();
app.UseMiddleware<PublicFacingUrlMiddleware>($"{publicIp}");
app.UseForwardedHeaders(khOptions);
app.UseRouting();
app.UseIdentityServer();
@ -108,27 +107,5 @@ namespace IdentityServer
endpoints.MapDefaultControllerRoute();
});
}
public class PublicFacingUrlMiddleware
{
private readonly RequestDelegate _next;
private readonly string _publicFacingUri;
public PublicFacingUrlMiddleware(RequestDelegate next, string publicFacingUri)
{
_publicFacingUri = publicFacingUri;
_next = next;
}
public async Task Invoke(HttpContext context)
{
var request = context.Request;
context.SetIdentityServerOrigin(_publicFacingUri);
// context.SetIdentityServerBasePath(request.PathBase.Value.TrimEnd('/'));
await _next(context);
}
}
}
}

2
samples/voting/results/Pages/LoginDisplay.razor

@ -1,6 +1,6 @@
<AuthorizeView>
<Authorized>
<form method="post" action="/logout">
<form method="post" action="logout">
<button type="submit" class="btn btn-primary">Log out</button>
</form>
</Authorized>

10
samples/voting/results/Startup.cs

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@ -65,6 +66,15 @@ namespace Results
app.UsePathBase("/results");
var khOptions = new ForwardedHeadersOptions()
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
};
khOptions.KnownProxies.Clear();
khOptions.KnownNetworks.Clear();
app.UseForwardedHeaders(khOptions);
app.UseStaticFiles();
app.UseRouting();

8
samples/voting/tye.yaml

@ -24,8 +24,8 @@ services:
protocol: http
env:
- name: public-ip
value: http://52.159.20.103
# value: http://localhost:8080
#value: http://52.159.20.103
value: http://localhost:8080
- name: identityserver
project: IdentityServer/IdentityServer.csproj
bindings:
@ -33,8 +33,8 @@ services:
protocol: http
env:
- name: public-ip
value: http://52.159.20.103
# value: http://localhost:8080
#value: http://52.159.20.103
value: http://localhost:8080
ingress:
- name: ingress
bindings:

Loading…
Cancel
Save