Skip to content

Instantly share code, notes, and snippets.

@aevitas
Last active January 10, 2017 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aevitas/ac977598cf51fbf83e5b9a3f9bd294f9 to your computer and use it in GitHub Desktop.
Save aevitas/ac977598cf51fbf83e5b9a3f9bd294f9 to your computer and use it in GitHub Desktop.
public JwtSecurityToken Generate(string userId, IEnumerable<Claim> claims)
{
Requires.NotEmpty(userId, nameof(userId));
// We're using a DateTimeOffset and later using the DateTime property thereof so we don't
// have to mess with extension methods to grab UNIX time, as DateTimeOffset has those built in.
var timeStamp = DateTimeOffset.UtcNow;
var token = new JwtSecurityToken(_options.Issuer, _options.Audience, claims, timeStamp.DateTime,
timeStamp.Add(_options.Expiration).DateTime, _options.SigningCredentials);
return token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment