Skip to content

Commit

Permalink
Add feature flag for checking hosted domain (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuscscp committed May 12, 2020
1 parent 07ca099 commit d2f0e1c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
9 changes: 5 additions & 4 deletions api/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ func (a *App) configureJaeger() error {
func (a *App) configureGoogleOAuth2Provider() {
repo := repositories.New(a.storage)
google := oauth2.NewGoogle(oauth2.GoogleConfig{
ClientID: a.config.GetString("oauth2.google.clientId"),
ClientSecret: a.config.GetString("oauth2.google.clientSecret"),
RedirectURL: a.config.GetString("oauth2.google.redirectUrl"),
HostedDomains: a.config.GetStringSlice("oauth2.google.hostedDomains"),
ClientID: a.config.GetString("oauth2.google.clientId"),
ClientSecret: a.config.GetString("oauth2.google.clientSecret"),
RedirectURL: a.config.GetString("oauth2.google.redirectUrl"),
CheckHostedDomain: a.config.GetBool("oauth2.google.checkHostedDomain"),
HostedDomains: a.config.GetStringSlice("oauth2.google.hostedDomains"),
}, repo)
a.oauth2Provider = google
}
Expand Down
1 change: 1 addition & 0 deletions config/local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ oauth2:
clientId: dummy
clientSecret: dummy
redirectUrl: dummy
checkHostedDomain: true
hostedDomains:
- domain1
- domain2
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ services:
- "postgres"
- "-c"
- "max_connections=9999"
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
11 changes: 6 additions & 5 deletions oauth2/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ const userEndpoint = "https://www.googleapis.com/oauth2/v2/userinfo"
// GoogleConfig are the basic required informations to use Google
// as oauth2 provider
type GoogleConfig struct {
ClientID string
ClientSecret string
RedirectURL string
HostedDomains []string
ClientID string
ClientSecret string
RedirectURL string
CheckHostedDomain bool
HostedDomains []string
}

var googleConfig GoogleConfig
Expand Down Expand Up @@ -196,7 +197,7 @@ func (g *Google) getUserInfo(accessToken string) (*userInfo, error) {
}

func (g *Google) checkHostedDomain(hd string) bool {
if g.config.HostedDomains == nil || len(g.config.HostedDomains) == 0 {
if !g.config.CheckHostedDomain || g.config.HostedDomains == nil || len(g.config.HostedDomains) == 0 {
return true
}
for _, allowed := range g.config.HostedDomains {
Expand Down

0 comments on commit d2f0e1c

Please sign in to comment.