Social Login
Module: Magenx_SocialLoginGraphQl
Stock Magento can only sign a customer in with an email and password. This module adds “Continue with Google” (and Apple): the storefront’s sign-in broker (Auth.js) completes the provider login, and Magento turns the provider’s verified identity into a customer session. The same step covers sign-in and registration.
How it works
Section titled “How it works”Two separate checks protect it:
| Check | Answers |
|---|---|
| Shared secret | Is the caller my storefront? |
| ID token verification (by Magento, against the provider’s keys) | Does this person own this email? |
A leaked secret alone is not an account takeover: the holder still can’t produce a Google or Apple signature for an email they don’t control.
- An existing account that is locked, or still waiting for email confirmation, is refused, like with a password.
- A new account gets its name from the token. Apple sends the name only on the first sign-in, so the storefront passes it as a fallback.
- Every refusal answers “Not authorized.” The real reason is in Magento’s logs.
Set up
Section titled “Set up”-
Create OAuth clients with Google and/or Apple for your storefront.
-
In Magento, set the shared secret and each provider’s client ID, in Stores > Configuration > Magenx > Social Login or as environment variables:
Terminal window MAGENX_SOCIAL_LOGIN_SECRET=<secret>MAGENX_SOCIAL_LOGIN_GOOGLE_CLIENT_ID=<client-id>.apps.googleusercontent.comMAGENX_SOCIAL_LOGIN_APPLE_CLIENT_ID=com.example.storefrontEnvironment variables win over admin settings. If PHP-FPM clears the environment, pass them with nginx
fastcgi_param. -
On the storefront, set
NEXT_PUBLIC_SOCIAL_LOGIN_ENABLED,AUTH_SECRET,AUTH_GOOGLE_ID,AUTH_GOOGLE_SECRET, andMAGENX_SOCIAL_LOGIN_SECRETwith the same secret. See Configuration.
- The client ID in Magento must be the same one the storefront signs in with, or every token is refused. A comma-separated list allows several clients (web, iOS, Android).
- Magento must reach
https://www.googleapis.com/oauth2/v3/certsandhttps://appleid.apple.com/auth/keysover HTTPS. Keys are cached, and kept for 24 hours longer if the provider is unreachable.
User flows
Section titled “User flows”Existing customer signs in
- The shopper picks a provider; the sign-in server completes the redirect flow and receives an identity token.
- It calls the back office with the shared secret and the token.
- The back office checks the secret, verifies the token, reads the verified email and finds the customer on the website.
- If the account is neither locked nor awaiting confirmation, a session is returned with "created: no".
New customer registers
- As F1, but no customer has that email on the website.
- A customer is created with a random password and the token's names, or the names passed with the call when the token has none.
- A session is returned with "created: yes"; no confirmation email is needed.
Refused
- Wrong or missing secret, bad signature, wrong issuer or audience, expired token, unverified email, locked or unconfirmed account.
- The caller always gets the same "Not authorized."; the reason goes to the log without personal data or token content.
Provider changes keys
- A token names a key not in the cache; the keys are fetched once more and verification is retried.
These always hold:
- No session without a matching secret and a valid provider signature over a verified email.
- Identity comes only from the verified token.
- A refusal tells the caller nothing about its reason.
- Logs never contain the secret, token content or personal data.
- Key lifetime = clamp(provider lifetime, 300 s, 86,400 s).
- Token valid when issue time − 60 ≤ now ≤ expiry + 60.
- A leaked secret alone only lets an attacker sign in as themselves.
- A provider outage within 24 hours of the last key fetch does not stop sign-in.
Edge cases
Section titled “Edge cases”| Situation | What happens |
|---|---|
| No secret set. | Every call refused. |
| Token issued to another application. | Refused (audience). |
| Email not verified. | Refused. |
| Token expired 30 s ago. | Accepted (leeway). |
| Token expired 2 minutes ago. | Refused. |
| Token without names, names passed with the call. | Account created with those names. |
| Existing account awaiting confirmation. | Refused. |
| Same email only on another website. | New account on this website. |
| Provider unreachable, keys 2 hours past expiry. | Old keys used. |
| Unsigned token. | Refused. |
Who it applies to
Section titled “Who it applies to”- Callers holding the shared secret; customers of the request's website.
Out of scope
Section titled “Out of scope”- The browser redirect flow itself (state and nonce handling belong to the storefront's sign-in server).
- Linking and unlinking several providers on one account explicitly.
- Social sign-in to the admin.
- Profile data beyond name and email.
- Calling the operation from a browser.
Install
Section titled “Install”composer require magenxcommerce/module-social-login-graph-qlbin/magento module:enable Magenx_SocialLoginGraphQlbin/magento setup:upgradebin/magento setup:di:compile # production mode onlybin/magento cache:flush- PHP
~8.4.0||~8.5.0, Magento 2.4.8.
Configuration
Section titled “Configuration”Stores > Configuration > Magenx > Social Login
General
| Setting | Default | Scope | Notes |
|---|---|---|---|
Shared Secretmagenx_social_login/ | empty | Store view | Secret. Authorizes the server-to-server socialLogin call, and must match MAGENX_SOCIAL_LOGIN_SECRET on the storefront. Answers "is this my broker?" — it is not what proves the customer's identity, so it never belongs in a browser bundle. While empty (and with no MAGENX_SOCIAL_LOGIN_SECRET set) every call is rejected. Overridden by that environment variable when it is set. |
Google OAuth Client IDmagenx_social_login/ | empty | Store view | Text. The aud value accepted on a Google ID token: the same client id the storefront signs in with (AUTH_GOOGLE_ID), ending in .apps.googleusercontent.com. Comma-separate several to serve sibling clients (web, iOS, Android) from one Google project. While empty, every Google token is rejected — including a perfectly valid one. Overridden by MAGENX_SOCIAL_LOGIN_GOOGLE_CLIENT_ID when it is set. |
Apple Services IDmagenx_social_login/ | empty | Store view | Text. The aud value accepted on an Apple ID token: the Services ID the storefront signs in with (AUTH_APPLE_ID), e.g. com.example.storefront. Comma-separated list accepted. While empty, every Apple token is rejected. Overridden by MAGENX_SOCIAL_LOGIN_APPLE_CLIENT_ID when it is set. |
Admin permissions
Section titled “Admin permissions”Grant these under System > Permissions > User Roles > Role Resources:
| Resource | Under | ID |
|---|---|---|
| Social Login Section | Stores > Settings > Configuration | Magenx_SocialLoginGraphQl::config |
GraphQL
Section titled “GraphQL”socialLogin is called by the storefront server only. It is not on the browser allowlist.
Mutations
socialLogin(input: SocialLoginInput!): SocialLoginOutputExchange a provider-signed OpenID Connect ID token for a Magento customer access token, creating the customer if one does not already exist. Magento verifies the token itself (signature against the issuer's JWKS, issuer, audience, expiry and email_verified), so the caller is not trusted to assert an identity. Also gated by a shared secret: this is intended to be called ONLY server-to-server by the trusted Next.js OAuth broker, never from a browser.
| Argument | Type | Description |
|---|---|---|
input | SocialLoginInput! | A provider-signed ID token plus the shared server-to-server secret. |
Types
input SocialLoginInput - A provider-signed ID token relayed by the Next.js OAuth broker. The broker does not assert the identity — it only passes on what the provider signed, and Magento verifies it.
| Field | Type | Description |
|---|---|---|
secret | String! | The shared secret that authorizes this server-to-server call. Must match the storefront's configured secret. |
idToken | String! | The OpenID Connect ID token (compact JWS) issued by the social provider, as received by the broker during the OAuth round-trip. The customer's email is read from this token's verified claims and nowhere else. |
firstname | String | Optional display-name fallback, used only when creating a new customer AND the ID token carries no given_name claim (Apple never puts names in the token). Never used to match an account, so it carries no authority. |
lastname | String | Optional display-name fallback, used only when creating a new customer AND the ID token carries no family_name claim. Never used to match an account, so it carries no authority. |
type SocialLoginOutput - The result of a successful social login.
| Field | Type | Description |
|---|---|---|
token | String! | A Magento customer access token for the matched or newly created customer. |
created | Boolean! | True if a new customer account was created, false if an existing one was matched. |
Glossary
Section titled “Glossary”| Term | Meaning |
|---|---|
| Sign-in server | The storefront's server-side component that completes the provider redirect flow. |
| Identity token | OpenID Connect token signed by the provider. |
| Provider | Issuer names it signs as and the address of its public keys. |
| Public keys | The provider's published signing keys. |
| Client id | The application the token was issued to; must match the token's audience. |
| Shared secret | Value known only to the sign-in server and the back office. |
| Verified email | The email claim when the provider marks it verified. |
| Customer session | The same bearer session a password sign-in returns. |
| Clock leeway | 60 seconds of tolerance on token times. |