Created
June 2, 2014 00:19
-
-
Save mattatcha/f115dd69a3f775dc4b68 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
// 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