From 26f94e348328f369e4e9c81f037a16a56e03b533 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Thu, 30 Jul 2020 08:38:20 -0700 Subject: [PATCH] update function version --- .../voting/IdentityServer/Startup.cs | 8 +++--- .../azure-functions/voting/results/Startup.cs | 26 ++++++++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/samples/azure-functions/voting/IdentityServer/Startup.cs b/samples/azure-functions/voting/IdentityServer/Startup.cs index 47fa4534..fc1df2a2 100644 --- a/samples/azure-functions/voting/IdentityServer/Startup.cs +++ b/samples/azure-functions/voting/IdentityServer/Startup.cs @@ -60,13 +60,11 @@ namespace IdentityServer AllowedGrantTypes = GrantTypes.Code, - // These currently break when ingress is in place for redirect. - RedirectUris = { $"http://40.91.74.200/results/signin-oidc" }, - FrontChannelLogoutUri = $"http://40.91.74.200/results/signout-oidc", - PostLogoutRedirectUris = { $"http://40.91.74.200/results/signout-callback-oidc" }, + RedirectUris = { $"{Configuration.GetServiceUri("results:http")}signin-oidc" }, + FrontChannelLogoutUri = $"{Configuration.GetServiceUri("results:http")}signout-oidc", + PostLogoutRedirectUris = { $"{Configuration.GetServiceUri("results:http")}signout-callback-oidc" }, AllowOfflineAccess = true, - // AllowedCorsOrigins = { $"{Configuration.GetServiceUri("results")}" }, AllowedScopes = new List{IdentityServerConstants.StandardScopes.OpenId,IdentityServerConstants.StandardScopes.Profile, "scope"} }, }); diff --git a/samples/azure-functions/voting/results/Startup.cs b/samples/azure-functions/voting/results/Startup.cs index f57f54c4..0e907179 100644 --- a/samples/azure-functions/voting/results/Startup.cs +++ b/samples/azure-functions/voting/results/Startup.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; @@ -25,8 +26,29 @@ namespace Results // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.AddAuthorization(o => o.FallbackPolicy = o.DefaultPolicy); + services.AddRazorPages(); services.AddServerSideBlazor(); + + + JwtSecurityTokenHandler.DefaultMapInboundClaims = false; + + services.AddAuthentication(options => + { + options.DefaultScheme = "Cookies"; + options.DefaultChallengeScheme = "oidc"; + }) + .AddCookie("Cookies") + .AddOpenIdConnect("oidc", options => + { + options.Authority = $"{Configuration.GetServiceUri("identityserver:http")}"; + options.ClientId = "interactive"; + options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0"; + options.ResponseType = "code"; + options.SaveTokens = true; + options.RequireHttpsMetadata = false; + }); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -44,10 +66,12 @@ namespace Results app.UseStaticFiles(); app.UseRouting(); + app.UseAuthentication(); + app.UseAuthorization(); app.UseEndpoints(endpoints => { - endpoints.MapBlazorHub(); + endpoints.MapBlazorHub().RequireAuthorization(); endpoints.MapFallbackToPage("/_Host"); }); }