-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
307 additions
and
301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
ConfidentialClientCredentialsCertificate/MyServerRenderedPortal/HostingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Microsoft.AspNetCore.Authorization; | ||
using Microsoft.AspNetCore.Mvc.Authorization; | ||
using Microsoft.Identity.Web; | ||
using Microsoft.Identity.Web.UI; | ||
using Microsoft.IdentityModel.Logging; | ||
using Serilog; | ||
using System.IdentityModel.Tokens.Jwt; | ||
|
||
namespace MyServerRenderedPortal; | ||
|
||
internal static class HostingExtensions | ||
{ | ||
public static WebApplication ConfigureServices(this WebApplicationBuilder builder) | ||
{ | ||
var services = builder.Services; | ||
var configuration = builder.Configuration; | ||
|
||
services.AddTransient<ConfidentialClientApiService>(); | ||
services.AddTransient<ClientAssertionsApiService>(); | ||
services.AddHttpClient(); | ||
services.AddOptions(); | ||
|
||
services.AddMicrosoftIdentityWebAppAuthentication(configuration); | ||
|
||
services.AddRazorPages().AddMvcOptions(options => | ||
{ | ||
var policy = new AuthorizationPolicyBuilder() | ||
.RequireAuthenticatedUser() | ||
.Build(); | ||
options.Filters.Add(new AuthorizeFilter(policy)); | ||
}).AddMicrosoftIdentityUI(); | ||
return builder.Build(); | ||
} | ||
|
||
public static WebApplication ConfigurePipeline(this WebApplication app) | ||
{ | ||
IdentityModelEventSource.ShowPII = true; | ||
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); | ||
|
||
app.UseSerilogRequestLogging(); | ||
|
||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseSerilogRequestLogging(); | ||
|
||
app.UseHttpsRedirection(); | ||
app.UseStaticFiles(); | ||
|
||
app.UseRouting(); | ||
|
||
app.UseAuthentication(); | ||
app.UseAuthorization(); | ||
|
||
app.MapRazorPages(); | ||
app.MapControllers(); | ||
|
||
return app; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 34 additions & 42 deletions
76
ConfidentialClientCredentialsCertificate/MyServerRenderedPortal/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,40 @@ | ||
using MyServerRenderedPortal; | ||
|
||
using ServiceApi; | ||
using Azure.Identity; | ||
using Serilog; | ||
using Serilog.Events; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using System; | ||
|
||
namespace MyServerRenderedPortal; | ||
Log.Logger = new LoggerConfiguration() | ||
.WriteTo.Console() | ||
.WriteTo.AzureApp() | ||
.CreateBootstrapLogger(); | ||
|
||
public class Program | ||
try | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information) | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console() | ||
.CreateLogger(); | ||
Log.Information("Starting WebApi"); | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Host.UseSerilog((context, loggerConfiguration) => loggerConfiguration | ||
.ReadFrom.Configuration(context.Configuration)); | ||
|
||
try | ||
{ | ||
Log.Information("Starting web host"); | ||
CreateHostBuilder(args).Build().Run(); | ||
return 0; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Host terminated unexpectedly"); | ||
return 1; | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} | ||
} | ||
var app = builder | ||
.ConfigureServices() | ||
.ConfigurePipeline(); | ||
|
||
public static IHostBuilder CreateHostBuilder(string[] args) => | ||
Host.CreateDefaultBuilder(args) | ||
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration | ||
.ReadFrom.Configuration(hostingContext.Configuration) | ||
.Enrich.FromLogContext() | ||
.MinimumLevel.Verbose() | ||
.WriteTo.File("../LogsMyServerRenderedPortal.txt") | ||
.WriteTo.Console(theme: AnsiConsoleTheme.Code) | ||
) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
}); | ||
} | ||
app.Run(); | ||
} | ||
catch (Exception ex) when (ex.GetType().Name is not "StopTheHostException" | ||
&& ex.GetType().Name is not "HostAbortedException") | ||
{ | ||
Log.Fatal(ex, "Unhandled exception"); | ||
} | ||
finally | ||
{ | ||
Log.Information("Shut down complete"); | ||
Log.CloseAndFlush(); | ||
} |
19 changes: 1 addition & 18 deletions
19
...dentialClientCredentialsCertificate/MyServerRenderedPortal/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,12 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:60192", | ||
"sslPort": 44377 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"AZURE_CLIENT_ID": "64ecb044-417b-4892-83d4-5c03e8c977b9", | ||
"ASPNETCORE_ENVIRONMENT": "Development", | ||
"AZURE_TENANT_ID": "7ff95b15-dc21-4ba6-bc92-824856578fc1" | ||
} | ||
}, | ||
"MyServerRenderedPortal": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
}, | ||
"applicationUrl": "https://localhost:5001" | ||
"applicationUrl": "https://localhost:44377" | ||
} | ||
} | ||
} |
74 changes: 0 additions & 74 deletions
74
ConfidentialClientCredentialsCertificate/MyServerRenderedPortal/Startup.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.