Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb4a7fe3

Browse files
authored
fix: useexpires_in field for git device refresh (#8411)
This was causing git auth to never refresh after the tokenbecame expired after 8hrs.
1 parent9df8053 commitb4a7fe3

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
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
typeExchangeDeviceCodeResponsestruct {
141-
*oauth2.Token
143+
AccessTokenstring`json:"access_token"`
144+
RefreshTokenstring`json:"refresh_token"`
145+
ExpiresInint`json:"expires_in"`
142146
Errorstring`json:"error"`
143147
ErrorDescriptionstring`json:"error_description"`
144148
}
@@ -175,7 +179,11 @@ func (c *DeviceAuth) ExchangeDeviceCode(ctx context.Context, deviceCode string)
175179
ifbody.Error!="" {
176180
returnnil,xerrors.New(body.Error)
177181
}
178-
returnbody.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(deviceCodestring) (string,error) {

‎coderd/gitauth_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ func TestGitAuthDevice(t *testing.T) {
200200
require.Equal(t,"authorization_pending",sdkErr.Detail)
201201

202202
resp= gitauth.ExchangeDeviceCodeResponse{
203-
Token:&oauth2.Token{
204-
AccessToken:"hey",
205-
},
203+
AccessToken:"hey",
206204
}
207205

208206
err=client.GitAuthDeviceExchange(context.Background(),"test", codersdk.GitAuthDeviceExchange{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp