Skip to content

Commit

Permalink
feat: go template for introspect response (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdbulcke committed Aug 28, 2023
1 parent d05a577 commit 443453f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
31 changes: 26 additions & 5 deletions example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,28 @@ supported_scopes:
# ### Default: 5m
# # sync_duration: 1h





## Instropect Response Template (optional)
### since v0.8.0
### format: map[string]interface{}
### Use go template https://pkg.go.dev/text/template
### syntax to template string properties on introspect
### response based on claims from Access or Refresh token
### WARNING: go template only works with string value
introspect_response_template:
## template standard claims
## https://www.rfc-editor.org/rfc/rfc7662.html#section-2.2
client_id: "{{index .aud 0}}"
user_id: "{{ .sub }}"
username: "{{ .sub }}"

## works as well with static properties
foo:
- bar
- baz



## Default Mock User (Mandatory)
Expand Down Expand Up @@ -143,10 +164,10 @@ mock_user:
### Arbitrary key/values claims to
### add in the refresh_token
### since v0.7.0
refresh_token_claims:
foo:
- hello: world
- bar: baz
# refresh_token_claims:
# foo:
# - hello: world
# - bar: baz

## Userinfo Claims (optional)
### Arbitrary key/values claims to
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ require (
)

// from github.com/vdbulcke/mockoidc upstream branch
replace github.com/oauth2-proxy/mockoidc => github.com/vdbulcke/mockoidc v0.6.0
replace github.com/oauth2-proxy/mockoidc => github.com/vdbulcke/mockoidc v0.7.0

// replace github.com/oauth2-proxy/mockoidc => ../mockoidc
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/vdbulcke/mockoidc v0.6.0 h1:c0gjdd4mpojSD3kRyptQrDT0MX2vLPRcEV34MumBz+4=
github.com/vdbulcke/mockoidc v0.6.0/go.mod h1:/qmWJ3hthh1lAi2hIqQ3o6/4t6uYvOXvm+SpetkTcrY=
github.com/vdbulcke/mockoidc v0.7.0 h1:DCEJOtnSTqhNUF0bQOtiuYrcQ3b06HsSnH0F69YjmnU=
github.com/vdbulcke/mockoidc v0.7.0/go.mod h1:/qmWJ3hthh1lAi2hIqQ3o6/4t6uYvOXvm+SpetkTcrY=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
Expand Down
7 changes: 4 additions & 3 deletions src/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ type OIDCServerConfig struct {
// Folder where to find mocked user if not defined the user in mock_user will be returned
MockUserFolder string `yaml:"mock_user_folder"`

IssueNewRefreshTokenOnRefreshToken bool `yaml:"issue_new_refresh_token_on_refresh_token" default:"false" `
AccessTokenTTL time.Duration `yaml:"access_token_ttl_duration" default:"10m" validate:"required"`
RefreshTokenTTL time.Duration `yaml:"refresh_token_ttl_duration" default:"1h" validate:"required"`
IssueNewRefreshTokenOnRefreshToken bool `yaml:"issue_new_refresh_token_on_refresh_token" default:"false" `
AccessTokenTTL time.Duration `yaml:"access_token_ttl_duration" default:"10m" validate:"required"`
RefreshTokenTTL time.Duration `yaml:"refresh_token_ttl_duration" default:"1h" validate:"required"`
IntrospectTemplate map[string]interface{} `yaml:"introspect_response_template,omitempty" `

// Listen Address
ListenAddress string
Expand Down
1 change: 1 addition & 0 deletions src/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func NewOIDCServer(l *zap.Logger, c *cfg.OIDCServerConfig) (*OIDCServer, error)
if c.IssueNewRefreshTokenOnRefreshToken {
m.EnableIssueNewRefreshTokenOnRefreshToken()
}
m.SetIntrospectTemplate(c.IntrospectTemplate)

return &OIDCServer{
logger: l,
Expand Down

0 comments on commit 443453f

Please sign in to comment.