OAuth
Fully working OAuth flow without any external provider + Magic Links
Implementation
The main logic can be found in the service-go-user/domain/login/provider.go
file.
The OAuth implementation does not depend on any external providers. It’s built using the golang.org/x/oauth2
library.
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 a working email provider. If the log
option is chosen for email configuration, the magic link will appear in the application logs.
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 :).
Was this page helpful?