Skip to content

Sign users in with Google

Use this guide to add a "Continue with Google" button to a browser app, so users sign in to PlayTelly with Google instead of typing a password. For how tokens and sessions work, see Authentication.

Social sign-in only signs in people who already have a PlayTelly account (or an open invitation for the same e-mail address). It never creates an account.

Before you begin

  • Your app runs in a browser. Social sign-in ends in a web session: the tokens are set as cookies, never returned in a body. For scripts, servers and mobile apps, use password sign-in with PlayTelly-Platform: mobile.
  • Your app can use PlayTelly's cookies: on success, the sign-in sets the access_token and refresh_token cookies on PlayTelly's domain, and your app receives no token, user data or query parameter. Browsers send these cookies only to PlayTelly hosts and may block them for apps on other sites, so this guide fits apps served from an origin PlayTelly allows. Otherwise, use password sign-in with PlayTelly-Platform: mobile.
  • PlayTelly has added your app's origin (for example https://app.example.com) to the allowed sign-in return addresses. Ask PlayTelly support; until then the start call answers 400 REDIRECT_NOT_ALLOWED.
  • You know the AuthAPI host, <AUTH_HOST>. See API conventions.

Steps

  1. Check which providers are enabled.

    curl -s "https://<AUTH_HOST>/api/v1/auth/idp/providers"
    

    You get the provider keys you can use:

    { "providers": ["google"] }
    

    Show a button only for the keys in the list. An empty list means social sign-in is off on this instance: show no provider buttons.

  2. When the user clicks the button, send the whole browser window to the start URL. Don't call it with fetch: it answers with a redirect to Google and sets a cookie that must stay in this browser.

    https://<AUTH_HOST>/api/v1/auth/idp/google/start?redirect_uri=<RETURN_URL>
    

    Replace <RETURN_URL> with the URL-encoded page of your app where the user should land after sign-in, for example https%3A%2F%2Fapp.example.com%2Fhome.

    The browser goes to Google's account chooser.

  3. Let the user finish at Google. The rest happens without your code:

    • If the Google account is already linked to a PlayTelly account, the browser lands on <RETURN_URL>, signed in.
    • The first time, PlayTelly shows its own "Confirm it's you" page and asks for the user's PlayTelly password once, to link the Google account to the PlayTelly account with the same e-mail. Then the browser lands on <RETURN_URL>, signed in. Later sign-ins skip this screen.
    • If the user was invited and hasn't activated the account yet, and the Google e-mail is the invited address, the account is activated and the user lands on <RETURN_URL> without choosing a password.
    • If something fails, the browser lands on the PlayTelly sign-in page (not your app) with ?idp_error=<CODE>, and that page shows the message.

    The whole round trip must finish within 10 minutes, in the same browser.

Verify

From <RETURN_URL>, list the user's sessions with the cookies the sign-in set:

const res = await fetch("https://<AUTH_HOST>/api/v1/sessions", { credentials: "include" });
console.log(res.status, await res.json());

You get 200 and a session with "platform": "web" and "current": true:

{
  "sessions": [
    { "id": "5c8e1f2a-7b3d-4e9a-a1c6-0f2d4b6e8a10", "platform": "web", "current": true }
  ]
}

The session in the example is shortened. A 401 means no session cookie was sent: check that your origin is on the allowed list and that you send credentials: "include".

Troubleshooting

Symptom Cause Fix
Start URL answers 400 REDIRECT_NOT_ALLOWED <RETURN_URL> isn't on an allowed origin Ask PlayTelly support to add your origin.
Start URL answers 404 PROVIDER_NOT_FOUND The provider isn't enabled Show only keys from step 1.
idp_error=no_account No PlayTelly account has the Google e-mail address Ask the organization admin to invite that address.
idp_error=email_unverified Google didn't confirm the e-mail address Use a Google account with a verified address.
idp_error=state_invalid More than 10 minutes passed, or the flow finished in another browser Start again in one browser.
idp_error=provider_failed The user cancelled, or Google reported an error Start again.
idp_error=account_disabled, org_disabled and similar The account or organization isn't active See States.

Every code is listed in Social sign-in result codes.

Next steps