This is a simple Golang OAuth2 authentication server using the Goth library. It supports Google login and stores user data in a Supabase database. Session management is handled with gorilla/sessions
, and authentication checks are performed using cookies.
- Google OAuth2 Provider: Allows users to log in with their Google accounts.
- Supabase Database: Stores user data persistently.
- Session Management: Uses
gorilla/sessions
for secure session handling. - Cookie-based Authentication: Checks user authentication with a given cookie.
- Go 1.23.4 installed.
- Supabase account and project setup.
- Google Cloud Console project with OAuth 2.0 credentials.
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Install dependencies:
go mod tidy
-
Configure environment variables: rename
.env.example to .env
and enter your credentials. -
Run the server:
go run main.go
or Install air:
go install github.com/air-verse/air@latest
Run with:
air
- User data is stored in the Supabase database.
- Session information is stored in a cookie.
- Protected routes can be accessed by authenticated users with a valid session cookie.
- The cookie is used to check for authentication on protected routes.
- Goth
- gorilla/sessions ...
- Ensure your environment variables are set correctly.
- Securely manage your session key.
- Adapt the database schema and user data storage to your specific needs.
- Feel free to change things and make a PR. thanks !