Skip to content

Commit

Permalink
Added audience override for token sent to authorization server
Browse files Browse the repository at this point in the history
  • Loading branch information
davidallendj committed Apr 29, 2024
1 parent 20ba7bc commit c67c6f7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type TokenOptions struct {
Forwarding bool `yaml:"forwarding"`
Refresh bool `yaml:"refresh"`
Scope []string `yaml:"scope"`
//TODO: allow specifying audience in returned token
}

type Authentication struct {
Expand All @@ -55,9 +56,10 @@ type Authentication struct {
}

type Authorization struct {
Token TokenOptions `yaml:"token"`
Endpoints Endpoints `yaml:"endpoints"`
KeyPath string `yaml:"key-path"`
Token TokenOptions `yaml:"token"`
Audience []string `yaml:"audience"` // NOTE: overrides the "aud" claim in token sent to authorization server
}

type Config struct {
Expand Down
6 changes: 6 additions & 0 deletions internal/flows/jwt_bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type JwtBearerFlowParams struct {
// IdentityProvider *oidc.IdentityProvider
TrustedIssuer *oauth.TrustedIssuer
Client *oauth.Client
Audience []string
Refresh bool
Verbose bool
KeyPath string
Expand Down Expand Up @@ -143,6 +144,11 @@ func NewJwtBearerFlow(eps JwtBearerFlowEndpoints, params JwtBearerFlowParams) (s
payload["exp"] = time.Now().Add(time.Second * 3600 * 16).Unix()
payload["sub"] = "opaal"

// if an "audience" value is set, then override the token endpoint value
if len(params.Audience) > 0 {
payload["aud"] = params.Audience
}

// include the offline_access scope if refresh tokens are enabled
if params.Refresh {
v, ok := payload["scope"]
Expand Down
5 changes: 3 additions & 2 deletions internal/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ func Login(config *Config) error {
ExpiresAt: time.Now().Add(config.Authorization.Token.Duration),
Scope: []string{},
},
Verbose: config.Options.Verbose,
Refresh: config.Authorization.Token.Refresh,
Verbose: config.Options.Verbose,
Refresh: config.Authorization.Token.Refresh,
Audience: config.Authorization.Audience,
},
ClientCredentialsEndpoints: flows.ClientCredentialsFlowEndpoints{
Clients: config.Authorization.Endpoints.Clients,
Expand Down

0 comments on commit c67c6f7

Please sign in to comment.