refactor to improve database operability in hwsauth
This commit is contained in:
@@ -6,22 +6,31 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Config holds the configuration settings for the authenticator.
|
||||
// All time-based settings are in minutes.
|
||||
type Config struct {
|
||||
SSL bool // ENV HWSAUTH_SSL: Flag for SSL Mode (default: false)
|
||||
TrustedHost string // ENV HWSAUTH_TRUSTED_HOST: Full server address to accept as trusted SSL host (required if SSL is true)
|
||||
SecretKey string // ENV HWSAUTH_SECRET_KEY: Secret key for signing tokens (required)
|
||||
SSL bool // ENV HWSAUTH_SSL: Enable SSL secure cookies (default: false)
|
||||
TrustedHost string // ENV HWSAUTH_TRUSTED_HOST: Full server address for SSL (required if SSL is true)
|
||||
SecretKey string // ENV HWSAUTH_SECRET_KEY: Secret key for signing JWT tokens (required)
|
||||
AccessTokenExpiry int64 // ENV HWSAUTH_ACCESS_TOKEN_EXPIRY: Access token expiry in minutes (default: 5)
|
||||
RefreshTokenExpiry int64 // ENV HWSAUTH_REFRESH_TOKEN_EXPIRY: Refresh token expiry in minutes (default: 1440)
|
||||
TokenFreshTime int64 // ENV HWSAUTH_TOKEN_FRESH_TIME: Time for tokens to stay fresh in minutes (default: 5)
|
||||
LandingPage string // ENV HWSAUTH_LANDING_PAGE: Path of the desired landing page for logged in users (default: "/profile")
|
||||
TokenFreshTime int64 // ENV HWSAUTH_TOKEN_FRESH_TIME: Token fresh time in minutes (default: 5)
|
||||
LandingPage string // ENV HWSAUTH_LANDING_PAGE: Redirect destination for authenticated users (default: "/profile")
|
||||
DatabaseType string // ENV HWSAUTH_DATABASE_TYPE: Database type (postgres, mysql, sqlite, mariadb) (default: "postgres")
|
||||
DatabaseVersion string // ENV HWSAUTH_DATABASE_VERSION: Database version (default: "15")
|
||||
JWTTableName string // ENV HWSAUTH_JWT_TABLE_NAME: JWT blacklist table name (default: "jwtblacklist")
|
||||
DatabaseVersion string // ENV HWSAUTH_DATABASE_VERSION: Database version string (default: "15")
|
||||
JWTTableName string // ENV HWSAUTH_JWT_TABLE_NAME: Custom JWT blacklist table name (default: "jwtblacklist")
|
||||
}
|
||||
|
||||
// ConfigFromEnv loads configuration from environment variables.
|
||||
//
|
||||
// Required environment variables:
|
||||
// - HWSAUTH_SECRET_KEY: Secret key for JWT signing
|
||||
// - HWSAUTH_TRUSTED_HOST: Required if HWSAUTH_SSL is true
|
||||
//
|
||||
// Returns an error if required variables are missing or invalid.
|
||||
func ConfigFromEnv() (*Config, error) {
|
||||
ssl := env.Bool("HWSAUTH_SSL", false)
|
||||
trustedHost := env.String("HWS_TRUSTED_HOST", "")
|
||||
trustedHost := env.String("HWSAUTH_TRUSTED_HOST", "")
|
||||
if ssl && trustedHost == "" {
|
||||
return nil, errors.New("SSL is enabled and no HWS_TRUSTED_HOST set")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user