Skip to content

Instantly share code, notes, and snippets.


Mircea Teodor Oprea Mirch

Block or report user

Report or block Mirch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View TokenService.cs
public class TokenService : ITokenService
private readonly AuthenticationSettings _authenticationSettings;
public TokenService(IOptions<AuthenticationSettings> authenticationSettings)
_authenticationSettings = authenticationSettings.Value;
public string BuildToken(string email, string role = "User")
View ITokenService.cs
public interface ITokenService
string BuildToken(string email, string role = "User");
View ProjectTypesController.cs
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme, Roles = "Admin")]
public async Task<IActionResult> CreateProjectType([FromBody] ProjectType model)
View AuthenticationController.cs
public IActionResult Login([FromBody]UserCredentials credentials)
var user = _context.Users.SingleOrDefault(u => u.Email == credentials.Email);
if (user != null)
var hashedPassword = _hashingService.Hash(credentials.Password, user.Salt);
if (hashedPassword == user.HashedPassword)
View AuthenticationController.cs
public async Task<IActionResult> Register([FromBody]UserCredentials credentials)
var alreadyExists = _context.Users.Any(u => u.Email == credentials.Email);
if (alreadyExists)
return BadRequest("User already exists.");
View User.cs
public struct UserCredentials
public string Email { get; set; }
public string Password { get; set; }
View AuthenticationController.cs
private string BuildToken(string email)
var tokenHandler = new JwtSecurityTokenHandler();
var key = Encoding.UTF8.GetBytes(_authenticationSettings.JwtKey);
var tokenDescriptor = new SecurityTokenDescriptor
Subject = new ClaimsIdentity(new Claim[]
new Claim(ClaimTypes.Name, email)
View AuthenticationController.cs
public class AuthenticationController : ControllerBase
private readonly BlueInkDbContext _context;
private readonly HashingService _hashingService;
private readonly ITokenService _tokenService;
public AuthenticationController(BlueInkDbContext context,
HashingService hashingService,
ITokenService tokenService)
View Startup.cs
public void ConfigureServices(IServiceCollection services)
services.AddDbContext<BlueInkDbContext>(options =>
var signingKey = Encoding.UTF8.GetBytes(Configuration.GetSection("AuthenticationSettings")
View AuthenticationSettings.cs
public class AuthenticationSettings
public string JwtKey { get; set; }
You can’t perform that action at this time.