Skip to content

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.

MagentoGoogle / AppleStorefront (Auth.js)BrowserMagentoGoogle / AppleStorefront (Auth.js)BrowserContinue with GoogleOAuth sign-insigned ID tokensocialLogin(secret, ID token)fetch signing keyscheck signature, audience, expiry, verified emailcustomer token (account created if new)signed in

Two separate checks protect it:

CheckAnswers
Shared secretIs 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.
  1. Create OAuth clients with Google and/or Apple for your storefront.

  2. 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.com
    MAGENX_SOCIAL_LOGIN_APPLE_CLIENT_ID=com.example.storefront

    Environment variables win over admin settings. If PHP-FPM clears the environment, pass them with nginx fastcgi_param.

  3. On the storefront, set NEXT_PUBLIC_SOCIAL_LOGIN_ENABLED, AUTH_SECRET, AUTH_GOOGLE_ID, AUTH_GOOGLE_SECRET, and MAGENX_SOCIAL_LOGIN_SECRET with 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/certs and https://appleid.apple.com/auth/keys over HTTPS. Keys are cached, and kept for 24 hours longer if the provider is unreachable.

Existing customer signs in

  1. The shopper picks a provider; the sign-in server completes the redirect flow and receives an identity token.
  2. It calls the back office with the shared secret and the token.
  3. The back office checks the secret, verifies the token, reads the verified email and finds the customer on the website.
  4. If the account is neither locked nor awaiting confirmation, a session is returned with "created: no".

New customer registers

  1. As F1, but no customer has that email on the website.
  2. 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.
  3. A session is returned with "created: yes"; no confirmation email is needed.

Refused

  1. Wrong or missing secret, bad signature, wrong issuer or audience, expired token, unverified email, locked or unconfirmed account.
  2. The caller always gets the same "Not authorized."; the reason goes to the log without personal data or token content.

Provider changes keys

  1. 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.
SituationWhat 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.
  • Callers holding the shared secret; customers of the request's website.
  • 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.
Terminal window
composer require magenxcommerce/module-social-login-graph-ql
bin/magento module:enable Magenx_SocialLoginGraphQl
bin/magento setup:upgrade
bin/magento setup:di:compile # production mode only
bin/magento cache:flush
  • PHP ~8.4.0||~8.5.0, Magento 2.4.8.

Stores > Configuration > Magenx > Social Login

General

SettingDefaultScopeNotes
Shared Secret
magenx_social_login/general/shared_secret
emptyStore viewSecret. 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 ID
magenx_social_login/general/google_client_id
emptyStore viewText. 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 ID
magenx_social_login/general/apple_client_id
emptyStore viewText. 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.

Grant these under System > Permissions > User Roles > Role Resources:

ResourceUnderID
Social Login SectionStores > Settings > ConfigurationMagenx_SocialLoginGraphQl::config

socialLogin is called by the storefront server only. It is not on the browser allowlist.

Mutations

socialLogin(input: SocialLoginInput!): SocialLoginOutput

Exchange 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.

ArgumentTypeDescription
inputSocialLoginInput!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.
FieldTypeDescription
secretString!The shared secret that authorizes this server-to-server call. Must match the storefront's configured secret.
idTokenString!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.
firstnameStringOptional 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.
lastnameStringOptional 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.
FieldTypeDescription
tokenString!A Magento customer access token for the matched or newly created customer.
createdBoolean!True if a new customer account was created, false if an existing one was matched.
TermMeaning
Sign-in serverThe storefront's server-side component that completes the provider redirect flow.
Identity tokenOpenID Connect token signed by the provider.
ProviderIssuer names it signs as and the address of its public keys.
Public keysThe provider's published signing keys.
Client idThe application the token was issued to; must match the token's audience.
Shared secretValue known only to the sign-in server and the back office.
Verified emailThe email claim when the provider marks it verified.
Customer sessionThe same bearer session a password sign-in returns.
Clock leeway60 seconds of tolerance on token times.