MultiPaaS

Add end-user sign-in

Your app's users sign in to MultiPaaS, and your app gets an access token for the generated API. Run the commands in your app's directory, after multipaas init, which Build on the generated API covers.

Register your app

multipaas oauth-client create --name NAME --redirect-uri https://app.example.com/callback

The client's id is saved in multipaas.json as oauthClientId.

Sign a user in

Use the endpoints that multipaas init --json printed: endpoints.authorize, endpoints.token, endpoints.revoke and endpoints.userinfo. They are also listed in the server's metadata, at /.well-known/oauth-authorization-server on the API host. If your framework has an OAuth library with PKCE, use it.

  1. Authorize. Send the browser to the authorize endpoint with client_id, redirect_uri (one of the client's registered ones, or one registered on the environment you sign in to: the one named in environment, else the default environment), response_type=code, code_challenge, code_challenge_method=S256 and state. Add environment, the environmentId in multipaas.json (written by multipaas init from CLI 1.2.0), to sign in to one environment. It is optional, and leaving it out means the default environment. To let the user pick an account, add prompt=select_account, which always shows the account chooser. prompt=login makes the user sign in again, and wins when both are given. prompt takes space-separated values, and consent changes nothing. prompt=none on its own is answered with an interaction_required redirect to your redirect_uri with your state, because the user is always asked, so don't send it. none with another value, or any value not named here, is refused with invalid_request. To ask for one person, add login_hint with their email address: with no prompt, if they are already signed in on the browser, the chooser is skipped, and otherwise sign-in opens with the address filled in. prompt outranks login_hint, so select_account still shows the chooser and login still signs in again. Every account signed in on the browser is one click on the chooser, and choosing one never changes the account the user's other tabs or apps use. A multipaas.json written by a CLI older than 1.2.0 has no environmentId, even after you upgrade; to sign in to another environment, run init again as Environments describes, adding --api-version API_VERSION with the file's apiVersion to keep the pin. Don't send scope. For an environment other than the default, the consent page names it. The user signs in to one of that environment's app-tenants only, choosing one on the page when they can reach several. The page also has an Allow changes checkbox, on by default. If the user turns it off, the tokens can only read: every mutation is refused with FORBIDDEN ("This connection can only read"), and that holds after a refresh. If the sign-in client is set to Always allow changes (in the console, or alwaysAllowChanges through the builder tools), the page has no checkbox, and tokens from a sign-in made while it is on are never limited to reading (users still change only what their roles allow). Read-only sign-ins from before stay read-only until the user signs in again. Set it for your app's own sites; leave it off for a client another app uses. The tokens are for that environment. If that environment has been deleted, the authorize request is refused; see Environments for repointing multipaas.json.
  2. Exchange. Your callback receives code and state. Check state. Within 60 seconds, POST the code, form-encoded (application/x-www-form-urlencoded), to the token endpoint with grant_type=authorization_code, client_id, code, redirect_uri and code_verifier. The answer holds an access token and a refresh token.
  3. Call the API with Authorization: Bearer <access_token> and X-MultiPaaS-App-Api-Version: <the apiVersion in multipaas.json>.
  4. See who signed in. GET the userinfo endpoint with Authorization: Bearer <access_token>. The answer is {"sub", "email", "app_tenant_id", "app_tenant_name"}, where sub is the user's id and app_tenant_id and app_tenant_name name the app-tenant the user signed in to. An expired or revoked token answers 401 with invalid_token: refresh it, and if the refresh is refused, send the user through the authorize step again. A token from client_credentials (an app identity) or one for an MCP server answers 403 with insufficient_scope, because neither signs a person in: call userinfo only with the token this flow returned. login_hint is only a hint, so read the signed-in user from here rather than assuming it.
  5. Refresh before the access token expires. POST, form-encoded, to the token endpoint with grant_type=refresh_token, client_id and refresh_token. If the sign-in's environment has been deleted, the refresh is refused with invalid_grant: send the user through the authorize step again, for a live environment.
  6. Sign out. POST, form-encoded, to the revoke endpoint with client_id and token, the refresh token.

Access tokens last 3600 seconds. Each refresh returns a new pair, so store both. If you use a refresh token twice, the whole sign-in is revoked. The one exception is a refresh whose answer never arrived: retry it with the same refresh token within 60 seconds, and the retry gets a new pair. The pair in the lost answer stops working. A sign-in lasts at most 7 days, and then the user signs in again. An access token issued just before then still lasts its full hour.

Several accounts

Your app can let one browser hold several of its users and switch between them:

Background jobs

A job with no user signed in uses an app identity instead. Run background jobs covers it.

More