Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom OIDC auth scenarios #111

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion config/development.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ auth:
- openid
- profile
- email
audience:
callbackUrl: http://localhost:8080/auth/sso/callback
passIdToken: false
options: # added as URL query params when redirecting to auth provider
audience: myorg-dev
organization: org_xxxxxxxxxxxx
invitation:
tls:
caFile:
certFile:
Expand Down
1 change: 0 additions & 1 deletion docker/config_template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ auth:
- openid
- profile
- email
audience:
passIdToken: false
18 changes: 9 additions & 9 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ type (
}

AuthProvider struct {
Label string `yaml:"label"`
Type string `yaml:"type"`
ProviderUrl string `yaml:"providerUrl"`
ClientID string `yaml:"clientId"`
ClientSecret string `yaml:"clientSecret"`
Scopes []string `yaml:"scopes"`
Audience string `yaml:"audience"`
CallbackURL string `yaml:"callbackUrl"`
PassIDToken bool `yaml:"passIdToken"`
Label string `yaml:"label"`
Type string `yaml:"type"`
ProviderUrl string `yaml:"providerUrl"`
ClientID string `yaml:"clientId"`
ClientSecret string `yaml:"clientSecret"`
Scopes []string `yaml:"scopes"`
CallbackURL string `yaml:"callbackUrl"`
PassIDToken bool `yaml:"passIdToken"`
Options map[string]interface{} `yaml:"options"`
}
)

Expand Down
28 changes: 22 additions & 6 deletions server/routes/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@ func SetAuthRoutes(e *echo.Echo, cfgProvider *config.ConfigProviderWithRefresh)
}

api := e.Group("/auth")
opts := []oauth2.AuthCodeOption{
oauth2.SetAuthURLParam("audience", providerCfg.Audience),
}
api.GET("/sso", authenticate(&config, opts))

api.GET("/sso", authenticate(&config, providerCfg.Options))
api.GET("/sso/callback", authenticateCb(ctx, &config, provider))
api.GET("/logout", logout)
}

func authenticate(config *oauth2.Config, opts []oauth2.AuthCodeOption) func(echo.Context) error {
func authenticate(config *oauth2.Config, options map[string]interface{}) func(echo.Context) error {
return func(c echo.Context) error {
state, err := randString()
if err != nil {
Expand All @@ -105,7 +103,25 @@ func authenticate(config *oauth2.Config, opts []oauth2.AuthCodeOption) func(echo
setCallbackCookie(c, "state", state)
setCallbackCookie(c, "nonce", nonce)

opts = append(opts, oidc.Nonce(nonce))
opts := []oauth2.AuthCodeOption{
oidc.Nonce(nonce),
}
for k, v := range options {
var value string
if vStr, ok := v.(string); ok {
value = vStr
}

// Some options, ex Auth0 invitation code, may be undefined in config as they are unknowns beforehand
// These may come from outside, ex in an invitation email
vOverride := c.QueryParam(k)
if vOverride != "" {
value = vOverride
}

opts = append(opts, oauth2.SetAuthURLParam(k, value))
}

url := config.AuthCodeURL(state, opts...)

return c.Redirect(http.StatusFound, url)
Expand Down