Skip to content

Commit 6309641

Browse files
committed
fix: use expires_in field for git device refresh
This was causing git auth to never refresh after the token became expired after 8hrs.
1 parent d896b74 commit 6309641

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

coderd/gitauth/oauth.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ import (
66
"net/http"
77
"net/url"
88
"regexp"
9+
"time"
910

1011
"golang.org/x/oauth2"
1112
"golang.org/x/oauth2/github"
1213
"golang.org/x/xerrors"
1314

15+
"github.com/coder/coder/coderd/database"
1416
"github.com/coder/coder/codersdk"
1517
)
1618

@@ -138,7 +140,9 @@ func (c *DeviceAuth) AuthorizeDevice(ctx context.Context) (*codersdk.GitAuthDevi
138140
}
139141

140142
type ExchangeDeviceCodeResponse struct {
141-
*oauth2.Token
143+
AccessToken string `json:"access_token"`
144+
RefreshToken string `json:"refresh_token"`
145+
ExpiresIn int `json:"expires_in"`
142146
Error string `json:"error"`
143147
ErrorDescription string `json:"error_description"`
144148
}
@@ -175,7 +179,11 @@ func (c *DeviceAuth) ExchangeDeviceCode(ctx context.Context, deviceCode string)
175179
if body.Error != "" {
176180
return nil, xerrors.New(body.Error)
177181
}
178-
return body.Token, nil
182+
return &oauth2.Token{
183+
AccessToken: body.AccessToken,
184+
RefreshToken: body.RefreshToken,
185+
Expiry: database.Now().Add(time.Duration(body.ExpiresIn) * time.Second),
186+
}, nil
179187
}
180188

181189
func (c *DeviceAuth) formatDeviceTokenURL(deviceCode string) (string, error) {

0 commit comments

Comments
 (0)