Browse Source

Still making progress

jkotalik/newVotingSample
Justin Kotalik 6 years ago
parent
commit
0d34b84c9e
  1. 44
      samples/voting/IdentityServer/Startup.cs
  2. 1
      samples/voting/results/Pages/_Host.cshtml
  3. 10
      samples/voting/results/Startup.cs
  4. 6
      samples/voting/results/appsettings.json
  5. 8
      samples/voting/tye.yaml

44
samples/voting/IdentityServer/Startup.cs

@ -16,6 +16,10 @@ using IdentityServer4.Services;
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;
using IdentityServer4.Extensions;
using Microsoft.AspNetCore.HttpOverrides;
namespace IdentityServer namespace IdentityServer
{ {
@ -41,7 +45,7 @@ namespace IdentityServer
options.Events.RaiseInformationEvents = true; options.Events.RaiseInformationEvents = true;
options.Events.RaiseFailureEvents = true; options.Events.RaiseFailureEvents = true;
options.Events.RaiseSuccessEvents = true; options.Events.RaiseSuccessEvents = true;
// options.IssuerUri = $"{publicIp}/identityserver"; options.IssuerUri = $"{publicIp}/identityserver";
// see https://identityserver4.readthedocs.io/en/latest/topics/resources.html // see https://identityserver4.readthedocs.io/en/latest/topics/resources.html
options.EmitStaticAudienceClaim = true; options.EmitStaticAudienceClaim = true;
}) })
@ -63,10 +67,9 @@ namespace IdentityServer
AllowedGrantTypes = GrantTypes.Code, AllowedGrantTypes = GrantTypes.Code,
// These currently break when ingress is in place for redirect. // These currently break when ingress is in place for redirect.
RedirectUris = { $"{publicIp}/results/signin-oidc"}, // $"{Configuration.GetServiceUri("results:http")}results/signin-oidc", $"{Configuration.GetServiceUri("results:http")}signin-oidc"
RedirectUris = { $"{publicIp}/results/signin-oidc", $"{Configuration.GetServiceUri("results:http")}results/signin-oidc", $"{Configuration.GetServiceUri("results:http")}signin-oidc" },
FrontChannelLogoutUri = $"{publicIp}/results/signout-oidc", FrontChannelLogoutUri = $"{publicIp}/results/signout-oidc",
PostLogoutRedirectUris = { $"{publicIp}/results/signout-callback-oidc", $"{Configuration.GetServiceUri("results:http")}results/signout-callback-oidc", $"{Configuration.GetServiceUri("results:http")}signout-callback-oidc" }, PostLogoutRedirectUris = { $"{publicIp}/results/signout-callback-oidc" }, // , $"{Configuration.GetServiceUri("results:http")}results/signout-callback-oidc", $"{Configuration.GetServiceUri("results:http")}signout-callback-oidc"
AllowOfflineAccess = true, AllowOfflineAccess = true,
AllowedScopes = new List<string>{IdentityServerConstants.StandardScopes.OpenId,IdentityServerConstants.StandardScopes.Profile, "scope"} AllowedScopes = new List<string>{IdentityServerConstants.StandardScopes.OpenId,IdentityServerConstants.StandardScopes.Profile, "scope"}
@ -83,9 +86,20 @@ namespace IdentityServer
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
// app.UseForwardedHeaders();
app.UsePathBase("/identityserver");
app.UseStaticFiles(); app.UseStaticFiles();
app.UseForwardedHeaders(new ForwardedHeadersOptions()
{
ForwardedHeaders = ForwardedHeaders.All
});
var publicIp = Configuration["public-ip"];
app.UseMiddleware<PublicFacingUrlMiddleware>($"{publicIp}");
app.UseRouting(); app.UseRouting();
app.UseIdentityServer(); app.UseIdentityServer();
app.UseAuthorization(); app.UseAuthorization();
@ -94,5 +108,27 @@ namespace IdentityServer
endpoints.MapDefaultControllerRoute(); 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);
}
}
} }
} }

1
samples/voting/results/Pages/_Host.cshtml

@ -14,7 +14,6 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Results</title> <title>Results</title>
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" /> <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" /> <link href="css/site.css" rel="stylesheet" />
<link rel="stylesheet" href="_content/ChartJs.Blazor/ChartJSBlazor.css" /> <link rel="stylesheet" href="_content/ChartJs.Blazor/ChartJSBlazor.css" />

10
samples/voting/results/Startup.cs

@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using System.IdentityModel.Tokens.Jwt; using System.IdentityModel.Tokens.Jwt;
using System.Threading.Tasks;
namespace Results namespace Results
{ {
@ -24,6 +25,7 @@ namespace Results
services.AddRazorPages(); services.AddRazorPages();
services.AddServerSideBlazor(); services.AddServerSideBlazor();
JwtSecurityTokenHandler.DefaultMapInboundClaims = false; JwtSecurityTokenHandler.DefaultMapInboundClaims = false;
services.AddAuthentication(options => services.AddAuthentication(options =>
@ -34,12 +36,18 @@ namespace Results
.AddCookie("Cookies") .AddCookie("Cookies")
.AddOpenIdConnect("oidc", options => .AddOpenIdConnect("oidc", options =>
{ {
options.Authority = $"{Configuration["public-ip"]}/identityserver"; options.Authority = $"{Configuration["public-ip"]}/identityserver/";
options.ClientId = "interactive"; options.ClientId = "interactive";
options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0"; options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0";
options.ResponseType = "code"; options.ResponseType = "code";
options.SaveTokens = true; options.SaveTokens = true;
options.RequireHttpsMetadata = false; options.RequireHttpsMetadata = false;
options.ReturnUrlParameter = $"{Configuration["public-ip"]}/results";
options.Events.OnRedirectToIdentityProvider = n =>
{
n.ProtocolMessage.RedirectUri = $"{Configuration["public-ip"]}/results/signin-oidc";
return Task.CompletedTask;
};
}); });
} }

6
samples/voting/results/appsettings.json

@ -1,9 +1,9 @@
{ {
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Trace",
"Microsoft": "Warning", "Microsoft": "Trace",
"Microsoft.Hosting.Lifetime": "Information" "Microsoft.Hosting.Lifetime": "Trace"
} }
}, },
"AllowedHosts": "*" "AllowedHosts": "*"

8
samples/voting/tye.yaml

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

Loading…
Cancel
Save