Skip to content

Commit 04767cd

Browse files
committed
Require at least one parameter in WithAudience, WithScope, WithResource
1 parent 6985315 commit 04767cd

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

credentials/options.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func WithGrantType(grantType string) Oauth2TokenExchangeCredentialsOption {
3636
}
3737

3838
// Resource
39-
func WithResource(resource ...string) Oauth2TokenExchangeCredentialsOption {
40-
return credentials.WithResource(resource...)
39+
func WithResource(resource string, resources ...string) Oauth2TokenExchangeCredentialsOption {
40+
return credentials.WithResource(resource, resources...)
4141
}
4242

4343
// RequestedTokenType
@@ -46,8 +46,8 @@ func WithRequestedTokenType(requestedTokenType string) Oauth2TokenExchangeCreden
4646
}
4747

4848
// Scope
49-
func WithScope(scope ...string) Oauth2TokenExchangeCredentialsOption {
50-
return credentials.WithScope(scope...)
49+
func WithScope(scope string, scopes ...string) Oauth2TokenExchangeCredentialsOption {
50+
return credentials.WithScope(scope, scopes...)
5151
}
5252

5353
// RequestTimeout
@@ -96,8 +96,8 @@ type oauthCredentialsAndJWTCredentialsOption interface {
9696
credentials.JWTTokenSourceOption
9797
}
9898

99-
func WithAudience(audience ...string) oauthCredentialsAndJWTCredentialsOption {
100-
return credentials.WithAudience(audience...)
99+
func WithAudience(audience string, audiences ...string) oauthCredentialsAndJWTCredentialsOption {
100+
return credentials.WithAudience(audience, audiences...)
101101
}
102102

103103
// Issuer

internal/credentials/oauth2.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ func WithGrantType(grantType string) grantTypeOption {
146146
type resourceOption []string
147147

148148
func (resource resourceOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error {
149-
c.resource = resource
149+
c.resource = append(c.resource, resource...)
150150

151151
return nil
152152
}
153153

154-
func WithResource(resource ...string) resourceOption {
155-
return resource
154+
func WithResource(resource string, resources ...string) resourceOption {
155+
return append([]string{resource}, resources...)
156156
}
157157

158158
// RequestedTokenType
@@ -172,26 +172,26 @@ func WithRequestedTokenType(requestedTokenType string) requestedTokenTypeOption
172172
type audienceOption []string
173173

174174
func (audience audienceOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error {
175-
c.audience = audience
175+
c.audience = append(c.audience, audience...)
176176

177177
return nil
178178
}
179179

180-
func WithAudience(audience ...string) audienceOption {
181-
return audience
180+
func WithAudience(audience string, audiences ...string) audienceOption {
181+
return append([]string{audience}, audiences...)
182182
}
183183

184184
// Scope
185185
type scopeOption []string
186186

187187
func (scope scopeOption) ApplyOauth2CredentialsOption(c *oauth2TokenExchange) error {
188-
c.scope = scope
188+
c.scope = append(c.scope, scope...)
189189

190190
return nil
191191
}
192192

193-
func WithScope(scope ...string) scopeOption {
194-
return scope
193+
func WithScope(scope string, scopes ...string) scopeOption {
194+
return append([]string{scope}, scopes...)
195195
}
196196

197197
// RequestTimeout
@@ -573,7 +573,7 @@ func (cfg *oauth2TokenSourceConfig) applyConfigFixedJWT(tokenSrcType int) (*toke
573573
}
574574

575575
if cfg.Audience != nil && len(cfg.Audience.Values) > 0 {
576-
opts = append(opts, WithAudience(cfg.Audience.Values...))
576+
opts = append(opts, WithAudience(cfg.Audience.Values[0], cfg.Audience.Values[1:]...))
577577
}
578578

579579
if cfg.ID != "" {
@@ -623,15 +623,15 @@ func (cfg *oauth2Config) applyConfig(opts *[]Oauth2TokenExchangeCredentialsOptio
623623
}
624624

625625
if cfg.Resource != nil && len(cfg.Resource.Values) > 0 {
626-
*opts = append(*opts, WithResource(cfg.Resource.Values...))
626+
*opts = append(*opts, WithResource(cfg.Resource.Values[0], cfg.Resource.Values[1:]...))
627627
}
628628

629629
if cfg.Audience != nil && len(cfg.Audience.Values) > 0 {
630-
*opts = append(*opts, WithAudience(cfg.Audience.Values...))
630+
*opts = append(*opts, WithAudience(cfg.Audience.Values[0], cfg.Audience.Values[1:]...))
631631
}
632632

633633
if cfg.Scope != nil && len(cfg.Scope.Values) > 0 {
634-
*opts = append(*opts, WithScope(cfg.Scope.Values...))
634+
*opts = append(*opts, WithScope(cfg.Scope.Values[0], cfg.Scope.Values[1:]...))
635635
}
636636

637637
if cfg.RequestedTokenType != "" {
@@ -1153,7 +1153,7 @@ func WithSubject(subject string) subjectOption {
11531153

11541154
// Audience
11551155
func (audience audienceOption) ApplyJWTTokenSourceOption(s *jwtTokenSource) error {
1156-
s.audience = audience
1156+
s.audience = append(s.audience, audience...)
11571157

11581158
return nil
11591159
}

0 commit comments

Comments
 (0)