diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-02-09 21:56:32 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-02-09 21:56:32 -0800 |
| commit | 4ff4a147b258bb7787e492a74254f3993bb69d1a (patch) | |
| tree | 304dd8cba4ce415b7a9312f90760c8d086793b77 /weed/security/jwt.go | |
| parent | 501bd72b1c9a88cadb5182cf9c13c2d796cf775f (diff) | |
| download | seaweedfs-4ff4a147b258bb7787e492a74254f3993bb69d1a.tar.xz seaweedfs-4ff4a147b258bb7787e492a74254f3993bb69d1a.zip | |
cleanup security.Secret
Diffstat (limited to 'weed/security/jwt.go')
| -rw-r--r-- | weed/security/jwt.go | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/weed/security/jwt.go b/weed/security/jwt.go index 46b7efaaf..844ffb77b 100644 --- a/weed/security/jwt.go +++ b/weed/security/jwt.go @@ -11,10 +11,10 @@ import ( ) type EncodedJwt string -type Secret string +type SigningKey string -func GenJwt(secret Secret, fileId string) EncodedJwt { - if secret == "" { +func GenJwt(signingKey SigningKey, fileId string) EncodedJwt { + if signingKey == "" { return "" } @@ -23,7 +23,7 @@ func GenJwt(secret Secret, fileId string) EncodedJwt { ExpiresAt: time.Now().Add(time.Second * 10).Unix(), Subject: fileId, } - encoded, e := t.SignedString(secret) + encoded, e := t.SignedString(signingKey) if e != nil { glog.V(0).Infof("Failed to sign claims: %v", t.Claims) return "" @@ -55,20 +55,20 @@ func GetJwt(r *http.Request) EncodedJwt { return EncodedJwt(tokenStr) } -func EncodeJwt(secret Secret, claims *jwt.StandardClaims) (EncodedJwt, error) { - if secret == "" { +func EncodeJwt(signingKey SigningKey, claims *jwt.StandardClaims) (EncodedJwt, error) { + if signingKey == "" { return "", nil } t := jwt.New(jwt.GetSigningMethod("HS256")) t.Claims = claims - encoded, e := t.SignedString(secret) + encoded, e := t.SignedString(signingKey) return EncodedJwt(encoded), e } -func DecodeJwt(secret Secret, tokenString EncodedJwt) (token *jwt.Token, err error) { +func DecodeJwt(signingKey SigningKey, tokenString EncodedJwt) (token *jwt.Token, err error) { // check exp, nbf return jwt.Parse(string(tokenString), func(token *jwt.Token) (interface{}, error) { - return secret, nil + return signingKey, nil }) } |
