Skip to content

Commit 59471d4

Browse files
feat!: replace deprecated PKCE flag (#168)
* fix: replace deprecated PKCE flag * make PKCE method configurable * Fix comment for WithPKCEMethod function
1 parent 79af406 commit 59471d4

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

pkg/clusteraccess/access.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ func createOIDCKubeconfig(opts *CreateOIDCKubeconfigOptions) ([]byte, error) {
387387
for _, extraScope := range opts.ExtraScopes {
388388
exec.Args = append(exec.Args, "--oidc-extra-scope="+extraScope)
389389
}
390-
if opts.UsePKCE {
391-
exec.Args = append(exec.Args, "--oidc-use-pkce")
390+
if opts.PKCEMethod != "" {
391+
exec.Args = append(exec.Args, "--oidc-pkce-method="+string(opts.PKCEMethod))
392392
}
393393
if opts.ForceRefresh {
394394
exec.Args = append(exec.Args, "--force-refresh")
@@ -434,7 +434,7 @@ type CreateOIDCKubeconfigOptions struct {
434434
ClientID string
435435
ClientSecret string
436436
ExtraScopes []string
437-
UsePKCE bool
437+
PKCEMethod PKCEMethod
438438
ForceRefresh bool
439439
GrantType OIDCGrantType
440440
}
@@ -449,6 +449,14 @@ const (
449449
GrantTypeDeviceCode OIDCGrantType = "device-code"
450450
)
451451

452+
type PKCEMethod string
453+
454+
const (
455+
PKCEMethodAuto PKCEMethod = "auto"
456+
PKCEMethodNo PKCEMethod = "no"
457+
PKCEMethodS256 PKCEMethod = "S256"
458+
)
459+
452460
type CreateOIDCKubeconfigOption func(*CreateOIDCKubeconfigOptions)
453461

454462
// WithExtraScope is an option for CreateOIDCKubeconfig that adds an extra scope to the oidc-login subcommand.
@@ -459,10 +467,10 @@ func WithExtraScope(scope string) CreateOIDCKubeconfigOption {
459467
}
460468
}
461469

462-
// UsePKCE is an option for CreateOIDCKubeconfig that enforces the use of PKCE.
463-
func UsePKCE() CreateOIDCKubeconfigOption {
470+
// WithPKCEMethod is an option for CreateOIDCKubeconfig that sets the PKCE method.
471+
func WithPKCEMethod(m PKCEMethod) CreateOIDCKubeconfigOption {
464472
return func(opts *CreateOIDCKubeconfigOptions) {
465-
opts.UsePKCE = true
473+
opts.PKCEMethod = m
466474
}
467475
}
468476

pkg/clusteraccess/access_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ var _ = Describe("ClusterAccess", func() {
495495
kcfgBytes, err := clusteraccess.CreateOIDCKubeconfig("testuser", "https://api.example.com", []byte("test-ca"), "https://example.com/oidc", "test-client-id",
496496
clusteraccess.WithExtraScope("foo"),
497497
clusteraccess.WithExtraScope("bar"),
498-
clusteraccess.UsePKCE(),
498+
clusteraccess.WithPKCEMethod(clusteraccess.PKCEMethodAuto),
499499
clusteraccess.ForceRefresh(),
500500
clusteraccess.WithClientSecret("test-client-secret"),
501501
clusteraccess.WithGrantType(clusteraccess.GrantTypePassword),
@@ -523,7 +523,7 @@ var _ = Describe("ClusterAccess", func() {
523523
"--grant-type=password",
524524
"--oidc-extra-scope=foo",
525525
"--oidc-extra-scope=bar",
526-
"--oidc-use-pkce",
526+
"--oidc-pkce-method=auto",
527527
"--force-refresh",
528528
))
529529
})

0 commit comments

Comments
 (0)