Skip to content

Instantly share code, notes, and snippets.

if (await _viewModel.UserViewModel.RestorePermitAsync())
{
// Navigate to the home page
// if a valid JWT not found!
await GoHomeAsync();
}
else
{
// Either register or login
<?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 (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"))
{
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;
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()
// 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 enum Result
{
Succeeded = 0,
Failed = -1,
Unauthorized = -5,
InternalError = -10,
UserNotFound = -15,
IncorrectEmail = -20,
EmailNotConfirmed = -25,
IncorrectSecurityCode = -30,
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JwtKey"]));
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
var expires = DateTime.Now.AddHours(Convert.ToDouble(_configuration["JwtExpireHours"]));
var token = new JwtSecurityToken(
_configuration["JwtIssuer"],
_configuration["JwtIssuer"],
claims,
expires: expires,
signingCredentials: creds
public async Task<ResultMultiple<Share>> QuerySharesAsync(
bool doCache = true, bool throwIfError = true)
{
Share shareSeed = new Share();
shareSeed.OwnedBy = _selectedIndustry;
ResultMultiple<Share> result = await ResultMultipleUI<Share>.WaitForObjectAsync(
backend, throwIfError, shareSeed, doCache);
string clientSignature = JsonConvert.SerializeObject((
Model: DeviceInfo.Model,
Manufacturer: DeviceInfo.Manufacturer,
Name: DeviceInfo.Name,
Platform: DeviceInfo.Platform,
Idiom: DeviceInfo.Idiom,
DeviceType: DeviceInfo.DeviceType,
HardwareVersion: DeviceInfo.VersionString,
SoftwareVersion: typeof(MainPage).GetTypeInfo()