Skip to main content
Native Plugins & Integrations2 min read

Social Login: Apple, Google and Facebook

Add native Sign in with Apple, Sign in with Google and Facebook Login to your app, verify tokens on your server, and meet Apple's sign-in rules.

Overview

Google blocks its sign-in pages inside apps (error disallowed_useragent), so your website's own Google button does not work in the app. The social login plugins replace it with native sign-in, and return a token your server verifies before starting the user's session.

PluginPlatformsMethod
Sign in with AppleiOSwapp.socialLogin.apple.login()
Sign in with GoogleiOS, Androidwapp.socialLogin.google.login()
Facebook LoginiOS, Androidwapp.socialLogin.facebook.login()

Turn them on in Integrations › Native plugins and build a new version.

Important

Apple requires Sign in with Apple (or an equivalent private login) when an iPhone app offers Google or Facebook sign-in. Add the Apple plugin too.

Sign in with Google

Setup in Google Cloud › APIs & Services › Credentials:

  1. A Web application client: copy its ID into Web client ID. The ID token is issued for this client.
  2. An iOS client with your bundle ID: copy its ID into iOS client ID (changing it needs a new build).
  3. An Android client with your package name and the SHA-1 values shown in the plugin settings: the app's build key and, once the app is on Google Play, the "App signing key" from Play Console › Setup › App signing.
javascript
const result = await wapp.socialLogin.google.login();
if (result.success) {
  // Verify the ID token on your server (aud = your web client ID), then start the session
  await fetch('/auth/google', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ idToken: result.idToken }),
  });
}

Result: { type: 'google', idToken, user: { id, email, name, givenName, familyName, photo }, serverAuthCode? }. serverAuthCode is only returned with that setting on. Optional Extra scopes can be set in the plugin.

Sign in with Apple

Setup: connect your App Store Connect API key in Release › Publish, so iPhone builds can turn on the Sign in with Apple capability. The plugin settings show whether everything is ready.

javascript
const result = await wapp.socialLogin.apple.login({ scope: ['fullName', 'email'] });
if (result.success) {
  // Apple sends name and email only the FIRST time: store them now
  await signInOnServer({ idToken: result.idToken, code: result.code,
    firstName: result.firstName, lastName: result.lastName });
}

Result: { type: 'apple', idToken, code, user, email?, firstName?, lastName? }. Verify idToken against Apple's public keys with aud = your bundle ID. Pass a nonce to protect against replay. On Android, login() answers UNSUPPORTED_PLATFORM: show your website's web-based Apple button there, or hide the option.

Facebook Login

Setup (Meta for Developers): copy the App ID, Client Token (a public value) and Display Name into the plugin settings, and add your bundle ID, package name and Android key hashes to the Facebook app. Changing these needs a new build.

javascript
const result = await wapp.socialLogin.facebook.login({ scope: ['public_profile', 'email'] });
if (result.success) {
  if (result.limitedLogin) await signInOnServer({ authToken: result.authToken, nonce: result.nonce });
  else await signInOnServer({ accessToken: result.accessToken });
}

With Limited Login on iPhone (forceLimitedLogin: true, or the setting Always use Limited Login on iPhone), Facebook returns only an identity token (authToken, a JWT to verify) and no Graph API token. The app turns off Facebook's automatic app events and advertising ID collection.

Server sign-in URL (optional)

Each plugin can have a Server sign-in URL. The app then also POSTs the result to it as a normal form POST (the token is not put in a URL). Your server verifies the token and sets its session cookie, like any login form.

Sign out

wapp.socialLogin.google.logout() and wapp.socialLogin.facebook.logout() sign out of the provider in the app. Apple has no sign-out: end the session on your server.

Next steps