Skip to main content

Email & Password

Email and password is the foundational authentication method in YorAuth. Users register with a name, email address, and password. After verifying their email, they can log in to receive a JWT access token and refresh token.

Register a User

Create a new user account for your application.

Endpoint: POST /api/v1/applications/{applicationId}/users/register

Request Body

FieldTypeRequiredDescription
emailstringYesValid email address. Must be unique within the application.
passwordstringYesMust meet password strength requirements.
namestringYesDisplay name, up to 255 characters.
metadataobjectNoArbitrary JSON object for custom user data.
bash
curl -X POST https://api.yorauth.com/api/v1/applications/your-application-id/users/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "jane@example.com",
    "password": "Str0ng!Passw0rd",
    "name": "Jane Doe",
    "metadata": {
      "plan": "starter",
      "referral_code": "FRIEND10"
    }
  }'
javascript
const response = await fetch(
  'https://api.yorauth.com/api/v1/applications/your-application-id/users/register',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      email: 'jane@example.com',
      password: 'Str0ng!Passw0rd',
      name: 'Jane Doe',
      metadata: { plan: 'starter' }
    })
  }
);
const data = await response.json();

Response 201 Created

json
{
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "email": "jane@example.com",
    "name": "Jane Doe",
    "email_verified": false,
    "created_at": "2026-02-25T10:00:00Z",
    "metadata": {
      "plan": "starter",
      "referral_code": "FRIEND10"
    }
  },
  "message": "Registration successful. Please check your email to verify your account."
}

Error Responses

HTTP StatusError CodeDescription
400VALIDATION_MULTIPLE_ERRORSMultiple field validation failures
400VALIDATION_INVALID_FORMATSingle field validation failure (e.g. invalid email format)
409Inline messageEmail already registered for this application
422VALIDATION_PASSWORD_TOO_WEAKPassword does not meet requirements
403tier_limit_exceededApplication has reached its user limit

After registration, a verification email is sent automatically. Users can log in before verifying their email, but your application may choose to enforce verification before granting access. Use the email verification endpoints to manage this.


Log In

Authenticate an existing user with their email and password.

Endpoint: POST /api/v1/applications/{applicationId}/users/login

Request Body

FieldTypeRequiredDescription
emailstringYesThe user's email address.
passwordstringYesThe user's password.
remember_mebooleanNoIf true, the refresh token expires in 30 days instead of 7.
bash
curl -X POST https://api.yorauth.com/api/v1/applications/your-application-id/users/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "jane@example.com",
    "password": "Str0ng!Passw0rd",
    "remember_me": false
  }'
javascript
const response = await fetch(
  'https://api.yorauth.com/api/v1/applications/your-application-id/users/login',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      email: 'jane@example.com',
      password: 'Str0ng!Passw0rd',
      remember_me: false
    })
  }
);
const data = await response.json();

Response 200 OK — Successful Login

json
{
  "data": {
    "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
    "refresh_token": "ref_a1b2c3d4e5f6...",
    "token_type": "Bearer",
    "expires_in": 900,
    "user": {
      "id": "550e8400-e29b-41d4-a716-446655440000",
      "email": "jane@example.com",
      "name": "Jane Doe",
      "email_verified": true,
      "created_at": "2026-02-25T10:00:00Z",
      "metadata": null
    }
  }
}

Response 200 OK — MFA Required

If the user has TOTP MFA enabled, login does not immediately return tokens. Instead, it returns a challenge token:

json
{
  "data": {
    "mfa_required": true,
    "challenge_token": "mfa_challenge_xyz789abc",
    "mfa_methods": ["totp"]
  }
}

Pass the challenge_token and the user's TOTP code to the MFA verification endpoint to complete login. See Multi-Factor Authentication for details.

Error Responses

HTTP StatusError CodeDescription
401AUTH_INVALID_CREDENTIALSEmail or password is incorrect.
403AUTH_ACCOUNT_SUSPENDEDThe account has been suspended.
429AUTH_ACCOUNT_LOCKEDToo many failed attempts — account locked for 15 minutes.

After 5 consecutive failed login attempts for the same email, the account is locked for 15 minutes. This is enforced per email address per application, not per IP address.


Log Out

Revoke the current session's refresh token. The access token remains valid until it expires (up to 15 minutes), but the refresh token is immediately invalidated so no new access tokens can be issued.

Endpoint: POST /api/v1/applications/{applicationId}/users/logout

Request Body

FieldTypeRequiredDescription
refresh_tokenstringYesThe refresh token to revoke.
bash
curl -X POST https://api.yorauth.com/api/v1/applications/your-application-id/users/logout \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access_token>" \
  -d '{
    "refresh_token": "ref_a1b2c3d4e5f6..."
  }'
javascript
await fetch(
  'https://api.yorauth.com/api/v1/applications/your-application-id/users/logout',
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${accessToken}`
    },
    body: JSON.stringify({ refresh_token: refreshToken })
  }
);

Response 204 No Content

No body is returned on successful logout.


Change Password

Allow an authenticated user to update their own password. Requires the current password for verification.

Endpoint: POST /api/v1/applications/{applicationId}/users/{userId}/change-password

Authentication: JWT Bearer token required. The authenticated user must own the {userId} in the path.

Request Body

FieldTypeRequiredDescription
current_passwordstringYesThe user's existing password.
new_passwordstringYesThe new password. Must meet strength requirements.
new_password_confirmationstringYesMust match new_password.
bash
curl -X POST https://api.yorauth.com/api/v1/applications/your-application-id/users/550e8400-e29b-41d4-a716-446655440000/change-password \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access_token>" \
  -d '{
    "current_password": "Str0ng!Passw0rd",
    "new_password": "Even$tronger2026",
    "new_password_confirmation": "Even$tronger2026"
  }'
javascript
await fetch(
  `https://api.yorauth.com/api/v1/applications/your-application-id/users/${userId}/change-password`,
  {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${accessToken}`
    },
    body: JSON.stringify({
      current_password: 'Str0ng!Passw0rd',
      new_password: 'Even$tronger2026',
      new_password_confirmation: 'Even$tronger2026'
    })
  }
);

Response 200 OK

json
{
  "data": {
    "message": "Password changed successfully."
  }
}

Error Responses

HTTP StatusError CodeDescription
422INVALID_PASSWORDCurrent password is incorrect.
400VALIDATION_MULTIPLE_ERRORSValidation failures (e.g. passwords don't match).

Forgot Password

Send a password reset email. Returns success regardless of whether the email exists to prevent email enumeration.

Endpoint: POST /api/v1/applications/{applicationId}/users/password/forgot

Request Body

FieldTypeRequiredDescription
emailstringYesThe email address to send the reset link to.
bash
curl -X POST https://api.yorauth.com/api/v1/applications/your-application-id/users/password/forgot \
  -H "Content-Type: application/json" \
  -d '{"email": "jane@example.com"}'
javascript
await fetch(
  'https://api.yorauth.com/api/v1/applications/your-application-id/users/password/forgot',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ email: 'jane@example.com' })
  }
);

Response 200 OK

json
{
  "data": {
    "message": "If an account with that email exists, a password reset link has been sent."
  }
}
HTTP StatusError CodeDescription
429AUTH_PASSWORD_RESET_RATE_LIMITEDMore than 3 reset requests in 15 minutes for this email.

Reset Password

Complete a password reset using the token from the reset email.

Endpoint: POST /api/v1/applications/{applicationId}/users/password/reset

Request Body

FieldTypeRequiredDescription
tokenstringYesThe reset token from the email link.
emailstringYesThe user's email address.
passwordstringYesThe new password. Must meet strength requirements.
bash
curl -X POST https://api.yorauth.com/api/v1/applications/your-application-id/users/password/reset \
  -H "Content-Type: application/json" \
  -d '{
    "token": "abc123def456...",
    "email": "jane@example.com",
    "password": "NewStr0ng!Pass"
  }'
javascript
await fetch(
  'https://api.yorauth.com/api/v1/applications/your-application-id/users/password/reset',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      token: 'abc123def456...',
      email: 'jane@example.com',
      password: 'NewStr0ng!Pass'
    })
  }
);

Response 200 OK

json
{
  "data": {
    "message": "Your password has been reset successfully."
  }
}

Error Responses

HTTP StatusError CodeDescription
400AUTH_INVALID_RESET_TOKENToken does not match the email or was already used.
410AUTH_RESET_TOKEN_EXPIREDToken has expired. Request a new reset link.

Email Verification

Verify Email Address

Endpoint: POST /api/v1/applications/{applicationId}/users/email/verify

FieldTypeRequiredDescription
tokenstringYesThe verification token from the email link.
bash
curl -X POST https://api.yorauth.com/api/v1/applications/your-application-id/users/email/verify \
  -H "Content-Type: application/json" \
  -d '{"token": "verify_token_here"}'

Response 200 OK

json
{
  "data": {
    "message": "Email address verified successfully."
  }
}
HTTP StatusError CodeDescription
400AUTH_INVALID_VERIFICATION_TOKENToken is invalid or already used.
410AUTH_VERIFICATION_TOKEN_EXPIREDToken has expired.

Resend Verification Email

Endpoint: POST /api/v1/applications/{applicationId}/users/email/resend

FieldTypeRequiredDescription
emailstringYesThe user's email address.
bash
curl -X POST https://api.yorauth.com/api/v1/applications/your-application-id/users/email/resend \
  -H "Content-Type: application/json" \
  -d '{"email": "jane@example.com"}'

Response 200 OK

json
{
  "data": {
    "message": "If an account with that email exists and is not verified, a verification email has been sent."
  }
}
HTTP StatusError CodeDescription
429AUTH_VERIFICATION_RATE_LIMITEDMore than 2 resend requests per minute for this email.