Skip to content

Commit d70f94c

Browse files
committed
Change GenerateBearer function signature
1 parent ee20339 commit d70f94c

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

jwt.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"encoding/base64"
88
"fmt"
99
"math/big"
10-
"time"
1110
)
1211

1312
func i2osp(n *big.Int, l int) []byte {
@@ -32,15 +31,14 @@ func es256(key *ecdsa.PrivateKey, body string) ([]byte, error) {
3231
return append(i2osp(r, 32), i2osp(s, 32)...), nil
3332
}
3433

35-
func GenerateBearer(key *ecdsa.PrivateKey, keyId, teamId string) (string, int64, error) {
36-
iat := time.Now().Unix()
34+
func GenerateBearer(key *ecdsa.PrivateKey, keyId, teamId string, issuedAt int64) (string, error) {
3735
h := fmt.Sprintf(`{"alg":"ES256","typ":"JWT","kid":"%s"}`, keyId)
38-
p := fmt.Sprintf(`{"iss":"%s","iat":%d}`, teamId, iat)
36+
p := fmt.Sprintf(`{"iss":"%s","iat":%d}`, teamId, issuedAt)
3937
hp := base64.RawURLEncoding.EncodeToString([]byte(h)) + "." + base64.RawURLEncoding.EncodeToString([]byte(p))
4038
sig, err := es256(key, hp)
4139
if err != nil {
42-
return "", 0, err
40+
return "", err
4341
}
4442
t := hp + "." + base64.RawURLEncoding.EncodeToString([]byte(sig))
45-
return t, iat, nil
43+
return t, nil
4644
}

token.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func (t *Token) Generate() (string, error) {
7676
if t.Key == nil {
7777
return "", errors.New("key is nil")
7878
}
79-
bearer, issuedAt, err := GenerateBearer(t.Key, t.KeyID, t.TeamID)
79+
issuedAt := time.Now().Unix()
80+
bearer, err := GenerateBearer(t.Key, t.KeyID, t.TeamID, issuedAt)
8081
if err != nil {
8182
return "", err
8283
}

0 commit comments

Comments
 (0)