Implementation
The main logic can be found in theservice-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_IDandGOOGLE_CLIENT_SECRETenvironment variables. - To enable the GitHub provider, you need to set the
GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRETenvironment variables.
log option is chosen for email configuration, the magic link will appear in the application logs.
Getting Secrets
Github
To get theGITHUB_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
ActiveonWebhook. - Check
Any accountonWhere can this GitHub App be installed?. - Click on “Create GitHub App”.
- Click on “Generate a new client secret”.
- Copy the
Client IDandClient Secret.
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 nameand 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 URIsand click on “Create”. - Copy the
Client IDandClient Secret.