Skip to content

kaleb110/goth-oauth2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Golang Goth OAuth2 Authentication Server

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.

Features

  • 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.

Prerequisites

  • Go 1.23.4 installed.
  • Supabase account and project setup.
  • Google Cloud Console project with OAuth 2.0 credentials.

Setup

  1. Clone the repository:

    git clone <repository_url>
    cd <repository_directory>
  2. Install dependencies:

    go mod tidy
  3. Configure environment variables: rename .env.example to .env and enter your credentials.

  4. Run the server:

    go run main.go

    or Install air:

    go install github.com/air-verse/air@latest

    Run with:

    air

Usage

  • 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.

Dependencies

Notes

  • Ensure your environment variables are set correctly.
  • Securely manage your session key.
  • Adapt the database schema and user data storage to your specific needs.

contribute

  • Feel free to change things and make a PR. thanks !

Releases

No releases published

Packages

No packages published