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
// Get the method we intend to call using reflection (GetMethod) | |
var methodInfo = _contactManager.GetType().GetMethod(method); |
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
// 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); | |
} | |
} |
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
// 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; |
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] | |
public async Task<JsonResult> Call() | |
{ | |
} |
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 UserToken DecodeToken(string token) | |
{ | |
if (string.IsNullOrWhiteSpace(token)) | |
{ | |
return new UserToken() | |
{ | |
IsValid = false, | |
}; | |
} |
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 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, |
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 Authentication : IAuthentication | |
{ | |
readonly UserManager<ApplicationUser> _userManager; | |
public Authentication(UserManager<ApplicationUser> userManager) | |
{ | |
_userManager = userManager; | |
} | |
public async Task<User> CreateUser(string email, string password) |
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 Configurator | |
{ | |
public static void ConfigureServices(IServiceCollection services, IConfiguration configuration) | |
{ | |
services.AddDbContext<ApplicationDbContext>(options => | |
options.UseSqlite( | |
configuration.GetConnectionString("DefaultConnection"))); | |
services.AddIdentity<ApplicationUser, IdentityRole>() | |
.AddEntityFrameworkStores<ApplicationDbContext>() |
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 ApplicationUser: IdentityUser | |
{ | |
} |
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 ApplicationDbContext : IdentityDbContext<ApplicationUser> | |
{ | |
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) | |
: base(options) | |
{ | |
} | |
public DbSet<ApplicationUser> ApplicationUsers { get; set; } | |
} |