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

Commit380022f

Browse files
authored
fix: update oauth token on each login (#3542)
1 parentc3eea98 commit380022f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

‎coderd/features_internal_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"net/http/httptest"
77
"testing"
88

9-
"github.com/coder/coder/codersdk"
109
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
11+
12+
"github.com/coder/coder/codersdk"
1213
)
1314

1415
funcTestEntitlements(t*testing.T) {

‎coderd/userauth.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,23 @@ func (api *API) userOAuth2Github(rw http.ResponseWriter, r *http.Request) {
241241
}
242242
}
243243

244+
iflink.UserID!=uuid.Nil {
245+
link,err=api.Database.UpdateUserLink(ctx, database.UpdateUserLinkParams{
246+
UserID:user.ID,
247+
LoginType:database.LoginTypeGithub,
248+
OAuthAccessToken:state.Token.AccessToken,
249+
OAuthRefreshToken:state.Token.RefreshToken,
250+
OAuthExpiry:state.Token.Expiry,
251+
})
252+
iferr!=nil {
253+
httpapi.Write(rw,http.StatusInternalServerError, codersdk.Response{
254+
Message:"A database error occurred.",
255+
Detail:fmt.Sprintf("update user link: %s",err.Error()),
256+
})
257+
return
258+
}
259+
}
260+
244261
_,created:=api.createAPIKey(rw,r,createAPIKeyParams{
245262
UserID:user.ID,
246263
LoginType:database.LoginTypeGithub,
@@ -432,6 +449,23 @@ func (api *API) userOIDC(rw http.ResponseWriter, r *http.Request) {
432449
}
433450
}
434451

452+
iflink.UserID!=uuid.Nil {
453+
link,err=api.Database.UpdateUserLink(ctx, database.UpdateUserLinkParams{
454+
UserID:user.ID,
455+
LoginType:database.LoginTypeOIDC,
456+
OAuthAccessToken:state.Token.AccessToken,
457+
OAuthRefreshToken:state.Token.RefreshToken,
458+
OAuthExpiry:state.Token.Expiry,
459+
})
460+
iferr!=nil {
461+
httpapi.Write(rw,http.StatusInternalServerError, codersdk.Response{
462+
Message:"A database error occurred.",
463+
Detail:fmt.Sprintf("update user link: %s",err.Error()),
464+
})
465+
return
466+
}
467+
}
468+
435469
// If the upstream email or username has changed we should mirror
436470
// that in Coder. Many enterprises use a user's email/username as
437471
// security auditing fields so they need to stay synced.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp