OAuth
Fully working OAuth flow without any external provider + Magic Links
Configuration
The base application includes configurations for two providers: Google and GitHub, plus a Magic Link option.
- To enable the Google provider, you need to set the
GOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
environment variables. - To enable the GitHub provider, you need to set the
GITHUB_CLIENT_ID
andGITHUB_CLIENT_SECRET
environment variables.
The Magic Link option requires only a working email provider. If the log
option is chosen for email configuration, the magic link will appear in the application logs.
Implementation Details
The OAuth implementation does not depend on any external providers. It’s built using the golang.org/x/oauth2
library. The main logic can be found in the /auth/provider.go
file.
Adding a new provider
To add a new provider, follow these steps in the /auth/provider.go
file:
Backend
- Add the new provider to the
Provider
constant.
- Create a new provider struct.
- Return the new provider in the
NewProvider
function:
- Implement the required methods:
-
Add any new secrets in the
env.go
file. -
Fill in the
docker-compose.yml
file with the new provider configuration.
Frontend
On the frontend side, all you need to do is create a new form with a button and a hidden input that holds the new provider name.
SvelteKit:
NextJS:
Getting Secrets
Github
To get the GITHUB_CLIENT_ID
and GITHUB_CLIENT_SECRET
, you need to create a new GitHub App:
- Go to GitHub Developer Settings.
- Click on “New GitHub App”.
- Fill in the
GitHub App name
,Homepage URL
,Callback URL
. - Check
Request user authorization (OAuth) during installation
. - Uncheck
Active
onWebhook
. - Check
Any account
onWhere can this GitHub App be installed?
. - Click on “Create GitHub App”.
- Click on “Generate a new client secret”.
- Copy the
Client ID
andClient Secret
.
To get the GOOGLE_CLIENT_ID
and GOOGLE_CLIENT_SECRET
, you need to create a new Google Project:
- Go to Google Cloud Console.
- Click on “Select a project” and then “New Project”.
- Fill in the
Project name
and click on “Create”. - Go to “APIs & Services” > “OAuth consent screen”.
- Fill all the required fields and click on “Save and continue”.
- Go to “APIs & Services” > “Credentials”.
- Click on “Create credentials” > “OAuth client ID”.
- Select “Web application”.
- Fill in the
Name
,Authorized redirect URIs
and click on “Create”. - Copy the
Client ID
andClient Secret
.
Need help?
Visit our discord server to ask any questions, make suggestions and give feedback :).