Docs

Guides

Signing in your end users

Choose how your users identify and prove who they are, then sign them up and in from your server with sessions issued on their behalf.

You choose, per project, how your users sign up and sign in. The API accepts nothing else, and it publishes the journey it expects, so you build your own screens.

Choose the methods in the Hub#

In the Hub, Settings, User journey, tick:

  • the identifiers accepted: a username (tagname), a phone number (phone), an email address (email), one or several;
  • the proofs accepted: a password created by the user, a one-time code by SMS (sms_code, needs the phone identifier), an authenticator app (totp, which the user adds from their account; combine it with another proof). One proof is enough to sign in.

Publish the change. Until you do, the historical flow applies: phone number and code by SMS. Everything below is available with sandbox keys; live comes later.

Read the journey, build your screens#

Retrieve the published signup flow: authentication lists your identifiers and proofs, and flow describes the journey without any visual: the fields to ask at sign-up and sign-in, their rules (lengths, formats), the routes to call, the lifetimes of sessions and the error codes.

const { authentication, flow } = await tilt.signupConfig.retrieve()
// authentication: { identifiers: ['email'], proofs: ['password', 'totp'] }
// flow.signup.fields: [{ name: 'email', required: true, ... }, { name: 'password', rules: { min_length: 10 }, ... }]

Two places, two credentials#

// On your server
const session = await tilt.auth.signUp({ email: '[email protected]', password: 'correct horse battery' })
// hand session.access_token and session.refresh_token to the browser or app

// In the user's browser or app
const user = new TiltPayUser({
  accessToken: session.access_token,
  refreshToken: session.refresh_token,
  onSessionChange: (s) => save(s), // a refresh token works once: store the new ones
})
const me = await user.me.retrieve()

Sessions#

  • The access token lasts 15 minutes; the refresh token lasts 30 days and works once. A session ends 90 days after sign-in at the latest.
  • Renewing returns a new pair. Presenting an old refresh token again means it was copied: the whole session is revoked.
  • TiltPayUser renews by itself when a call answers session_expired, and shares one renewal between concurrent calls. A renewal is never retried automatically.
  • Sign out one session or all of them (logOut); from your server, revoke all the sessions of a user. The sessions of a suspended user stop working at once.

Passwords, codes and authenticator apps#

  • Passwords are 10 to 128 characters and are stored hashed. Changing one signs out the user's other sessions. Setting a first password needs a sign-in less than 10 minutes old.
  • In the sandbox, the code by SMS is always 123456 and nothing is sent. Request it with requestAuthChallenge; the answer is the same whether or not the account exists.
  • An authenticator app (TOTP: 6 digits, 30 seconds) is added in two steps: enrollTotp returns the secret once, with an otpauth_uri to show as a QR code, then confirmTotp activates it with a code. A code works once, and removing the app (disableTotp) needs a valid code. If the user lost their device, your server removes the app with resetUserTotp after checking their identity; every session is then closed and the user signs in with another proof.

Errors and protection#

  • Every sign-in failure is 401 invalid_credentials: an unknown identifier, a wrong proof and a method the user has not set up give the same answer.
  • After 5 consecutive failures the identifier is locked for 15 minutes (429 rate_limit_exceeded with Retry-After), doubled at each new lock and capped at 24 hours. The same limit applies to identifiers that do not exist. Attempts and sign-ups are also limited per IP address.
  • A suspended user gets 409 user_suspended once the proof is valid.
  • The email address identifies the user but is not verified yet: no email is sent.
  • A user can sign up without a phone number: phone is then null on the user.