Skip to content

Commit 085f625

Browse files
committed
fix: fix oauth group provider check
1 parent c307f7e commit 085f625

4 files changed

Lines changed: 17 additions & 15 deletions

File tree

‎internal/bootstrap/app_bootstrap.go‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ func (app *BootstrapApp) Setup() error {
147147
}
148148

149149
// Configured providers
150-
babysit := map[string]string{
151-
"google": "Google",
152-
"github": "GitHub",
153-
}
154150
configuredProviders := make([]controller.Provider, 0)
155151

156152
for id, provider := range oauthProviders {
@@ -159,7 +155,7 @@ func (app *BootstrapApp) Setup() error {
159155
}
160156

161157
if provider.Name == "" {
162-
if name, ok := babysit[id]; ok {
158+
if name, ok := config.OverrideProviders[id]; ok {
163159
provider.Name = name
164160
} else {
165161
provider.Name = utils.Capitalize(id)

‎internal/config/config.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ type OAuthServiceConfig struct {
6565
Name string `key:"name"`
6666
}
6767

68+
var OverrideProviders = map[string]string{
69+
"google": "Google",
70+
"github": "GitHub",
71+
}
72+
6873
// User/session related stuff
6974

7075
type User struct {

‎internal/service/auth_service.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,14 @@ func (auth *AuthService) IsInOAuthGroup(c *gin.Context, context config.UserConte
309309
return true
310310
}
311311

312-
if context.Provider != "generic" {
313-
log.Debug().Msg("Not using generic provider, skipping group check")
314-
return true
312+
for id := range config.OverrideProviders {
313+
if context.Provider == id {
314+
log.Info().Str("provider", id).Msg("OAuth groups not supported for this provider")
315+
return true
316+
}
315317
}
316318

317-
for _, userGroup := range strings.Split(context.OAuthGroups, ",") {
319+
for userGroup := range strings.SplitSeq(context.OAuthGroups, ",") {
318320
if utils.CheckFilter(requiredGroups, strings.TrimSpace(userGroup)) {
319321
return true
320322
}

‎internal/utils/app_utils.go‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,13 @@ func GetOAuthProvidersConfig(env []string, args []string, appUrl string) (map[st
183183
providers[name] = provider
184184
}
185185

186-
// If we have google/github providers and no redirect URL babysit them
187-
babysitProviders := []string{"google", "github"}
186+
// If we have google/github providers and no redirect URL then set a default
188187

189-
for _, name := range babysitProviders {
190-
if provider, exists := providers[name]; exists {
188+
for id := range config.OverrideProviders {
189+
if provider, exists := providers[id]; exists {
191190
if provider.RedirectURL == "" {
192-
provider.RedirectURL = appUrl + "/api/oauth/callback/" + name
193-
providers[name] = provider
191+
provider.RedirectURL = appUrl + "/api/oauth/callback/" + id
192+
providers[id] = provider
194193
}
195194
}
196195
}

0 commit comments

Comments
 (0)