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

feat!: support PKCE in the oauth2 client's auth/exchange flow#21215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Emyrk wants to merge18 commits intomain
base:main
Choose a base branch
Loading
fromstevenmasley/oauth_pkce
Open
Changes from1 commit
Commits
Show all changes
18 commits
Select commitHold shift + click to select a range
08f52e9
feat: oauth2 client to use pkce in auth/exchange flow
EmyrkDec 10, 2025
40283ea
force pkce
EmyrkDec 10, 2025
5eb6e9f
chore: pkce defaults
EmyrkDec 10, 2025
53fc864
frontend test
EmyrkDec 10, 2025
ead92c8
chore: sane defaults and make gen
EmyrkDec 11, 2025
0be0bb2
make some tests use pkce
EmyrkDec 11, 2025
303ea30
fmt
EmyrkDec 11, 2025
7af6c3a
fix tests
EmyrkDec 11, 2025
7f11ab7
make gen
EmyrkDec 11, 2025
65b08c8
fix tests
EmyrkDec 11, 2025
c6b3b24
fix tests
EmyrkDec 11, 2025
37aa4c0
PR feedback
EmyrkDec 12, 2025
263b925
rename cookie from challenge to verifier
EmyrkDec 12, 2025
3e78053
Add some comments
EmyrkDec 12, 2025
ef3a3d3
make gen
EmyrkDec 12, 2025
82fdc0f
docs: added docs to external auth page
EmyrkDec 12, 2025
a753ff4
remove oidc from docs, since it is auto
EmyrkDec 12, 2025
675b528
PR feedback
EmyrkDec 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
force pkce
  • Loading branch information
@Emyrk
Emyrk committedDec 10, 2025
commit40283ea3835472b262f2fefa3cc84a725f2d4266
17 changes: 12 additions & 5 deletionscoderd/httpmw/oauth2.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"reflect"
"slices"

"github.com/go-chi/chi/v5"
"github.com/google/uuid"
Expand DownExpand Up@@ -133,14 +134,18 @@ func ExtractOAuth2(config promoauth.OAuth2Config, client *http.Client, cookieCfg
HttpOnly: true,
}))

authOpts := slices.Clone(opts)
var verifier = oauth2.GenerateVerifier()
authOpts = append(authOpts, oauth2.S256ChallengeOption(verifier))

http.SetCookie(rw, cookieCfg.Apply(&http.Cookie{
Name: codersdk.OAuth2PKCEChallenge,
Value: verifier,
Path: "/",
HttpOnly: true,
}))
http.Redirect(rw, r, config.AuthCodeURL(state, append(opts, oauth2.S256ChallengeOption(verifier))...), http.StatusTemporaryRedirect)

http.Redirect(rw, r, config.AuthCodeURL(state, authOpts...), http.StatusTemporaryRedirect)
return
}

Expand DownExpand Up@@ -170,13 +175,15 @@ func ExtractOAuth2(config promoauth.OAuth2Config, client *http.Client, cookieCfg
redirect = stateRedirect.Value
}

exchangeOpts := []oauth2.AuthCodeOption{}
pkceChallenge, err := r.Cookie(codersdk.OAuth2PKCEChallenge)
if err == nil {
exchangeOpts = append(exchangeOpts, oauth2.VerifierOption(pkceChallenge.Value))
if err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "PKCE challenge must be provided.",
})
return
}

oauthToken, err := config.Exchange(ctx, code,exchangeOpts...)
oauthToken, err := config.Exchange(ctx, code,oauth2.VerifierOption(pkceChallenge.Value))
if err != nil {
errorCode := http.StatusInternalServerError
detail := err.Error()
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp