Skip to content

Commit 0afe16b

Browse files
committed
feat: add --oidc-issuer-url-override flag
Signed-off-by: kahirokunn <[email protected]>
1 parent c088abb commit 0afe16b

File tree

5 files changed

+39
-22
lines changed

5 files changed

+39
-22
lines changed

pkg/cmd/get_token.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
// getTokenOptions represents the options for get-token command.
1515
type getTokenOptions struct {
1616
IssuerURL string
17+
IssuerURLOverride string
1718
ClientID string
1819
ClientSecret string
1920
ExtraScopes []string
@@ -26,6 +27,7 @@ type getTokenOptions struct {
2627

2728
func (o *getTokenOptions) addFlags(f *pflag.FlagSet) {
2829
f.StringVar(&o.IssuerURL, "oidc-issuer-url", "", "Issuer URL of the provider (mandatory)")
30+
f.StringVar(&o.IssuerURLOverride, "oidc-issuer-url-override", "", "Override Issuer URL")
2931
f.StringVar(&o.ClientID, "oidc-client-id", "", "Client ID of the provider (mandatory)")
3032
f.StringVar(&o.ClientSecret, "oidc-client-secret", "", "Client secret of the provider")
3133
f.StringSliceVar(&o.ExtraScopes, "oidc-extra-scope", nil, "Scopes to request to the provider")
@@ -75,11 +77,12 @@ func (cmd *GetToken) New() *cobra.Command {
7577
}
7678
in := credentialplugin.Input{
7779
Provider: oidc.Provider{
78-
IssuerURL: o.IssuerURL,
79-
ClientID: o.ClientID,
80-
ClientSecret: o.ClientSecret,
81-
UsePKCE: o.UsePKCE,
82-
ExtraScopes: o.ExtraScopes,
80+
IssuerURL: o.IssuerURL,
81+
IssuerURLOverride: o.IssuerURLOverride,
82+
ClientID: o.ClientID,
83+
ClientSecret: o.ClientSecret,
84+
UsePKCE: o.UsePKCE,
85+
ExtraScopes: o.ExtraScopes,
8386
},
8487
TokenCacheDir: o.TokenCacheDir,
8588
GrantOptionSet: grantOptionSet,

pkg/cmd/setup.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// setupOptions represents the options for setup command.
1212
type setupOptions struct {
1313
IssuerURL string
14+
IssuerURLOverride string
1415
ClientID string
1516
ClientSecret string
1617
ExtraScopes []string
@@ -21,6 +22,7 @@ type setupOptions struct {
2122

2223
func (o *setupOptions) addFlags(f *pflag.FlagSet) {
2324
f.StringVar(&o.IssuerURL, "oidc-issuer-url", "", "Issuer URL of the provider")
25+
f.StringVar(&o.IssuerURLOverride, "oidc-issuer-url-override", "", "Overrided Issuer URL of the provider")
2426
f.StringVar(&o.ClientID, "oidc-client-id", "", "Client ID of the provider")
2527
f.StringVar(&o.ClientSecret, "oidc-client-secret", "", "Client secret of the provider")
2628
f.StringSliceVar(&o.ExtraScopes, "oidc-extra-scope", nil, "Scopes to request to the provider")
@@ -45,13 +47,14 @@ func (cmd *Setup) New() *cobra.Command {
4547
return fmt.Errorf("setup: %w", err)
4648
}
4749
in := setup.Stage2Input{
48-
IssuerURL: o.IssuerURL,
49-
ClientID: o.ClientID,
50-
ClientSecret: o.ClientSecret,
51-
ExtraScopes: o.ExtraScopes,
52-
UsePKCE: o.UsePKCE,
53-
GrantOptionSet: grantOptionSet,
54-
TLSClientConfig: o.tlsOptions.tlsClientConfig(),
50+
IssuerURL: o.IssuerURL,
51+
IssuerURLOverride: o.IssuerURLOverride,
52+
ClientID: o.ClientID,
53+
ClientSecret: o.ClientSecret,
54+
ExtraScopes: o.ExtraScopes,
55+
UsePKCE: o.UsePKCE,
56+
GrantOptionSet: grantOptionSet,
57+
TLSClientConfig: o.tlsOptions.tlsClientConfig(),
5558
}
5659
if c.Flags().Lookup("listen-address").Changed {
5760
in.ListenAddressArgs = o.authenticationOptions.ListenAddress

pkg/oidc/client/factory.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func (f *Factory) New(ctx context.Context, p oidc.Provider, tlsClientConfig tlsc
5252
}
5353

5454
ctx = context.WithValue(ctx, oauth2.HTTPClient, httpClient)
55+
56+
if p.IssuerURLOverride != "" {
57+
ctx = gooidc.InsecureIssuerURLContext(ctx, p.IssuerURLOverride)
58+
}
59+
5560
provider, err := gooidc.NewProvider(ctx, p.IssuerURL)
5661
if err != nil {
5762
return nil, fmt.Errorf("oidc discovery error: %w", err)

pkg/oidc/oidc.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111

1212
// Provider represents an OIDC provider.
1313
type Provider struct {
14-
IssuerURL string
15-
ClientID string
16-
ClientSecret string // optional
17-
ExtraScopes []string // optional
18-
UsePKCE bool // optional
14+
IssuerURL string
15+
IssuerURLOverride string // optional
16+
ClientID string
17+
ClientSecret string // optional
18+
ExtraScopes []string // optional
19+
UsePKCE bool // optional
1920
}
2021

2122
// TokenSet represents a set of ID token and refresh token.

pkg/usecases/setup/stage2.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ type stage2Vars struct {
6565
ClientID string
6666
Args []string
6767
Subject string
68+
IssuerURLOverride string
6869
}
6970

7071
// Stage2Input represents an input DTO of the stage2.
7172
type Stage2Input struct {
7273
IssuerURL string
74+
IssuerURLOverride string
7375
ClientID string
7476
ClientSecret string
7577
ExtraScopes []string // optional
@@ -83,11 +85,12 @@ func (u *Setup) DoStage2(ctx context.Context, in Stage2Input) error {
8385
u.Logger.Printf("authentication in progress...")
8486
out, err := u.Authentication.Do(ctx, authentication.Input{
8587
Provider: oidc.Provider{
86-
IssuerURL: in.IssuerURL,
87-
ClientID: in.ClientID,
88-
ClientSecret: in.ClientSecret,
89-
ExtraScopes: in.ExtraScopes,
90-
UsePKCE: in.UsePKCE,
88+
IssuerURL: in.IssuerURL,
89+
IssuerURLOverride: in.IssuerURLOverride,
90+
ClientID: in.ClientID,
91+
ClientSecret: in.ClientSecret,
92+
ExtraScopes: in.ExtraScopes,
93+
UsePKCE: in.UsePKCE,
9194
},
9295
GrantOptionSet: in.GrantOptionSet,
9396
TLSClientConfig: in.TLSClientConfig,
@@ -103,6 +106,7 @@ func (u *Setup) DoStage2(ctx context.Context, in Stage2Input) error {
103106
v := stage2Vars{
104107
IDTokenPrettyJSON: idTokenClaims.Pretty,
105108
IssuerURL: in.IssuerURL,
109+
IssuerURLOverride: in.IssuerURLOverride,
106110
ClientID: in.ClientID,
107111
Args: makeCredentialPluginArgs(in),
108112
Subject: idTokenClaims.Subject,
@@ -118,6 +122,7 @@ func (u *Setup) DoStage2(ctx context.Context, in Stage2Input) error {
118122
func makeCredentialPluginArgs(in Stage2Input) []string {
119123
var args []string
120124
args = append(args, "--oidc-issuer-url="+in.IssuerURL)
125+
args = append(args, "--oidc-issuer-url-override="+in.IssuerURL)
121126
args = append(args, "--oidc-client-id="+in.ClientID)
122127
if in.ClientSecret != "" {
123128
args = append(args, "--oidc-client-secret="+in.ClientSecret)

0 commit comments

Comments
 (0)