Skip to main content

POST /api/auth/login

Log in to get a JWT token.

POST /api/auth/register

Register a new user.

GET /api/auth/user

Get the currently authenticated user.

POST /api/auth/change-password

Change the password for the current user.

POST /api/auth/passkey/login

Sign in with a passkey.

GET /api/auth/passkeys

List, add, and remove the current user’s passkeys.

Login

Authenticates a user and returns a JWT token along with user details.
  • Endpoint: /api/auth/login
  • Method: POST
  • Body:
    • username (string, required): The user’s username.
    • password (string, required): The user’s password.
  • Request Example:
  • Success Response:
  • Password login disabled: while Better Auth’s disablePasswordLogin is in effect, the endpoint answers 403 with {"success": false, "message": "Password login is disabled. Sign in with SSO, or use a bearer key for API access."}. See SSO-only sign-in.

Register

Registers a regular user and returns a JWT token. Requires systemConfig.auth.allowRegistration: true (default: false) and password login to be enabled; otherwise returns HTTP 403.
  • Endpoint: /api/auth/register
  • Method: POST
  • Body:
    • username (string, required): The desired username.
    • password (string, required): The desired password (at least 8 characters, including a letter, a number, and a special character).
    • Administrator privileges cannot be requested; isAdmin is ignored.
  • Request Example:
  • Success Response:

Get Current User

Retrieves the profile of the currently authenticated user.
  • Endpoint: /api/auth/user
  • Method: GET
  • Authentication: Bearer Token required.
  • Success Response:

Change Password

Allows the authenticated user to change their password.
  • Endpoint: /api/auth/change-password
  • Method: POST
  • Authentication: Bearer Token required.
  • Body:
    • currentPassword (string, required): The user’s current password.
    • newPassword (string, required): The desired new password (must be at least 6 characters).
  • Request Example:
  • Success Response:

Passkey Sign-in

Signs in with a passkey (WebAuthn discoverable credential) in two steps. The browser side is what @simplewebauthn/browser produces: pass options to startAuthentication({ optionsJSON: options }) and send its result back. See Passkeys for requirements and behavior. Both endpoints are public. While SSO-only sign-in is in effect they answer 403. The relying party is taken from the request’s Origin header (or its host and protocol). 1. Request a challenge
  • Endpoint: /api/auth/passkey/options
  • Method: POST
  • Success Response:
The challengeToken is valid for five minutes and can be used once. 2. Verify the assertion
  • Endpoint: /api/auth/passkey/login
  • Method: POST
  • Body:
    • challengeToken (string, required): The token from step 1.
    • response (object, required): The AuthenticationResponseJSON returned by the browser.
  • Success Response: the same token and user fields as Login.
  • Failure: 401 with {"success": false, "code": "passkey_login_failed", "message": "Passkey sign-in failed"} for an unknown, removed, revoked, or invalid passkey, a reused or expired challenge, or another origin. Every passkey error response carries such a code.

Manage Passkeys

Endpoints for the signed-in user’s own passkeys. They require a dashboard session (JWT or Better Auth session) of a local account; bearer keys, forward-auth identities, and skip-auth mode receive 403.
  • List: GET /api/auth/passkeys
    Credential IDs and public keys are never returned. rpId is the host name the passkey works on. Passkeys revoked by a password change are not listed. registrationAvailable is false while SSO-only sign-in is in effect.
  • Start registration: POST /api/auth/passkeys/registration/options
    • Body: currentPassword (string, required).
    • Response: options for startRegistration({ optionsJSON: options }) and a challengeToken, as in passkey sign-in.
    • A wrong password answers 400 (not 401, which would end the dashboard session). Failed attempts count against the login rate limit.
  • Finish registration: POST /api/auth/passkeys
    • Body: challengeToken (string, required), response (RegistrationResponseJSON, required), name (string, optional, up to 64 characters).
    • Response: 201 with the new passkey in data. 409 if the credential is already registered; 400 when the challenge expired, belongs to another user, or the response cannot be verified.
  • Remove: DELETE /api/auth/passkeys/:id removes one of the user’s passkeys. Another user’s passkey answers 404.

Social Login (Better Auth)

MCPHub integrates Better Auth to provide seamless social login capabilities (GitHub, Google, etc.). Prerequisites:
  1. Database Mode: DB_URL environment variable must be configured (PostgreSQL is required for Better Auth persistence).
  2. Provider Configuration: Better Auth bootstrap settings are read once at startup, so restart MCPHub after changing them.
  3. Environment Variables:
  • Global: BETTER_AUTH_ENABLED, BETTER_AUTH_URL, optional BETTER_AUTH_BASE_PATH, optional BETTER_AUTH_TRUSTED_ORIGINS.
  • GitHub: BETTER_AUTH_GITHUB_ENABLED, GITHUB_CLIENT_ID, and GITHUB_CLIENT_SECRET.
  • Google: BETTER_AUTH_GOOGLE_ENABLED, GOOGLE_CLIENT_ID, and GOOGLE_CLIENT_SECRET.
  • Local OIDC: BETTER_AUTH_OIDC_ENABLED, optional BETTER_AUTH_OIDC_PROVIDER_ID, BETTER_AUTH_OIDC_DISCOVERY_URL (or legacy OIDC_DISCOVERY_URL), optional BETTER_AUTH_OIDC_SCOPES, optional BETTER_AUTH_OIDC_PKCE, optional BETTER_AUTH_OIDC_PROMPT, plus OIDC_CLIENT_ID and OIDC_CLIENT_SECRET.
Non-secret Better Auth settings can also be stored in systemConfig.auth.betterAuth, but the BETTER_AUTH_* environment variables take precedence over stored config values. Endpoints: The Better Auth handler is mounted at ${BASE_PATH}${betterAuthConfig.basePath}. The default betterAuthConfig.basePath is /api/auth/better; set BETTER_AUTH_BASE_PATH to override it at startup, or use systemConfig.auth.betterAuth.basePath as a fallback. BETTER_AUTH_URL takes precedence over systemConfig.install.baseUrl when MCPHub builds redirect URLs. If you also set BASE_PATH, prepend it to every example below. Key endpoints include:
  • Initiate Login:
    • GET /api/auth/better/signIn/social?provider=github
    • GET /api/auth/better/signIn/social?provider=google
  • Session Management:
    • GET /api/auth/better/session (Get current session)
    • POST /api/auth/better/signOut (Sign out)
For a complete list of endpoints and usage details, refer to the Better Auth API Documentation. Disabling Better Auth: Better Auth is automatically disabled if DB_URL is not configured, if BETTER_AUTH_ENABLED=false, or if no login providers are effectively enabled with their required credentials.