For the complete documentation index, see llms.txt. This page is also available as Markdown.

Neucron OAuth 2.0 SDK

This guide shows how to add Sign in with Neucron to any application using the @timechainlabs/neucron-ts-sdk. The flow is stack-agnostic — adapt the route names and session storage to your framework (E

Overview

Sign in with Neucron authenticates users with their Neucron account and returns an access token your application uses as a bearer credential for Neucron REST APIs.

Your application:

  1. Redirects the user to Neucron for authentication.

  2. Receives an authorization code on your registered callback URL.

  3. Exchanges the code for an access_token on the server (client secret never leaves the backend).

  4. Stores the token and uses it for authorized Neucron API calls.


OAuth flow


Prerequisites

  • Access to the Neucron developer / OAuth console

  • An OAuth client registered for your platform / app

  • A publicly reachable (or locally tunneled) redirect URI

  • A backend that can hold client_secret securely

  • Test users granted access to your platform on Neucron


Register your OAuth application

  1. Open the Neucron OAuth / developer console.

  2. Create an OAuth application.

  3. Set the platform / app name (e.g. YourApp). This must match the platform parameter you send in the authorize request.

  4. Copy the Client ID and Client Secret.

  5. Register exact redirect URIs, for example:

    • Development: https://localhost:3000/auth/callback

    • Production: https://your-domain.com/auth/callback

redirect_uri must match exactly (scheme, host, port, path) in:

  • the Neucron console registration

  • the authorize request

  • the token exchange request


SDK setup

Install the SDK:

Store credentials in environment variables (never expose client_secret to the browser):

Create a shared SDK instance with OAuth defaults:

SDK OAuth methods

Method
Endpoint
Purpose

sdk.oauth.authorize()

GET /oauth/authorize

Returns { redirect_url } for hosted login

sdk.oauth.exchangeToken()

GET /oauth/token

Exchanges code for { access_token } and stores token on sdk.auth

generateOAuthState()

Generates a random CSRF state value

After exchangeToken(), call any protected SDK method — for example sdk.auth.userInfo().


Backend implementation

1. Start login — GET /auth/login

When OAuth defaults are configured on the SDK instance, you can omit client_id, redirect_uri, and platform from each call.

2. Handle callback — GET /auth/callback

3. Session endpoint — GET /auth/me

4. Logout — POST /auth/logout


Frontend integration

Sign-in button

Use a full-page redirect (not XHR alone) so the browser can follow Neucron’s hosted login redirects:

Post-login bootstrap

On app load:

  1. Call GET /auth/me with credentials: 'include'.

  2. If authenticated, hydrate user profile and app data from Neucron APIs.


API usage after login

The access token works as the Authorization header for Neucron REST APIs:

Typical hydration after sign-in:

  • GET /auth/user/info

  • Load businesses / teams

  • Resolve roles / permissions

  • Load product-specific resources (wallets, assets, etc.)


Flows: sign-in vs sign-up

Both use the same authorize → callback → token exchange pipeline. Pass flow: 'sign-in' or flow: 'sign-up' to sdk.oauth.authorize() — only the hosted UI path differs.


Security guidelines

  • Never expose client_secret to browsers, mobile binaries, or public repos.

  • Always use HTTPS in production for authorize, callback, and token exchange.

  • Generate a random state per login attempt and verify it on callback (CSRF protection). Use generateOAuthState() from the SDK.

  • Prefer httpOnly, Secure, SameSite=Lax cookies for browser sessions.

  • Keep redirect URI allowlists tight.

  • On logout, clear both server session cookies and any client-stored tokens.

  • Treat the access token as opaque; do not rely on client-side JWT decoding for authorization decisions.


Verification checklist


Reference

Endpoints

Step
Method
Path

Authorize

GET

/v1/oauth/authorize

Token exchange

GET

/v1/oauth/token

Authorize parameters

response_type, client_id, redirect_uri, state, platform, flow

Token parameters

grant_type=authorization_code, code, redirect_uri, client_id, client_secret, state

Platform name

platform is project-specific. Register it in the Neucron console and send the same string from your login handler. Do not reuse another application’s platform name.


MCP tools (optional)

If you use the Neucron MCP server, equivalent tools are available:

MCP Tool
SDK equivalent

neucron_oauth_authorize

sdk.oauth.authorize()

neucron_oauth_exchange_token

sdk.oauth.exchangeToken() + sdk.auth.userInfo()


Neucron OAuth 2.0 Authorization Code — Sign in with Neucron. Applicable to any application stack.

Last updated