Skip to content

Instantly share code, notes, and snippets.

View chadmichel's full-sized avatar
😀
Working

Chad Michel chadmichel

😀
Working
View GitHub Profile
// Get the method we intend to call using reflection (GetMethod)
var methodInfo = _contactManager.GetType().GetMethod(method);
// Put parameters from JSON into a dictionary
var parameters = new Dictionary<string, object>();
foreach (var p in parsed.Property("parameters").First())
{
if (p is JProperty parameter)
{
parameters.Add(parameter.Name, parameter.Value);
}
}
// Convert the input into a string
using var str = new StreamReader(Request.Body);
var json = await str.ReadToEndAsync();
// Parse into a JObject with NewtonSoft
var parsed = JsonConvert.DeserializeObject(json) as JObject;
[HttpPost]
public async Task<JsonResult> Call()
{
}
public UserToken DecodeToken(string token)
{
if (string.IsNullOrWhiteSpace(token))
{
return new UserToken()
{
IsValid = false,
};
}
public string CreateToken(string guid, string email, int expireDays)
{
var tokenHandler = new JwtSecurityTokenHandler();
var claims = new ClaimsIdentity();
claims.AddClaim(new Claim(ClaimTypes.Email, email));
claims.AddClaim(new Claim(ClaimTypes.Sid, guid));
var token = tokenHandler.CreateJwtSecurityToken(
Issuer,
public class Authentication : IAuthentication
{
readonly UserManager<ApplicationUser> _userManager;
public Authentication(UserManager<ApplicationUser> userManager)
{
_userManager = userManager;
}
public async Task<User> CreateUser(string email, string password)
public class Configurator
{
public static void ConfigureServices(IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlite(
configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
public class ApplicationUser: IdentityUser
{
}
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
}