Created
August 10, 2020 13:23
-
-
Save chadmichel/2ae28a30be803eb6944de90362f42eb5 to your computer and use it in GitHub Desktop.
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
[ApiController] | |
[Route("[controller]")] | |
public class AuthController : Controller | |
{ | |
// GET | |
[HttpGet] | |
public string Token() | |
{ | |
var tokenHandler = new JwtSecurityTokenHandler(); | |
var key = Encoding.ASCII.GetBytes("YOUR_KEY"); | |
var tokenDescriptor = new SecurityTokenDescriptor | |
{ | |
Subject = new ClaimsIdentity(new[] | |
{ | |
new Claim(ClaimTypes.Email, "bob@example.com") | |
}), | |
Expires = DateTime.UtcNow.AddMinutes(600), | |
SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature) | |
}; | |
var token = tokenHandler.CreateToken(tokenDescriptor); | |
return tokenHandler.WriteToken(token); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment