Skip to content
  • Android
  • iOS
  • Web

Auth

Start Google or Apple sign-in in the system browser and validate OAuth callback data using the Rust core.

API notes

  • createRequest() creates state and nonce values for both providers. Google also uses S256 PKCE and returns a codeVerifier for the backend exchange.
  • Pass the full Google callback URL including its query, or the Apple callback URL and raw form-encoded POST body. readCallback() returns success, cancelled or denied and rejects invalid callbacks.
  • Keep provider secrets on the backend. Consume each transaction once and verify the ID token signature, issuer, audience, expiry and nonce before issuing an app session.

Examples

Quick start

Use a Google Web application client ID or Apple Services ID and an HTTPS return URL registered with the provider. The backend binds the pending request to the initiating session, verifies the callback, exchanges the code, and verifies the ID token before creating a session.

nayan-ui/auth
import { auth, type SignInOptions, type SignInProvider, type SignInRequest } from 'nayan-ui/auth';

export async function startSignIn(
  provider: SignInProvider,
  options: SignInOptions,
  registerPending: (request: SignInRequest) => Promise<void>,
  openBrowser: (url: string) => void | Promise<void>
) {
  const request = await auth.createRequest(provider, options);
  await registerPending(request);
  await openBrowser(request.authorizationUrl);
}

Read a Google or Apple callback

Use the saved transaction. Google sends the code in the URL query. Apple sends a form-encoded POST body to your backend. The backend consumes the transaction once and exchanges the code.

nayan-ui/auth
import { auth, type SignInTransaction } from 'nayan-ui/auth';

export async function readProviderCallback(pending: SignInTransaction, url: string, body?: string) {
  const result = await auth.readCallback(pending, { url, body });
  return result.status === 'success' ? { code: result.code } : { status: result.status };
}

Tags