Last active
February 19, 2019 18:38
-
-
Save monkov/6a864aa5493cc1247022f28beea90193 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
func CreateToken(email, ua, password string) (string, error) { | |
//Creating empty slice | |
r := make([]byte, 24) | |
//Push random data to slice | |
rand.Read(r) | |
//Generate secret code for jwt | |
secret := sha3.New512().Sum(append([]byte(email + ua + password), r...)) | |
//Create custom claims with user data | |
claims := JwtClaims{ | |
Email: email, | |
StandardClaims: jwt.StandardClaims{ | |
ExpiresAt: time.Now().Add(time.Hour).Unix(), | |
}, | |
} | |
//Generate jwt token | |
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) | |
//Sign jwt token | |
jwt, err := token.SignedString(secret) | |
if err != nil {return "", err} | |
//TODO: Adding hash to database to current device. | |
return jwt, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment