mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-29 05:05:42 +00:00
refactor: users are not a requirement when using oauth
This commit is contained in:
@@ -41,7 +41,10 @@ var rootCmd = &cobra.Command{
|
|||||||
// Users
|
// Users
|
||||||
log.Info().Msg("Parsing users")
|
log.Info().Msg("Parsing users")
|
||||||
users, usersErr := utils.GetUsers(config.Users, config.UsersFile)
|
users, usersErr := utils.GetUsers(config.Users, config.UsersFile)
|
||||||
HandleError(usersErr, "Failed to parse users")
|
|
||||||
|
if (len(users) == 0 || usersErr != nil) && !utils.OAuthConfigured(config) {
|
||||||
|
log.Fatal().Err(usersErr).Msg("Failed to parse users")
|
||||||
|
}
|
||||||
|
|
||||||
// Secrets
|
// Secrets
|
||||||
log.Info().Msg("Parsing secrets")
|
log.Info().Msg("Parsing secrets")
|
||||||
|
|||||||
@@ -194,6 +194,12 @@ func (api *API) SetupRoutes() {
|
|||||||
log.Debug().Msg("Checking status")
|
log.Debug().Msg("Checking status")
|
||||||
userContext := api.Hooks.UseUserContext(c)
|
userContext := api.Hooks.UseUserContext(c)
|
||||||
|
|
||||||
|
configuredProviders := api.Providers.GetConfiguredProviders()
|
||||||
|
|
||||||
|
if api.Auth.UserAuthConfigured() {
|
||||||
|
configuredProviders = append(configuredProviders, "username")
|
||||||
|
}
|
||||||
|
|
||||||
if !userContext.IsLoggedIn {
|
if !userContext.IsLoggedIn {
|
||||||
log.Debug().Msg("Unauthenticated")
|
log.Debug().Msg("Unauthenticated")
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
@@ -203,13 +209,13 @@ func (api *API) SetupRoutes() {
|
|||||||
"isLoggedIn": false,
|
"isLoggedIn": false,
|
||||||
"oauth": false,
|
"oauth": false,
|
||||||
"provider": "",
|
"provider": "",
|
||||||
"configuredProviders": api.Providers.GetConfiguredProviders(),
|
"configuredProviders": configuredProviders,
|
||||||
"disableContinue": api.Config.DisableContinue,
|
"disableContinue": api.Config.DisableContinue,
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug().Interface("userContext", userContext).Strs("configuredProviders", api.Providers.GetConfiguredProviders()).Bool("disableContinue", api.Config.DisableContinue).Msg("Authenticated")
|
log.Debug().Interface("userContext", userContext).Strs("configuredProviders", configuredProviders).Bool("disableContinue", api.Config.DisableContinue).Msg("Authenticated")
|
||||||
|
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
"status": 200,
|
"status": 200,
|
||||||
@@ -218,7 +224,7 @@ func (api *API) SetupRoutes() {
|
|||||||
"isLoggedIn": userContext.IsLoggedIn,
|
"isLoggedIn": userContext.IsLoggedIn,
|
||||||
"oauth": userContext.OAuth,
|
"oauth": userContext.OAuth,
|
||||||
"provider": userContext.Provider,
|
"provider": userContext.Provider,
|
||||||
"configuredProviders": api.Providers.GetConfiguredProviders(),
|
"configuredProviders": configuredProviders,
|
||||||
"disableContinue": api.Config.DisableContinue,
|
"disableContinue": api.Config.DisableContinue,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -88,3 +88,7 @@ func (auth *Auth) GetSessionCookie(c *gin.Context) (types.SessionCookie, error)
|
|||||||
Provider: provider,
|
Provider: provider,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (auth *Auth) UserAuthConfigured() bool {
|
||||||
|
return len(auth.Users) > 0
|
||||||
|
}
|
||||||
|
|||||||
@@ -129,3 +129,7 @@ func GetUsers(env string, file string) (types.Users, error) {
|
|||||||
|
|
||||||
return ParseUsers(users)
|
return ParseUsers(users)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func OAuthConfigured(config types.Config) bool {
|
||||||
|
return (config.GithubClientId != "" && config.GithubClientSecret != "") || (config.GoogleClientId != "" && config.GoogleClientSecret != "") || (config.GenericClientId != "" && config.GenericClientSecret != "")
|
||||||
|
}
|
||||||
|
|||||||
@@ -153,13 +153,16 @@ export const LoginPage = () => {
|
|||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
{configuredProviders.includes("username") && (
|
||||||
<Divider
|
<Divider
|
||||||
label="Or continue with password"
|
label="Or continue with password"
|
||||||
labelPosition="center"
|
labelPosition="center"
|
||||||
my="lg"
|
my="lg"
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
{configuredProviders.includes("username") && (
|
||||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||||
<TextInput
|
<TextInput
|
||||||
label="Username"
|
label="Username"
|
||||||
@@ -187,6 +190,7 @@ export const LoginPage = () => {
|
|||||||
Login
|
Login
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
)}
|
||||||
</Paper>
|
</Paper>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user