File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,25 +3,26 @@ package utils
33import (
44 "crypto/rand"
55 "encoding/base64"
6+ "time"
7+
68 jwtlib "github.com/dgrijalva/jwt-go"
79 "github.com/golang/glog"
810 "github.com/google/go-github/github"
9- "time"
1011)
1112
12- func GenerateToken (user * github.User ) (tok string , err error ) {
13- // Create the token
13+ // GenerateToken signs a session token for user with secret. secret comes
14+ // from config.Config.App.JWTSecret (env-sourced, never hardcoded — see
15+ // config/config.go). Previously this was a literal string,
16+ // "unicornsAreAwesome", committed in a public repo; anyone with the
17+ // source could mint a valid token for any user ID.
18+ func GenerateToken (user * github.User , secret []byte ) (tok string , err error ) {
1419 token := jwtlib .New (jwtlib .GetSigningMethod ("HS256" ))
15- // Set some claims
1620 token .Claims = jwtlib.MapClaims {
1721 "Name" : user .Login ,
1822 "UserID" : user .ID ,
1923 "exp" : time .Now ().Add (time .Hour * 1 ).Unix (),
2024 }
21- // Sign and get the complete encoded token as a string
22- mySuperSecretPassword := "unicornsAreAwesome"
23-
24- tokenString , err := token .SignedString ([]byte (mySuperSecretPassword ))
25+ tokenString , err := token .SignedString (secret )
2526 if err != nil {
2627 return "" , err
2728 }
You can’t perform that action at this time.
0 commit comments