mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2025-10-30 05:35:44 +00:00
Compare commits
6 Commits
v4.0.0-alp
...
v4.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c307f7eb2e | ||
|
|
5dd8526833 | ||
|
|
e8558b89b4 | ||
|
|
f8047a6c2e | ||
|
|
e114bf0943 | ||
|
|
c9867ccb76 |
17
.env.example
17
.env.example
@@ -4,20 +4,6 @@ APP_URL=http://localhost:3000
|
|||||||
USERS=your_user_password_hash
|
USERS=your_user_password_hash
|
||||||
USERS_FILE=users_file
|
USERS_FILE=users_file
|
||||||
SECURE_COOKIE=false
|
SECURE_COOKIE=false
|
||||||
GITHUB_CLIENT_ID=github_client_id
|
|
||||||
GITHUB_CLIENT_SECRET=github_client_secret
|
|
||||||
GITHUB_CLIENT_SECRET_FILE=github_client_secret_file
|
|
||||||
GOOGLE_CLIENT_ID=google_client_id
|
|
||||||
GOOGLE_CLIENT_SECRET=google_client_secret
|
|
||||||
GOOGLE_CLIENT_SECRET_FILE=google_client_secret_file
|
|
||||||
GENERIC_CLIENT_ID=generic_client_id
|
|
||||||
GENERIC_CLIENT_SECRET=generic_client_secret
|
|
||||||
GENERIC_CLIENT_SECRET_FILE=generic_client_secret_file
|
|
||||||
GENERIC_SCOPES=generic_scopes
|
|
||||||
GENERIC_AUTH_URL=generic_auth_url
|
|
||||||
GENERIC_TOKEN_URL=generic_token_url
|
|
||||||
GENERIC_USER_URL=generic_user_url
|
|
||||||
DISABLE_CONTINUE=false
|
|
||||||
OAUTH_WHITELIST=
|
OAUTH_WHITELIST=
|
||||||
GENERIC_NAME=My OAuth
|
GENERIC_NAME=My OAuth
|
||||||
SESSION_EXPIRY=7200
|
SESSION_EXPIRY=7200
|
||||||
@@ -31,3 +17,6 @@ BACKGROUND_IMAGE=some_image_url
|
|||||||
GENERIC_SKIP_SSL=false
|
GENERIC_SKIP_SSL=false
|
||||||
RESOURCES_DIR=/data/resources
|
RESOURCES_DIR=/data/resources
|
||||||
DATABASE_PATH=/data/tinyauth.db
|
DATABASE_PATH=/data/tinyauth.db
|
||||||
|
DISABLE_ANALYTICS=false
|
||||||
|
DISABLE_RESOURCES=false
|
||||||
|
TRUSTED_PROXIES=
|
||||||
@@ -95,6 +95,7 @@ func init() {
|
|||||||
{"database-path", "/data/tinyauth.db", "Path to the Sqlite database file."},
|
{"database-path", "/data/tinyauth.db", "Path to the Sqlite database file."},
|
||||||
{"trusted-proxies", "", "Comma separated list of trusted proxies (IP addresses or CIDRs) for correct client IP detection."},
|
{"trusted-proxies", "", "Comma separated list of trusted proxies (IP addresses or CIDRs) for correct client IP detection."},
|
||||||
{"disable-analytics", false, "Disable anonymous version collection."},
|
{"disable-analytics", false, "Disable anonymous version collection."},
|
||||||
|
{"disable-resources", false, "Disable the resources server."},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, opt := range configOptions {
|
for _, opt := range configOptions {
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ var VerifyCmd = &cobra.Command{
|
|||||||
|
|
||||||
err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(iPassword))
|
err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(iPassword))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal().Msg("Ppassword is incorrect")
|
log.Fatal().Msg("Password is incorrect")
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.TotpSecret == "" {
|
if user.TotpSecret == "" {
|
||||||
|
|||||||
@@ -188,6 +188,10 @@ func (app *BootstrapApp) Setup() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create engine
|
// Create engine
|
||||||
|
if config.Version != "development" {
|
||||||
|
gin.SetMode(gin.ReleaseMode)
|
||||||
|
}
|
||||||
|
|
||||||
engine := gin.New()
|
engine := gin.New()
|
||||||
|
|
||||||
if len(app.config.TrustedProxies) > 0 {
|
if len(app.config.TrustedProxies) > 0 {
|
||||||
@@ -198,10 +202,6 @@ func (app *BootstrapApp) Setup() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Version != "development" {
|
|
||||||
gin.SetMode(gin.ReleaseMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create middlewares
|
// Create middlewares
|
||||||
var middlewares []Middleware
|
var middlewares []Middleware
|
||||||
|
|
||||||
@@ -255,7 +255,8 @@ func (app *BootstrapApp) Setup() error {
|
|||||||
}, apiRouter, authService)
|
}, apiRouter, authService)
|
||||||
|
|
||||||
resourcesController := controller.NewResourcesController(controller.ResourcesControllerConfig{
|
resourcesController := controller.NewResourcesController(controller.ResourcesControllerConfig{
|
||||||
ResourcesDir: app.config.ResourcesDir,
|
ResourcesDir: app.config.ResourcesDir,
|
||||||
|
ResourcesDisabled: app.config.DisableResources,
|
||||||
}, mainRouter)
|
}, mainRouter)
|
||||||
|
|
||||||
healthController := controller.NewHealthController(apiRouter)
|
healthController := controller.NewHealthController(apiRouter)
|
||||||
@@ -337,8 +338,8 @@ func (app *BootstrapApp) heartbeat() {
|
|||||||
|
|
||||||
res.Body.Close()
|
res.Body.Close()
|
||||||
|
|
||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 && res.StatusCode != 201 {
|
||||||
log.Debug().Str("status", res.Status).Msg("Heartbeat returned non-200 status")
|
log.Debug().Str("status", res.Status).Msg("Heartbeat returned non-200/201 status")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ type Config struct {
|
|||||||
DatabasePath string `mapstructure:"database-path" validate:"required"`
|
DatabasePath string `mapstructure:"database-path" validate:"required"`
|
||||||
TrustedProxies string `mapstructure:"trusted-proxies"`
|
TrustedProxies string `mapstructure:"trusted-proxies"`
|
||||||
DisableAnalytics bool `mapstructure:"disable-analytics"`
|
DisableAnalytics bool `mapstructure:"disable-analytics"`
|
||||||
|
DisableResources bool `mapstructure:"disable-resources"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// OAuth/OIDC config
|
// OAuth/OIDC config
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type ResourcesControllerConfig struct {
|
type ResourcesControllerConfig struct {
|
||||||
ResourcesDir string
|
ResourcesDir string
|
||||||
|
ResourcesDisabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourcesController struct {
|
type ResourcesController struct {
|
||||||
@@ -38,5 +39,12 @@ func (controller *ResourcesController) resourcesHandler(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if controller.config.ResourcesDisabled {
|
||||||
|
c.JSON(403, gin.H{
|
||||||
|
"status": 403,
|
||||||
|
"message": "Resources are disabled",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
controller.fileServer.ServeHTTP(c.Writer, c.Request)
|
controller.fileServer.ServeHTTP(c.Writer, c.Request)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func (broker *OAuthBrokerService) Init() error {
|
|||||||
log.Error().Err(err).Msgf("Failed to initialize OAuth service: %T", name)
|
log.Error().Err(err).Msgf("Failed to initialize OAuth service: %T", name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Info().Msgf("Initialized OAuth service: %T", name)
|
log.Info().Str("service", service.GetName()).Msg("Initialized OAuth service")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -18,10 +18,14 @@ func NormalizeKeys(keys map[string]string, rootName string, sep string) map[stri
|
|||||||
|
|
||||||
finalKey = append(finalKey, rootName)
|
finalKey = append(finalKey, rootName)
|
||||||
finalKey = append(finalKey, "providers")
|
finalKey = append(finalKey, "providers")
|
||||||
cebabKey := strings.ToLower(k)
|
lowerKey := strings.ToLower(k)
|
||||||
|
|
||||||
|
if !strings.HasPrefix(lowerKey, "providers"+sep) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
for _, known := range knownKeys {
|
for _, known := range knownKeys {
|
||||||
if strings.HasSuffix(cebabKey, strings.ReplaceAll(known, "-", sep)) {
|
if strings.HasSuffix(lowerKey, strings.ReplaceAll(known, "-", sep)) {
|
||||||
suffix = known
|
suffix = known
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -31,7 +35,11 @@ func NormalizeKeys(keys map[string]string, rootName string, sep string) map[stri
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
clientNameParts := strings.Split(strings.TrimPrefix(strings.TrimSuffix(cebabKey, sep+strings.ReplaceAll(suffix, "-", sep)), "providers"+sep), sep)
|
if strings.TrimSpace(strings.TrimSuffix(strings.TrimPrefix(lowerKey, "providers"+sep), strings.ReplaceAll(suffix, "-", sep))) == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
clientNameParts := strings.Split(strings.TrimPrefix(strings.TrimSuffix(lowerKey, sep+strings.ReplaceAll(suffix, "-", sep)), "providers"+sep), sep)
|
||||||
|
|
||||||
for i, p := range clientNameParts {
|
for i, p := range clientNameParts {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
@@ -46,9 +54,9 @@ func NormalizeKeys(keys map[string]string, rootName string, sep string) map[stri
|
|||||||
|
|
||||||
finalKey = append(finalKey, camelClientName)
|
finalKey = append(finalKey, camelClientName)
|
||||||
|
|
||||||
filedParts := strings.Split(suffix, "-")
|
fieldParts := strings.Split(suffix, "-")
|
||||||
|
|
||||||
for i, p := range filedParts {
|
for i, p := range fieldParts {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
camelField += p
|
camelField += p
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ func TestNormalizeKeys(t *testing.T) {
|
|||||||
"PROVIDERS_CLIENT1_CLIENT_SECRET": "my-client-secret",
|
"PROVIDERS_CLIENT1_CLIENT_SECRET": "my-client-secret",
|
||||||
"PROVIDERS_MY_AWESOME_CLIENT_CLIENT_ID": "my-awesome-client-id",
|
"PROVIDERS_MY_AWESOME_CLIENT_CLIENT_ID": "my-awesome-client-id",
|
||||||
"PROVIDERS_MY_AWESOME_CLIENT_CLIENT_SECRET_FILE": "/path/to/secret",
|
"PROVIDERS_MY_AWESOME_CLIENT_CLIENT_SECRET_FILE": "/path/to/secret",
|
||||||
|
"I_LOOK_LIKE_A_KEY_CLIENT_ID": "should-not-appear",
|
||||||
|
"PROVIDERS_CLIENT_ID": "should-not-appear",
|
||||||
}
|
}
|
||||||
expected := map[string]string{
|
expected := map[string]string{
|
||||||
"tinyauth.providers.client1.clientId": "my-client-id",
|
"tinyauth.providers.client1.clientId": "my-client-id",
|
||||||
@@ -31,6 +33,9 @@ func TestNormalizeKeys(t *testing.T) {
|
|||||||
"providers-client1-client-secret": "my-client-secret",
|
"providers-client1-client-secret": "my-client-secret",
|
||||||
"providers-my-awesome-client-client-id": "my-awesome-client-id",
|
"providers-my-awesome-client-client-id": "my-awesome-client-id",
|
||||||
"providers-my-awesome-client-client-secret-file": "/path/to/secret",
|
"providers-my-awesome-client-client-secret-file": "/path/to/secret",
|
||||||
|
"providers-should-not-appear-client": "should-not-appear",
|
||||||
|
"i-look-like-a-key-client-id": "should-not-appear",
|
||||||
|
"providers-client-id": "should-not-appear",
|
||||||
}
|
}
|
||||||
expected = map[string]string{
|
expected = map[string]string{
|
||||||
"tinyauth.providers.client1.clientId": "my-client-id",
|
"tinyauth.providers.client1.clientId": "my-client-id",
|
||||||
|
|||||||
Reference in New Issue
Block a user