
# Providers: Google and Apple

Most OpenID Connect providers (Keycloak, Okta, Auth0, Microsoft) need only a public client with PKCE and a redirect URI the app can catch. Google and Apple have rules of their own. This page says what each needs, as far as known in October 2026; the code is tested against fakes, so check the provider's console.

## Why

Google's console offers different client types per platform, with different redirects, and has changed its rules for Android. Apple asks apps to use its own sheet and gives the app's code to the app's server only. Knowing this up front saves a failed review or a login that never comes back.

## Login with Google

Google is an OpenID Connect provider; the registration `google` gets its endpoints from the OAuth2 client's known providers and needs only the client id.

```yaml
spring:
  security:
    oauth2:
      client:
        registration:
          google:
            client-id: 123-abc.apps.googleusercontent.com
            redirect-uri: com.googleusercontent.apps.123-abc:/oauth2redirect
            scope: openid,profile,email
```

| Where | Client type in Google Cloud | Redirect URI | Secret |
|---|---|---|---|
| iOS, macOS | iOS (the bundle id) | the reversed client id: `com.googleusercontent.apps.123-abc:/oauth2redirect` | none |
| Android | Android (package name and SHA-1); "Custom URI scheme" turned on under Advanced settings | the custom scheme the console accepts (the reversed client id) | none |
| Windows, Linux | Desktop app | `http://127.0.0.1/callback` (any port) | a `client_secret` that is no secret |
| Web (the server logs in) | Web application | `https://<server>/login/oauth2/code/google` | on the server only |

- **Android:** since October 2023 new Android clients may not use custom URI schemes unless "Custom URI scheme" is enabled; Google points Android apps to its Credential Manager, which this package does not wrap. Without the custom scheme, let the server log the user in.
- **Desktops:** a "Desktop app" client comes with a `client_secret` that Google itself says is not confidential; set it as `client-secret` when the token endpoint asks for it.
- **Roles:** Google has none. Map the user to authorities in a `GrantedAuthoritiesMapper` bean, and on the server, which decides.
- **Who the user is:** keep users by `sub`, never by e-mail; use the e-mail only with `email_verified=true`.
- **Refresh tokens** are long-lived and not rotated; `logout()` revokes them. Google issues no DPoP tokens (`dpop=auto` stays `Bearer`).

## Sign in with Apple

On iOS and macOS the app signs in with the system's own sheet (`ASAuthorizationAppleIDProvider`: Face ID, Touch ID or the passcode), not a browser. A registration whose provider is `apple` uses it by default; `native-sign-in` says it explicitly:

```yaml
spring:
  security:
    oauth2:
      client:
        registration:
          apple:
            client-id: books.neon.app          # the App ID (bundle id)
            native-sign-in: apple              # the sheet on iOS and macOS; none: the browser
        provider:
          apple:
            # The app's server exchanges the code: only it can sign Apple's client secret.
            token-uri: https://api.neon.example/oauth2/apple/token
```

The app needs the "Sign in with Apple" capability in Xcode and an App ID with Sign in with Apple enabled. `login('apple')`:

1. sends the sheet the scopes (`name`, `email`), a fresh `state`, and the SHA-256 hash of a fresh nonce;
2. checks the answer: the `state`; the identity token's signature against Apple's keys, its issuer, audience, times and nonce; its `sub` equal to the sheet's user. The token comes from the operating system, not a TLS connection, so it is verified like a server does;
3. exchanges the authorization code (valid five minutes, once) at the registration's token endpoint, which is **the app's server**: Apple takes a code only with a client secret signed with the team's key, which no app may hold. The server verifies, exchanges the code with Apple (the security starter's `JwtClientSecret`) and answers with the tokens of its own API;
4. keeps the name (and an e-mail the token lacks), which Apple sends **on the first authorization only**, with the login. Store it on the server too, at once.

Any failure is an `OAuth2AuthenticationException`; a closed sheet an `AuthorizationCancelledException`. On Android, Windows and Linux there is no sheet: the registration uses the browser, an `https` redirect and `response-mode=query`. Simpler there: let the server log the user in.

The App Store asks an app that offers a third-party login to offer Sign in with Apple too (App Review Guideline 4.8), and an app that creates accounts must let users delete them, which includes revoking the user's Apple tokens on the server.

## Registration keys used here

| Key | Meaning |
|---|---|
| `spring.security.oauth2.client.registration.<id>.native-sign-in` | `apple`: Sign in with Apple's sheet on iOS and macOS; `none`: the browser. Default `apple` for the `apple` provider |
| `spring.security.oauth2.client.registration.<id>.response-mode` | `query` (the default) or `form_post` (only a server can receive it) |
| `spring.security.oauth2.client.provider.<id>.token-uri` | For Apple: the app's server |

Every key of the registrations is on [All properties](properties.md).

## See also

- [The app login](app-login.md)
- [Login screens](login-screens.md)
- [spring_boot_starter_security](../spring-boot-starter-security/index.md)
