> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gofast.live/llms.txt
> Use this file to discover all available pages before exploring further.

# 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` and `GOOGLE_CLIENT_SECRET` environment variables.
* To enable the **GitHub** provider, you need to set the `GITHUB_CLIENT_ID` and `GITHUB_CLIENT_SECRET` environment variables.

```yaml theme={null}
services:
  server:
    environment:
      GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
      GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
      GITHUB_CLIENT_ID: ${GITHUB_CLIENT_ID}
      GITHUB_CLIENT_SECRET: ${GITHUB_CLIENT_SECRET}
```

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:

1. Go to [GitHub Developer Settings](https://github.com/settings/apps).
2. Click on "New GitHub App".
3. Fill in the `GitHub App name`, `Homepage URL`, `Callback URL`.
4. Check `Request user authorization (OAuth) during installation`.
5. Uncheck `Active` on `Webhook`.
6. In `Account permissions`, set `Email addresses` to `Read-only` (required).
7. Check `Any account` on `Where can this GitHub App be installed?`.
8. Click on "Create GitHub App".
9. Click on "Generate a new client secret".
10. Copy the `Client ID` and `Client Secret`.

### Google

To get the `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET`, you need to create a new Google Project:

1. Go to [Google Cloud Console](https://console.cloud.google.com/).
2. Click on "Select a project" and then "New Project".
3. Fill in the `Project name` and click on "Create".
4. Go to "APIs & Services" > "OAuth consent screen".
5. Fill all the required fields and click on "Save and continue".
6. Go to "APIs & Services" > "Credentials".
7. Click on "Create credentials" > "OAuth client ID".
8. Select "Web application".
9. Fill in the `Name`, `Authorized redirect URIs` and click on "Create".
10. Copy the `Client ID` and `Client Secret`.

## Need help?

Visit our discord server to ask any questions, make suggestions and give feedback :).

[https://discord.gg/EdSZbQbRyJ](https://discord.gg/EdSZbQbRyJ)
