Skip to content

Commit 37948f7

Browse files
authored
Add audience flag (#60)
1 parent e344994 commit 37948f7

File tree

6 files changed

+25
-2
lines changed

6 files changed

+25
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ The available flags are:
7676
--actor-token string acting party token
7777
--actor-token-type string acting party token type
7878
--assertion string claims for jwt bearer assertion
79+
--audience strings requested audience
7980
--auth-method string token endpoint authentication method
81+
--claims string claims parameter
8082
--client-id string client identifier
8183
--client-secret string client secret
8284
--dpop use DPoP

cmd/log.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func LogInputData(cc oauth2.ClientConfig) {
9292
{"Grant type", cc.GrantType},
9393
{"Auth method", cc.AuthMethod},
9494
{"Scopes", strings.Join(cc.Scopes, ", ")},
95+
{"Audience", strings.Join(cc.Audience, ", ")},
9596
{"Response types", strings.Join(cc.ResponseType, ", ")},
9697
{"Response mode", cc.ResponseMode},
9798
{"PKCE", strconv.FormatBool(cc.PKCE)},

cmd/oauth2.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func NewOAuth2Cmd() (cmd *OAuth2Cmd) {
5252
cmd.PersistentFlags().StringSliceVar(&cconfig.ResponseType, "response-types", []string{""}, "response type")
5353
cmd.PersistentFlags().StringVar(&cconfig.ResponseMode, "response-mode", "", "response mode")
5454
cmd.PersistentFlags().StringSliceVar(&cconfig.Scopes, "scopes", []string{}, "requested scopes")
55+
cmd.PersistentFlags().StringSliceVar(&cconfig.Audience, "audience", []string{}, "requested audience")
5556
cmd.PersistentFlags().BoolVar(&cconfig.PKCE, "pkce", false, "enable proof key for code exchange (PKCE)")
5657
cmd.PersistentFlags().BoolVar(&cconfig.PAR, "par", false, "enable pushed authorization requests (PAR)")
5758
cmd.PersistentFlags().BoolVar(&cconfig.RequestObject, "request-object", false, "pass request parameters as jwt")

internal/oauth2/oauth2.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type ClientConfig struct {
6060
ClientID string
6161
ClientSecret string
6262
Scopes []string
63+
Audience []string
6364
AuthMethod string
6465
PKCE bool
6566
PAR bool
@@ -359,8 +360,14 @@ func RequestToken(
359360
}
360361

361362
switch cconfig.GrantType {
362-
case ClientCredentialsGrantType, PasswordGrantType, RefreshTokenGrantType, JWTBearerGrantType:
363-
request.Form.Set("scope", strings.Join(cconfig.Scopes, " "))
363+
case ClientCredentialsGrantType, PasswordGrantType, RefreshTokenGrantType, JWTBearerGrantType, TokenExchangeGrantType:
364+
if len(cconfig.Scopes) > 0 {
365+
request.Form.Set("scope", strings.Join(cconfig.Scopes, " "))
366+
}
367+
368+
if len(cconfig.Audience) > 0 {
369+
request.Form.Set("audience", strings.Join(cconfig.Audience, " "))
370+
}
364371
}
365372

366373
switch cconfig.GrantType {

internal/oauth2/oauth2_device.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func RequestDeviceAuthorization(ctx context.Context, cconfig ClientConfig, sconf
3232
request.Form.Set("scope", strings.Join(cconfig.Scopes, " "))
3333
}
3434

35+
if len(cconfig.Audience) > 0 {
36+
request.Form.Set("audience", strings.Join(cconfig.Audience, " "))
37+
}
38+
3539
if req, err = http.NewRequestWithContext(
3640
ctx,
3741
http.MethodPost,

internal/oauth2/request.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ func (r *Request) AuthorizeRequest(
4949
r.Form.Set("scope", strings.Join(cconfig.Scopes, " "))
5050
}
5151

52+
if len(cconfig.Audience) > 0 {
53+
r.Form.Set("audience", strings.Join(cconfig.Audience, " "))
54+
}
55+
5256
if cconfig.IDTokenHint != "" {
5357
r.Form.Set("id_token_hint", cconfig.IDTokenHint)
5458
}
@@ -112,6 +116,10 @@ func (r *Request) AuthorizeRequest(
112116
if len(cconfig.Scopes) > 0 {
113117
r.Form.Set("scope", strings.Join(cconfig.Scopes, " "))
114118
}
119+
120+
if len(cconfig.Audience) > 0 {
121+
r.Form.Set("audience", strings.Join(cconfig.Audience, " "))
122+
}
115123
}
116124

117125
if cconfig.DPoP {

0 commit comments

Comments
 (0)