Skip to content

Instantly share code, notes, and snippets.

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddNester();
services.AddDbContext<JwtauthContext>(options =>
options.UseSqlite("Data Source=/var/app/source/shared/Jwtauth.db"));
services.AddScoped<IIndustryRepository, IndustryRepository>();
// Set API Version
services.AddApiVersioning(options => {
public static class IdentityExtension
{
public static void AddIdentity(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<IdentitySettings>(options => configuration.GetSection("IdentitySettings").Bind(options));
IdentitySettings identitySettings = configuration.GetSection(nameof(IdentitySettings)).Get<IdentitySettings>();
services.AddMvc(options => {
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
public static class JwtExtension
{
public static void AddJwt(this IServiceCollection services, IConfiguration configuration)
{
services.Configure<JwtSettings>(options => configuration.GetSection("JwtSettings").Bind(options));
JwtSettings jwtSettings = configuration.GetSection(nameof(JwtSettings)).Get<JwtSettings>();
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
if (result.HttpStatus == System.Net.HttpStatusCode.Unauthorized)
{
/*
* The token has expired. Renew is auto-renew option
* has been requested.
*/
if (Permit != null && AutoTokenRenew)
{
if (ex.Call.Response.Headers.Contains("Token-Expired"))
{
<?xml version="1.0" encoding="UTF-8"?>
<Shell>
<ShellItem Route="Bootstrap">
<ShellContent ContentTemplate="{DataTemplate local:BootPage}" />
</ShellItem>
<ShellItem Route="Onboarding">
<ShellContent ContentTemplate="{DataTemplate local:OnboardingPage}" />
</ShellItem>
if (await _viewModel.UserViewModel.RestorePermitAsync())
{
// Navigate to the home page
// if a valid JWT not found!
await GoHomeAsync();
}
else
{
// Either register or login