Skip to content

Commit 0ad0f25

Browse files
committed
Increase expireDelta time to 60 seconds
10 seconds token expire delta is too small as on poor connections one can easily end up with 401 error due to temporary network issues and lengthy TCP/IP retries. It leads to a rather misleading 401 authorization error. The issue is observed in real-life with Google Cloud object storage and other services.
1 parent 36a7019 commit 0ad0f25

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

jws/jws.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (c *ClaimSet) encode() (string, error) {
5555
// Reverting time back for machines whose time is not perfectly in sync.
5656
// If client machine's time is in the future according
5757
// to Google servers, an access token will not be issued.
58-
now := time.Now().Add(-10 * time.Second)
58+
now := time.Now().Add(-60 * time.Second)
5959
if c.Iat == 0 {
6060
c.Iat = now.Unix()
6161
}

token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
// expiryDelta determines how earlier a token should be considered
2020
// expired than its actual expiration time. It is used to avoid late
2121
// expirations due to client-server time mismatches.
22-
const expiryDelta = 10 * time.Second
22+
const expiryDelta = 60 * time.Second
2323

2424
// Token represents the credentials used to authorize
2525
// the requests to access protected resources on the OAuth 2.0

token_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ func TestTokenExpiry(t *testing.T) {
4242
tok *Token
4343
want bool
4444
}{
45-
{name: "12 seconds", tok: &Token{Expiry: now.Add(12 * time.Second)}, want: false},
46-
{name: "10 seconds", tok: &Token{Expiry: now.Add(expiryDelta)}, want: false},
47-
{name: "10 seconds-1ns", tok: &Token{Expiry: now.Add(expiryDelta - 1*time.Nanosecond)}, want: true},
45+
{name: "62 seconds", tok: &Token{Expiry: now.Add(62 * time.Second)}, want: false},
46+
{name: "60 seconds", tok: &Token{Expiry: now.Add(expiryDelta)}, want: false},
47+
{name: "60 seconds-1ns", tok: &Token{Expiry: now.Add(expiryDelta - 1*time.Nanosecond)}, want: true},
4848
{name: "-1 hour", tok: &Token{Expiry: now.Add(-1 * time.Hour)}, want: true},
4949
}
5050
for _, tc := range cases {

0 commit comments

Comments
 (0)