SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. func CreateToken(email, ua, password string) (string, error) {
  2.     //Creating empty slice
  3.     r := make([]byte, 24)
  4.    
  5.     //Push random data to slice
  6.     rand.Read(r)
  7.    
  8.     //Generate secret code for jwt
  9.     secret := sha3.New512().Sum(append([]byte(email + ua + password), r...))
  10.  
  11.     //Create custom claims with user data
  12.     claims := JwtClaims{
  13.         Email:  email,
  14.         StandardClaims: jwt.StandardClaims{
  15.             ExpiresAt: time.Now().Add(time.Hour).Unix(),
  16.         },
  17.     }
  18.  
  19.     //Generate jwt token
  20.     token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
  21.  
  22.     //Sign jwt token
  23.     jwt, err := token.SignedString(secret)
  24.     if err != nil {return "", err}
  25.  
  26.     //TODO: Adding hash to database to current device.
  27.  
  28.     return jwt, nil
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top