|
| 1 | +--- |
| 2 | +sidebar_position: 4 |
| 3 | +title: Social Login (OAuth2) |
| 4 | +description: Configure Google, GitHub, and Microsoft social login for Turing ES using Spring Security OAuth2. |
| 5 | +--- |
| 6 | + |
| 7 | +# Social Login (OAuth2) |
| 8 | + |
| 9 | +Turing ES supports **social login** via OAuth2 with Google, GitHub, and Microsoft. When configured, users can sign in with their existing accounts from these providers — no separate password required. |
| 10 | + |
| 11 | +This is ideal for development environments, small teams, and scenarios where a full Keycloak deployment is not needed. For enterprise SSO with LDAP/AD federation, MFA, and centralized user management, see [Security & Keycloak](./security-keycloak.md). |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## How It Works |
| 16 | + |
| 17 | +```mermaid |
| 18 | +sequenceDiagram |
| 19 | + participant User |
| 20 | + participant Turing ES |
| 21 | + participant OAuth2 Provider |
| 22 | +
|
| 23 | + User->>Turing ES: Click "Sign in with Google" |
| 24 | + Turing ES->>OAuth2 Provider: Redirect to authorization |
| 25 | + OAuth2 Provider->>User: Show consent screen |
| 26 | + User->>OAuth2 Provider: Approve |
| 27 | + OAuth2 Provider->>Turing ES: Redirect with authorization code |
| 28 | + Turing ES->>OAuth2 Provider: Exchange code for token + user info |
| 29 | + Turing ES->>User: Create session, redirect to /admin |
| 30 | +``` |
| 31 | + |
| 32 | +When a user signs in via a social provider for the first time, Turing ES **automatically creates a local user** with the profile information from the provider (name, email, avatar). Subsequent logins update the profile data. |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Prerequisites |
| 37 | + |
| 38 | +| Requirement | Details | |
| 39 | +|---|---| |
| 40 | +| `turing.authentication.thirdparty` | Must be `true` (default) | |
| 41 | +| Provider OAuth App | Create an OAuth App/Client in the provider's console | |
| 42 | +| Redirect URI | `http://<host>:<port>/login/oauth2/code/<provider>` | |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## Configuration |
| 47 | + |
| 48 | +Add the provider registration under `spring.security.oauth2.client` in your `application.yaml`: |
| 49 | + |
| 50 | +### Google |
| 51 | + |
| 52 | +1. Go to [Google Cloud Console](https://console.cloud.google.com/apis/credentials) |
| 53 | +2. Create an **OAuth 2.0 Client ID** (Web application) |
| 54 | +3. Add the authorized redirect URI: `http://localhost:2700/login/oauth2/code/google` |
| 55 | + |
| 56 | +```yaml |
| 57 | +spring: |
| 58 | + security: |
| 59 | + oauth2: |
| 60 | + client: |
| 61 | + registration: |
| 62 | + google: |
| 63 | + client-id: YOUR_GOOGLE_CLIENT_ID |
| 64 | + client-secret: YOUR_GOOGLE_CLIENT_SECRET |
| 65 | +``` |
| 66 | +
|
| 67 | +:::tip Scopes |
| 68 | +Spring Security auto-configures the Google provider with `openid`, `profile`, and `email` scopes — no need to set them manually. |
| 69 | +::: |
| 70 | + |
| 71 | +### GitHub |
| 72 | + |
| 73 | +1. Go to [GitHub Developer Settings > OAuth Apps](https://github.com/settings/developers) |
| 74 | +2. Click **New OAuth App** |
| 75 | +3. Set **Homepage URL** to `http://localhost:2700` |
| 76 | +4. Set **Authorization callback URL** to `http://localhost:2700/login/oauth2/code/github` |
| 77 | + |
| 78 | +```yaml |
| 79 | +spring: |
| 80 | + security: |
| 81 | + oauth2: |
| 82 | + client: |
| 83 | + registration: |
| 84 | + github: |
| 85 | + client-id: YOUR_GITHUB_CLIENT_ID |
| 86 | + client-secret: YOUR_GITHUB_CLIENT_SECRET |
| 87 | +``` |
| 88 | + |
| 89 | +:::note GitHub specifics |
| 90 | +- GitHub does not provide a separate first/last name — Turing splits the `name` attribute automatically. |
| 91 | +- Email may be `null` if the user's GitHub email is private. The email field is hidden in the profile page when empty. |
| 92 | +- The username is the GitHub `login` handle. |
| 93 | +::: |
| 94 | + |
| 95 | +### Microsoft (Entra ID / Azure AD) |
| 96 | + |
| 97 | +1. Go to [Azure Portal > App registrations](https://portal.azure.com/#view/Microsoft_AAD_RegisteredApps) |
| 98 | +2. Register a new application |
| 99 | +3. Under **Authentication**, add a **Web** redirect URI: `http://localhost:2700/login/oauth2/code/microsoft` |
| 100 | +4. Under **Certificates & secrets**, create a new client secret |
| 101 | + |
| 102 | +```yaml |
| 103 | +spring: |
| 104 | + security: |
| 105 | + oauth2: |
| 106 | + client: |
| 107 | + registration: |
| 108 | + microsoft: |
| 109 | + client-id: YOUR_MICROSOFT_CLIENT_ID |
| 110 | + client-secret: YOUR_MICROSOFT_CLIENT_SECRET |
| 111 | + scope: openid,profile,email |
| 112 | + authorization-grant-type: authorization_code |
| 113 | + redirect-uri: "{baseUrl}/login/oauth2/code/{registrationId}" |
| 114 | + provider: |
| 115 | + microsoft: |
| 116 | + issuer-uri: https://login.microsoftonline.com/common/v2.0 |
| 117 | +``` |
| 118 | + |
| 119 | +--- |
| 120 | + |
| 121 | +## Multiple Providers |
| 122 | + |
| 123 | +You can configure any combination of providers simultaneously. The login page **automatically shows only the buttons for configured providers**: |
| 124 | + |
| 125 | +```yaml |
| 126 | +spring: |
| 127 | + security: |
| 128 | + oauth2: |
| 129 | + client: |
| 130 | + registration: |
| 131 | + google: |
| 132 | + client-id: ... |
| 133 | + client-secret: ... |
| 134 | + github: |
| 135 | + client-id: ... |
| 136 | + client-secret: ... |
| 137 | + microsoft: |
| 138 | + client-id: ... |
| 139 | + client-secret: ... |
| 140 | + provider: |
| 141 | + microsoft: |
| 142 | + issuer-uri: https://login.microsoftonline.com/common/v2.0 |
| 143 | +``` |
| 144 | + |
| 145 | +If only GitHub is configured, only the GitHub button appears. If none are configured, the social login section is hidden entirely. |
| 146 | + |
| 147 | +--- |
| 148 | + |
| 149 | +## Redirect URIs Reference |
| 150 | + |
| 151 | +| Provider | Redirect URI | |
| 152 | +|---|---| |
| 153 | +| Google | `http://<host>:<port>/login/oauth2/code/google` | |
| 154 | +| GitHub | `http://<host>:<port>/login/oauth2/code/github` | |
| 155 | +| Microsoft | `http://<host>:<port>/login/oauth2/code/microsoft` | |
| 156 | + |
| 157 | +The pattern is always: `{baseUrl}/login/oauth2/code/{registrationId}` |
| 158 | + |
| 159 | +For production with HTTPS: `https://turing.example.com/login/oauth2/code/google` |
| 160 | + |
| 161 | +--- |
| 162 | + |
| 163 | +## User Profile Behavior |
| 164 | + |
| 165 | +When logged in via a social provider: |
| 166 | + |
| 167 | +- **Profile fields are read-only** — name, email, and username are managed by the provider |
| 168 | +- **Avatar can still be customized** in Turing |
| 169 | +- **Password section is hidden** — authentication is handled by the provider |
| 170 | +- **The provider name is displayed** on the profile page (e.g., "github", "google") |
| 171 | + |
| 172 | +--- |
| 173 | + |
| 174 | +## Configuration Properties |
| 175 | + |
| 176 | +| Property | Default | Description | |
| 177 | +|---|---|---| |
| 178 | +| `turing.authentication.thirdparty` | `true` | Enable third-party OAuth2 login buttons | |
| 179 | +| `spring.security.oauth2.client.registration.<provider>.client-id` | — | OAuth2 Client ID from the provider | |
| 180 | +| `spring.security.oauth2.client.registration.<provider>.client-secret` | — | OAuth2 Client Secret from the provider | |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +## Troubleshooting |
| 185 | + |
| 186 | +### 404 on provider authorization page |
| 187 | + |
| 188 | +The Client ID is likely incorrect. Double-check the value in `application.yaml` matches the one in the provider's console. |
| 189 | + |
| 190 | +### User profile shows empty name |
| 191 | + |
| 192 | +The provider attributes may use different field names. Turing handles Google (`given_name`, `family_name`), GitHub (`login`, `name`), and Microsoft (`given_name`, `family_name`) automatically. For other providers, the `name` attribute is split into first/last name. |
| 193 | + |
| 194 | +### Email is empty (GitHub) |
| 195 | + |
| 196 | +GitHub may not expose the user's email if it is set to private. This is by design — the email field is hidden in the profile page when empty. |
| 197 | + |
| 198 | +### Login redirects to wrong page |
| 199 | + |
| 200 | +The default success URL is `/admin`. If using a different frontend path, ensure the Spring Security configuration matches. |
| 201 | + |
| 202 | +--- |
| 203 | + |
| 204 | +## Related Pages |
| 205 | + |
| 206 | +| Page | Description | |
| 207 | +|---|---| |
| 208 | +| [Authentication](./security-authentication.md) | Native authentication and API Keys | |
| 209 | +| [Security & Keycloak](./security-keycloak.md) | Full Keycloak production setup with SSO | |
| 210 | +| [Configuration Reference](./configuration-reference.md) | All configuration properties | |
0 commit comments