Skip to content

Instantly share code, notes, and snippets.

@evgomes
Last active November 6, 2018 23:55
Show Gist options
  • Save evgomes/5dd7f6d1332f6eb91a0e7bcbc97a1698 to your computer and use it in GitHub Desktop.
Save evgomes/5dd7f6d1332f6eb91a0e7bcbc97a1698 to your computer and use it in GitHub Desktop.
Token creation method of JWT API.
public async Task<TokenResponse> CreateAccessTokenAsync(string email, string password)
{
var user = await _userService.FindByEmailAsync(email);
if (user == null || !_passwordHasher.PasswordMatches(password, user.Password))
{
return new TokenResponse(false, "Invalid credentials.", null);
}
var token = _tokenHandler.CreateAccessToken(user);
return new TokenResponse(true, null, token);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment