Skip to navigation

Authentication

Moyo Suite authenticates the web app with email + password, optional two-factor authentication, and short-lived tokens — not a long-lived API key.

Programmatic, third-party API-key access is planned but intentionally not available yet — keys need to be stored hashed, scoped, rotated, and audited server-side first. The POST /api/v1/auth/login flow below is what the Moyo Suite frontend itself uses; there is no separate developer API-key program today.

Every endpoint on this page is prefixed with /api/v1 — e.g. POST /api/v1/auth/login, not POST /auth/login.

Logging in

POST /api/v1/auth/login
{
"email": "you@company.com",
"password": "••••••••"
}
  • If the account has no 2FA enabled, this returns access_token and refresh_token (JWTs, token_type: "bearer") directly.
  • If the account has 2FA enabled, it instead returns requires_2fa: true plus a short-lived temp_token — see below.

POST /api/v1/auth/jwt/login (OAuth2 password form, used by the interactive API docs) applies the same lockout and SSO rules, but it cannot run the 2FA challenge, so it refuses accounts with 2FA enabled — use POST /api/v1/auth/login for those.

Resetting a password through POST /api/v1/auth/reset-password revokes every existing session for the account and emails a security notice. On an account whose email was never verified it also deletes the account’s linked OAuth identities and marks it verified: an identity attached before the address was proven was never shown to belong to its owner.

Other ways in: a magic link (POST /api/v1/auth/magic-link → emailed one-time link → POST /api/v1/auth/magic-verify), or social/OAuth login. Both honour 2FA: for an account with 2FA enabled, magic-verify and the social-login handoff return requires_2fa: true and a temp_token exactly as POST /api/v1/auth/login does, and no session is issued until the code is verified.

The PASSWORD_NOT_SET refusal carries a code and a message only. It deliberately does not list the account’s linked providers: unauthenticated, that is a fact about the person behind the address.

Social sign-in is bound to the browser that starts it: GET /api/v1/auth/oauth/{provider}/authorize sets a short-lived moyo_oauth_* cookie, and the callback rejects the flow (HTTP 400) if that cookie is missing or doesn’t match. Start the flow with a top-level browser navigation, not a server-side request. In connect mode (?intent=...), the browser must also be signed in as the account the intent was created for (HTTP 403 otherwise).

  • If the account exists but has no password — it was created through a social provider or SSO — login returns 401 with detail.code: "PASSWORD_NOT_SET" and detail.providers, the list of providers that account can sign in with. See below.

One account, several sign-in methods

A Moyo account is a single identity that can carry a password and any number of linked social providers at once. Either kind can be added or removed at any time, as long as at least one way in survives.

GET /api/v1/account/auth-methods reports what an account currently has:

{
"email": "you@company.com",
"has_password": false,
"is_2fa_enabled": false,
"linked_providers": ["google"],
"available_providers": ["microsoft", "github"],
"can_remove_a_method": false
}

Notifications and session handling

Any change to how an account can be signed into — a password set or changed, a provider connected or disconnected, two-factor authentication turned on or off, new backup codes generated, or a personal API token created or revoked — emails the account owner with the time, device and IP it came from. A sign-in from a browser or device the account hasn’t used before is also reported. The send is best-effort and never fails the operation.

These notices are always sent and are the one category that ignores email_preferences: whoever made the change controls the account, so an opt-out would be something an attacker could set on the owner’s behalf before taking it. They carry no List-Unsubscribe header and no unsubscribe link, and say so in the footer.

Setting or changing a password additionally revokes every refresh token for that account and returns a fresh access_token/refresh_token pair in the response body. Clients that keep tokens of their own must swap to them, or the caller is signed out at its next refresh along with everyone else. Outstanding access tokens are unaffected and remain valid until they expire (ACCESS_TOKEN_EXPIRE_SECONDS, one hour by default).

Connecting or disconnecting a provider does not revoke anything: it invalidates no credential the account still holds.

Adding a password to a social account

POST /api/v1/account/password with new_password and confirm_password sets a first password on an account that has none. It only ever adds: changing an existing password still requires the current one (POST /api/v1/auth/change-password), and this endpoint returns 409 PASSWORD_ALREADY_SET if one is already in place. The account’s email must be verified first — it returns 403 EMAIL_NOT_VERIFIED otherwise, so an address a provider never vouched for cannot be claimed this way. The ordinary forgot-password email works for these accounts too.

Connecting a provider to the account you are signed in as

POST /api/v1/account/social-accounts/link-intent with a provider returns an authorize_url to send the browser to. The account being connected to is carried in a single-use, server-side intent token — never in the URL — so the callback cannot be redirected onto a different account.

When a provider’s email already has an account

Signing in with a provider whose email already belongs to a Moyo account does not merge anything automatically. What happens depends on what the provider asserts:

  • Verified email. You are sent to a confirmation screen. If the existing account has a password, you confirm with it; if it has none, the explicit consent step is the confirmation. Declining changes nothing — no account is created and nothing is linked.
  • Unverified email. The connection is refused outright and you are returned to sign-in. Linking on an address the provider will not vouch for would let anyone who registered that address at the provider take over the existing account.

Identity is the (provider, account ID) pair, not the email address: changing your email at the provider does not disconnect you, and a provider account can only ever be connected to one Moyo account (enforced by a unique index, not only by an application check). The reverse also holds — one Moyo account carries at most one identity per provider; connecting a second Google account returns 409 PROVIDER_ALREADY_CONNECTED rather than accumulating a row the UI cannot show or remove.

Removing a method

DELETE /api/v1/account/social-accounts/{id} disconnects a provider. It returns 400 LAST_SIGN_IN_METHOD if it would leave the account with no way in — set a password first.

Two-factor authentication

2FA is TOTP-based (Google Authenticator, Authy, etc.), not a stub:

1

Set up

POST /api/v1/auth/2fa/setup returns a base32 secret, an otpauth:// URI to render as a QR code, and one-time backup codes.

2

Confirm

POST /api/v1/auth/2fa/confirm with a 6-digit code from your authenticator app turns 2FA on.

3

Verify at login

After a login returns requires_2fa: true, call POST /api/v1/auth/2fa/verify with the temp_token and a 6-digit code to receive the real access_token/refresh_token. This endpoint is rate-limited to 5 attempts/minute. Social sign-in challenges the same way: POST /api/v1/auth/oauth/exchange returns requires_2fa: true and a temp_token instead of tokens when the account has 2FA on.

You can disable 2FA (POST /api/v1/auth/2fa/disable, requires a valid code, plus the account password when the account has one), check status (GET /api/v1/auth/2fa/status), or regenerate backup codes (POST /api/v1/auth/2fa/backup-codes).

How tokens are used

Once you’re authenticated, requests carry credentials one of two ways:

  • Authorization: Bearer <access_token> header, or
  • HttpOnly cookies the API sets on the login response — moyo_session and moyo_refresh, scoped to your organization’s whole domain for SSO across Moyo Suite subdomains.

The Moyo Suite web app itself doesn’t read those SSO cookies directly. Its frontend makes a server-to-server call to /api/v1/auth/login, then writes its own first-party accessToken/refreshToken cookies from the JSON response. If you’re calling the API directly (not through the Moyo Suite web app), the moyo_session/moyo_refresh cookies above are the ones that matter.

POST /api/v1/auth/refresh (with a body token or the moyo_refresh cookie) rotates both tokens before they expire.

Rotation revokes the presented refresh_token, but a token that was rotated in the last few seconds is still accepted, and simply yields another new pair. Without that window, a client with several tabs open signs itself out: every tab notices the expired access token at the same moment and refreshes with the same credential, so one succeeds and the rest get a 401. Replaying a token after that window is still rejected.

refresh_tokens are long-lived credentials — never log them or expose them to client-side JavaScript. The cookie-based flow keeps them HttpOnly for exactly this reason.

Sessions

The Moyo Suite web app warns you about 5 minutes before your access token expires, with a Stay logged in option that calls /auth/refresh in the background and extends your session in place — you’re never silently logged out mid-form. This is purely a frontend convenience; the API’s own expiry/refresh behavior above is unchanged either way.

You can see and manage every device you’re signed in on:

EndpointWhat it does
GET /api/v1/auth/sessionsList active sessions
POST /api/v1/auth/sessions/revokeRevoke one session
POST /api/v1/auth/sessions/revoke-othersSign out every session except this one
POST /api/v1/auth/logout-allSign out everywhere

Signing up

POST /api/v1/auth/signup creates a brand-new organization and its first admin user in a single call (email, password, tenant_name, subdomain, initial_modules) — this is what powers Creating Your Organization. Joining an existing organization instead happens via a team invite; see Team & Permissions.