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
app.UseHsts(); | |
app.Use((context, next) => | |
{ | |
context.Request.Host = new HostString("api.domain.com); | |
context.Request.PathBase = new PathString("/identity"); //if you need this | |
context.Request.Scheme = "https"; | |
return next(); | |
}); | |
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
[HttpPost] | |
[AllowAnonymous] | |
[Route("account/external-login")] | |
public IActionResult ExternalLogin(string provider, string returnUrl) | |
{ | |
var redirectUrl = $"https://api.domain.com/identity/v1/account/external-auth-callback?returnUrl={returnUrl}"; | |
var properties = signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl); | |
properties.AllowRefresh = true; | |
return Challenge(properties, provider); | |
} |
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
<form method='POST' action={`https://api.domain.com/identity/v1/account/external-login?provider=Google&returnUrl=/home`} > | |
<Button | |
type="submit" | |
name='provider' | |
value='Google' | |
title={`Login using Google`}> | |
<img src='link-to-google-logo'} alt="" /> | |
Gooogle | |
</PageButton> | |
</form> |
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
app.UseAuthentication(); | |
app.UseAuthorization(); | |
app.UseSerilogRequestLogging(); | |
app.UseMiddleware<LogContextEnrichment>(); |
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
public class LogContextEnrichment | |
{ | |
private readonly RequestDelegate next; | |
public LogContextEnrichment(RequestDelegate next) | |
{ | |
this.next = next; | |
} | |
public async Task Invoke(HttpContext context, UserContext userContext, RequestContext requestContext, IDiagnosticContext diagnosticContext) |
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
using (LogContext.PushProperty("CorrelationId", context.GetCorrelationId())) | |
{ | |
logger.LogInformation('User {userId} placed a new order {orderId}', '27836478', 98733); | |
} |
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
_logger | |
.ForContext("OrderId", paymentId) | |
.ForContext("State", state) | |
.Information("Storing payment state in database"); |
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
{ | |
"AppSettings": { | |
"Monitoring": { | |
"AzureApplicationInsightsInstrumentationKey": "5303b86c-d318-4a74-8a43-85dae307dd38" | |
} | |
}, | |
"Serilog": { | |
"Using": [ | |
"Serilog.Sinks.ApplicationInsights" | |
], |
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
public class LoggingConfigurations | |
{ | |
public static ILogger GetLogger() | |
{ | |
var configuration = new ConfigurationBuilder() | |
.SetBasePath(Directory.GetCurrentDirectory()) | |
.AddJsonFile("appsettings.json", false) | |
.Build(); | |
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
public static void Main(string[] args) | |
{ | |
Log.Logger = LoggingConfigurations.GetLogger(); | |
try | |
{ | |
Log.Information("Application starting up."); | |
CreateHostBuilder(args).Build().Run(); | |
} |