mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-28 04:35:40 +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,40 +153,44 @@ export const LoginPage = () => {
|
|||||||
</Grid.Col>
|
</Grid.Col>
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
<Divider
|
{configuredProviders.includes("username") && (
|
||||||
label="Or continue with password"
|
<Divider
|
||||||
labelPosition="center"
|
label="Or continue with password"
|
||||||
my="lg"
|
labelPosition="center"
|
||||||
/>
|
my="lg"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
{configuredProviders.includes("username") && (
|
||||||
<TextInput
|
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||||
label="Username"
|
<TextInput
|
||||||
placeholder="user@example.com"
|
label="Username"
|
||||||
required
|
placeholder="user@example.com"
|
||||||
disabled={loginMutation.isLoading}
|
required
|
||||||
key={form.key("username")}
|
disabled={loginMutation.isLoading}
|
||||||
{...form.getInputProps("username")}
|
key={form.key("username")}
|
||||||
/>
|
{...form.getInputProps("username")}
|
||||||
<PasswordInput
|
/>
|
||||||
label="Password"
|
<PasswordInput
|
||||||
placeholder="password"
|
label="Password"
|
||||||
required
|
placeholder="password"
|
||||||
mt="md"
|
required
|
||||||
disabled={loginMutation.isLoading}
|
mt="md"
|
||||||
key={form.key("password")}
|
disabled={loginMutation.isLoading}
|
||||||
{...form.getInputProps("password")}
|
key={form.key("password")}
|
||||||
/>
|
{...form.getInputProps("password")}
|
||||||
<Button
|
/>
|
||||||
fullWidth
|
<Button
|
||||||
mt="xl"
|
fullWidth
|
||||||
type="submit"
|
mt="xl"
|
||||||
loading={loginMutation.isLoading}
|
type="submit"
|
||||||
>
|
loading={loginMutation.isLoading}
|
||||||
Login
|
>
|
||||||
</Button>
|
Login
|
||||||
</form>
|
</Button>
|
||||||
|
</form>
|
||||||
|
)}
|
||||||
</Paper>
|
</Paper>
|
||||||
</Layout>
|
</Layout>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user