Skip to content

Instantly share code, notes, and snippets.

@mattatcha
Created June 2, 2014 00:19
Show Gist options
  • Save mattatcha/f115dd69a3f775dc4b68 to your computer and use it in GitHub Desktop.
Save mattatcha/f115dd69a3f775dc4b68 to your computer and use it in GitHub Desktop.
// Create a token for the user after we verified their password.
// TODO: Store this in a db? This would be helpful if we would like to invalidate a login.
func (a *User) CreateToken() (string, error) {
token := jwt.New(jwt.GetSigningMethod("HS256"))
token.Claims["Id"] = a.Id
token.Claims["Email"] = a.Email
token.Claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
// TODO: Move this to a config file.
tokenString, err := token.SignedString([]byte("someRandomSigningKey"))
if err != nil {
return "", err
}
// Sould we just return a Token instead of a string???
return tokenString, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment