mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-11-03 23:55:44 +00:00 
			
		
		
		
	Compare commits
	
		
			8 Commits
		
	
	
		
			feat/new-u
			...
			feat/untru
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					f441645e36 | ||
| 
						 | 
					35ae69791c | ||
| 
						 | 
					1dfa54305f | ||
| 
						 | 
					3c3bd719db | ||
| 
						 | 
					a6aa97bcfa | ||
| 
						 | 
					1a7b6cfb99 | ||
| 
						 | 
					da7cebdfed | ||
| 
						 | 
					318f00993e | 
@@ -30,3 +30,4 @@ APP_TITLE=Tinyauth SSO
 | 
				
			|||||||
FORGOT_PASSWORD_MESSAGE=Some message about resetting the password
 | 
					FORGOT_PASSWORD_MESSAGE=Some message about resetting the password
 | 
				
			||||||
OAUTH_AUTO_REDIRECT=none
 | 
					OAUTH_AUTO_REDIRECT=none
 | 
				
			||||||
BACKGROUND_IMAGE=some_image_url
 | 
					BACKGROUND_IMAGE=some_image_url
 | 
				
			||||||
 | 
					GENERIC_SKIP_SSL=false
 | 
				
			||||||
@@ -52,7 +52,4 @@ COPY --from=builder /tinyauth/tinyauth ./
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
EXPOSE 3000
 | 
					EXPOSE 3000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
HEALTHCHECK --interval=10s --timeout=5s \
 | 
					 | 
				
			||||||
    CMD curl -f http://localhost:3000/api/healthcheck || exit 1
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
ENTRYPOINT ["./tinyauth"]
 | 
					ENTRYPOINT ["./tinyauth"]
 | 
				
			||||||
							
								
								
									
										12
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								README.md
									
									
									
									
									
								
							@@ -24,18 +24,22 @@ Tinyauth is a simple authentication middleware that adds simple username/passwor
 | 
				
			|||||||
> [!NOTE]
 | 
					> [!NOTE]
 | 
				
			||||||
> Tinyauth is intended for homelab use only and it is not made for production use cases. If you are looking for something production ready please use [authentik](https://goauthentik.io) instead.
 | 
					> Tinyauth is intended for homelab use only and it is not made for production use cases. If you are looking for something production ready please use [authentik](https://goauthentik.io) instead.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Discord
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
I just made a Discord server for tinyauth! It is not only for tinyauth but general self-hosting and homelabbing. [See you there!](https://discord.gg/eHzVaCzRRd).
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
## Getting Started
 | 
					## Getting Started
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can easily get started with tinyauth by following the guide in the [documentation](https://tinyauth.app/docs/getting-started.html). There is also an available [docker compose file](./docker-compose.example.yml) that has traefik, whoami and tinyauth to demonstrate its capabilities.
 | 
					You can easily get started with tinyauth by following the guide in the [documentation](https://tinyauth.app/docs/getting-started.html). There is also an available [docker compose file](./docker-compose.example.yml) that has traefik, whoami and tinyauth to demonstrate its capabilities.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Demo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					If you are still not sure if tinyauth suits your needs you can try out the [demo](https://demo.tinyauth.app). The default username is `user` and the default password is `password`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Documentation
 | 
					## Documentation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
You can find documentation and guides on all of the available configuration of tinyauth in the [website](https://tinyauth.app).
 | 
					You can find documentation and guides on all of the available configuration of tinyauth in the [website](https://tinyauth.app).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## Discord
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					I just made a Discord server for tinyauth! It is not only for tinyauth but general self-hosting and homelabbing. [See you there!](https://discord.gg/eHzVaCzRRd).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Contributing
 | 
					## Contributing
 | 
				
			||||||
 | 
					
 | 
				
			||||||
All contributions to the codebase are welcome! If you have any recommendations on how to improve security or find a security issue in tinyauth please open an issue or pull request so it can be fixed as soon as possible!
 | 
					All contributions to the codebase are welcome! If you have any recommendations on how to improve security or find a security issue in tinyauth please open an issue or pull request so it can be fixed as soon as possible!
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -79,6 +79,7 @@ var rootCmd = &cobra.Command{
 | 
				
			|||||||
			GenericAuthURL:      config.GenericAuthURL,
 | 
								GenericAuthURL:      config.GenericAuthURL,
 | 
				
			||||||
			GenericTokenURL:     config.GenericTokenURL,
 | 
								GenericTokenURL:     config.GenericTokenURL,
 | 
				
			||||||
			GenericUserURL:      config.GenericUserURL,
 | 
								GenericUserURL:      config.GenericUserURL,
 | 
				
			||||||
 | 
								GenericSkipSSL:      config.GenericSkipSSL,
 | 
				
			||||||
			AppURL:              config.AppURL,
 | 
								AppURL:              config.AppURL,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -197,6 +198,7 @@ func init() {
 | 
				
			|||||||
	rootCmd.Flags().String("generic-token-url", "", "Generic OAuth token URL.")
 | 
						rootCmd.Flags().String("generic-token-url", "", "Generic OAuth token URL.")
 | 
				
			||||||
	rootCmd.Flags().String("generic-user-url", "", "Generic OAuth user info URL.")
 | 
						rootCmd.Flags().String("generic-user-url", "", "Generic OAuth user info URL.")
 | 
				
			||||||
	rootCmd.Flags().String("generic-name", "Generic", "Generic OAuth provider name.")
 | 
						rootCmd.Flags().String("generic-name", "Generic", "Generic OAuth provider name.")
 | 
				
			||||||
 | 
						rootCmd.Flags().Bool("generic-skip-ssl", false, "Skip SSL verification for the generic OAuth provider.")
 | 
				
			||||||
	rootCmd.Flags().Bool("disable-continue", false, "Disable continue screen and redirect to app directly.")
 | 
						rootCmd.Flags().Bool("disable-continue", false, "Disable continue screen and redirect to app directly.")
 | 
				
			||||||
	rootCmd.Flags().String("oauth-whitelist", "", "Comma separated list of email addresses to whitelist when using OAuth.")
 | 
						rootCmd.Flags().String("oauth-whitelist", "", "Comma separated list of email addresses to whitelist when using OAuth.")
 | 
				
			||||||
	rootCmd.Flags().String("oauth-auto-redirect", "none", "Auto redirect to the specified OAuth provider if configured. (available providers: github, google, generic)")
 | 
						rootCmd.Flags().String("oauth-auto-redirect", "none", "Auto redirect to the specified OAuth provider if configured. (available providers: github, google, generic)")
 | 
				
			||||||
@@ -231,6 +233,7 @@ func init() {
 | 
				
			|||||||
	viper.BindEnv("generic-token-url", "GENERIC_TOKEN_URL")
 | 
						viper.BindEnv("generic-token-url", "GENERIC_TOKEN_URL")
 | 
				
			||||||
	viper.BindEnv("generic-user-url", "GENERIC_USER_URL")
 | 
						viper.BindEnv("generic-user-url", "GENERIC_USER_URL")
 | 
				
			||||||
	viper.BindEnv("generic-name", "GENERIC_NAME")
 | 
						viper.BindEnv("generic-name", "GENERIC_NAME")
 | 
				
			||||||
 | 
						viper.BindEnv("generic-skip-ssl", "GENERIC_SKIP_SSL")
 | 
				
			||||||
	viper.BindEnv("disable-continue", "DISABLE_CONTINUE")
 | 
						viper.BindEnv("disable-continue", "DISABLE_CONTINUE")
 | 
				
			||||||
	viper.BindEnv("oauth-whitelist", "OAUTH_WHITELIST")
 | 
						viper.BindEnv("oauth-whitelist", "OAUTH_WHITELIST")
 | 
				
			||||||
	viper.BindEnv("oauth-auto-redirect", "OAUTH_AUTO_REDIRECT")
 | 
						viper.BindEnv("oauth-auto-redirect", "OAUTH_AUTO_REDIRECT")
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,7 @@ export const LoginPage = () => {
 | 
				
			|||||||
    return <Navigate to="/logout" />;
 | 
					    return <Navigate to="/logout" />;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { configuredProviders, title, oauthAutoRedirect } = useAppContext();
 | 
					  const { configuredProviders, title, oauthAutoRedirect, genericName } = useAppContext();
 | 
				
			||||||
  const { search } = useLocation();
 | 
					  const { search } = useLocation();
 | 
				
			||||||
  const { t } = useTranslation();
 | 
					  const { t } = useTranslation();
 | 
				
			||||||
  const isMounted = useIsMounted();
 | 
					  const isMounted = useIsMounted();
 | 
				
			||||||
@@ -138,7 +138,7 @@ export const LoginPage = () => {
 | 
				
			|||||||
            )}
 | 
					            )}
 | 
				
			||||||
            {configuredProviders.includes("generic") && (
 | 
					            {configuredProviders.includes("generic") && (
 | 
				
			||||||
              <OAuthButton
 | 
					              <OAuthButton
 | 
				
			||||||
                title="Generic"
 | 
					                title={genericName}
 | 
				
			||||||
                icon={<GenericIcon />}
 | 
					                icon={<GenericIcon />}
 | 
				
			||||||
                className="w-full"
 | 
					                className="w-full"
 | 
				
			||||||
                onClick={() => oauthMutation.mutate("generic")}
 | 
					                onClick={() => oauthMutation.mutate("generic")}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,28 +3,48 @@ package oauth
 | 
				
			|||||||
import (
 | 
					import (
 | 
				
			||||||
	"context"
 | 
						"context"
 | 
				
			||||||
	"crypto/rand"
 | 
						"crypto/rand"
 | 
				
			||||||
 | 
						"crypto/tls"
 | 
				
			||||||
	"encoding/base64"
 | 
						"encoding/base64"
 | 
				
			||||||
	"net/http"
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"golang.org/x/oauth2"
 | 
						"golang.org/x/oauth2"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewOAuth(config oauth2.Config) *OAuth {
 | 
					func NewOAuth(config oauth2.Config, insecureSkipVerify bool) *OAuth {
 | 
				
			||||||
	return &OAuth{
 | 
						return &OAuth{
 | 
				
			||||||
		Config: config,
 | 
							Config:             config,
 | 
				
			||||||
 | 
							InsecureSkipVerify: insecureSkipVerify,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type OAuth struct {
 | 
					type OAuth struct {
 | 
				
			||||||
	Config   oauth2.Config
 | 
						Config             oauth2.Config
 | 
				
			||||||
	Context  context.Context
 | 
						Context            context.Context
 | 
				
			||||||
	Token    *oauth2.Token
 | 
						Token              *oauth2.Token
 | 
				
			||||||
	Verifier string
 | 
						Verifier           string
 | 
				
			||||||
 | 
						InsecureSkipVerify bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (oauth *OAuth) Init() {
 | 
					func (oauth *OAuth) Init() {
 | 
				
			||||||
	// Create a new context and verifier
 | 
						// Create transport with TLS
 | 
				
			||||||
 | 
						transport := &http.Transport{
 | 
				
			||||||
 | 
							TLSClientConfig: &tls.Config{
 | 
				
			||||||
 | 
								InsecureSkipVerify: oauth.InsecureSkipVerify,
 | 
				
			||||||
 | 
								MinVersion:         tls.VersionTLS12,
 | 
				
			||||||
 | 
							},
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Create a new context
 | 
				
			||||||
	oauth.Context = context.Background()
 | 
						oauth.Context = context.Background()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Create the HTTP client with the transport
 | 
				
			||||||
 | 
						httpClient := &http.Client{
 | 
				
			||||||
 | 
							Transport: transport,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Set the HTTP client in the context
 | 
				
			||||||
 | 
						oauth.Context = context.WithValue(oauth.Context, oauth2.HTTPClient, httpClient)
 | 
				
			||||||
 | 
						// Create the verifier
 | 
				
			||||||
	oauth.Verifier = oauth2.GenerateVerifier()
 | 
						oauth.Verifier = oauth2.GenerateVerifier()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -36,7 +36,7 @@ func (providers *Providers) Init() {
 | 
				
			|||||||
			RedirectURL:  fmt.Sprintf("%s/api/oauth/callback/github", providers.Config.AppURL),
 | 
								RedirectURL:  fmt.Sprintf("%s/api/oauth/callback/github", providers.Config.AppURL),
 | 
				
			||||||
			Scopes:       GithubScopes(),
 | 
								Scopes:       GithubScopes(),
 | 
				
			||||||
			Endpoint:     endpoints.GitHub,
 | 
								Endpoint:     endpoints.GitHub,
 | 
				
			||||||
		})
 | 
							}, false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Initialize the oauth provider
 | 
							// Initialize the oauth provider
 | 
				
			||||||
		providers.Github.Init()
 | 
							providers.Github.Init()
 | 
				
			||||||
@@ -53,7 +53,7 @@ func (providers *Providers) Init() {
 | 
				
			|||||||
			RedirectURL:  fmt.Sprintf("%s/api/oauth/callback/google", providers.Config.AppURL),
 | 
								RedirectURL:  fmt.Sprintf("%s/api/oauth/callback/google", providers.Config.AppURL),
 | 
				
			||||||
			Scopes:       GoogleScopes(),
 | 
								Scopes:       GoogleScopes(),
 | 
				
			||||||
			Endpoint:     endpoints.Google,
 | 
								Endpoint:     endpoints.Google,
 | 
				
			||||||
		})
 | 
							}, false)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Initialize the oauth provider
 | 
							// Initialize the oauth provider
 | 
				
			||||||
		providers.Google.Init()
 | 
							providers.Google.Init()
 | 
				
			||||||
@@ -73,7 +73,7 @@ func (providers *Providers) Init() {
 | 
				
			|||||||
				AuthURL:  providers.Config.GenericAuthURL,
 | 
									AuthURL:  providers.Config.GenericAuthURL,
 | 
				
			||||||
				TokenURL: providers.Config.GenericTokenURL,
 | 
									TokenURL: providers.Config.GenericTokenURL,
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
		})
 | 
							}, providers.Config.GenericSkipSSL)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Initialize the oauth provider
 | 
							// Initialize the oauth provider
 | 
				
			||||||
		providers.Generic.Init()
 | 
							providers.Generic.Init()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@ type Config struct {
 | 
				
			|||||||
	GenericTokenURL         string `mapstructure:"generic-token-url"`
 | 
						GenericTokenURL         string `mapstructure:"generic-token-url"`
 | 
				
			||||||
	GenericUserURL          string `mapstructure:"generic-user-url"`
 | 
						GenericUserURL          string `mapstructure:"generic-user-url"`
 | 
				
			||||||
	GenericName             string `mapstructure:"generic-name"`
 | 
						GenericName             string `mapstructure:"generic-name"`
 | 
				
			||||||
 | 
						GenericSkipSSL          bool   `mapstructure:"generic-skip-ssl"`
 | 
				
			||||||
	DisableContinue         bool   `mapstructure:"disable-continue"`
 | 
						DisableContinue         bool   `mapstructure:"disable-continue"`
 | 
				
			||||||
	OAuthWhitelist          string `mapstructure:"oauth-whitelist"`
 | 
						OAuthWhitelist          string `mapstructure:"oauth-whitelist"`
 | 
				
			||||||
	OAuthAutoRedirect       string `mapstructure:"oauth-auto-redirect" validate:"oneof=none github google generic"`
 | 
						OAuthAutoRedirect       string `mapstructure:"oauth-auto-redirect" validate:"oneof=none github google generic"`
 | 
				
			||||||
@@ -34,7 +35,7 @@ type Config struct {
 | 
				
			|||||||
	LoginTimeout            int    `mapstructure:"login-timeout"`
 | 
						LoginTimeout            int    `mapstructure:"login-timeout"`
 | 
				
			||||||
	LoginMaxRetries         int    `mapstructure:"login-max-retries"`
 | 
						LoginMaxRetries         int    `mapstructure:"login-max-retries"`
 | 
				
			||||||
	FogotPasswordMessage    string `mapstructure:"forgot-password-message" validate:"required"`
 | 
						FogotPasswordMessage    string `mapstructure:"forgot-password-message" validate:"required"`
 | 
				
			||||||
	BackgroundImage         string `mapstructure:"background-image" validate:"required,url"`
 | 
						BackgroundImage         string `mapstructure:"background-image" validate:"required"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Server configuration
 | 
					// Server configuration
 | 
				
			||||||
@@ -62,6 +63,7 @@ type OAuthConfig struct {
 | 
				
			|||||||
	GenericAuthURL      string
 | 
						GenericAuthURL      string
 | 
				
			||||||
	GenericTokenURL     string
 | 
						GenericTokenURL     string
 | 
				
			||||||
	GenericUserURL      string
 | 
						GenericUserURL      string
 | 
				
			||||||
 | 
						GenericSkipSSL      bool
 | 
				
			||||||
	AppURL              string
 | 
						AppURL              string
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user