Ir al contenido
AtheronDEVELOPERS
← Java and Kotlin SDK

Spring Boot (Java and Kotlin)

Sign in with Atheron in Spring Boot.

Inicie sesión para ver su propio ID de cliente de prueba en los ejemplos.

Coming soon. org.aton-network:aton-network-sdk is not published on Maven Central yet, so the install line on this page does not work until it is. Until then, everything works over plain HTTP: pick cURL in any code block, or start from Endpoints.

The starter signs people in on Spring Boot's servlet session with nothing to configure but your app's settings: the routes, @AtheronRequired for a page only for somebody signed in, @AtheronUser for the person, and AtheronWebhooks for deliveries. Spring Boot 3.

Set ATHERON_CLIENT_ID, ATHERON_CLIENT_SECRET and ATHERON_REDIRECT_URI on your server (or atheron.client-id, atheron.client-secret and atheron.redirect-uri in application.properties), and ATHERON_WEBHOOK_SECRET (or atheron.webhook-secrets) for webhooks.

The starter adds /auth/sign-in, /auth/callback, /auth/sign-out (a POST from your own site) and /auth/session on the servlet session. Register https://your.app/auth/callback as the redirect address.

The app

Este ejemplo aún no está escrito en cURL. Se muestra en Next.js.

// app/auth/[...atheron]/route.ts: every Sign in with Atheron route in one file.
// Set ATHERON_CLIENT_ID, ATHERON_CLIENT_SECRET, ATHERON_SECRET and
// ATHERON_REDIRECT_URI=https://your.app/auth/callback (the address you registered).
import { Atheron } from "@aton-network/nextjs";

const atheron = Atheron();

export const { GET, POST } = atheron.handlers;

Protect a page

@AtheronRequired works on a method or a whole controller. A request that asks for JSON gets a 401 instead of the trip to sign in.

Este ejemplo aún no está escrito en cURL. Se muestra en Next.js.

// proxy.ts (middleware.ts before Next 16): anybody not signed in goes to Atheron first, then back.
import { Atheron } from "@aton-network/nextjs";

const atheron = Atheron({ protect: ["/account", "/settings"] });

export async function proxy(request: Request): Promise<Response | undefined> {
  return atheron.proxy(request);
}

// In a server component, read the person with: await atheron.user(await cookies())

Webhooks

PKCE, state and nonce are checked on every sign-in, the flow is spent on use and lasts ten minutes, the session ID changes when somebody signs in, a return address is always a path on your site, signing out revokes the refresh token at Atheron, and a sign-out from another site is refused.

With Spring Security on the classpath the routes stay off (Spring Security guards every path); use Spring Security, or set atheron.routes.enabled=true and permit them yourself.

Este ejemplo aún no está escrito en cURL. Se muestra en TypeScript.

// Check that a webhook came from Atheron before you act on it. Pass the raw body, exactly as received.
import { verifyWebhook, type WebhookEvent } from "@aton-network/sdk";

export async function handleWebhook(request: Request): Promise<Response> {
  const raw = await request.text();
  const ok = await verifyWebhook(request.headers.get("atheron-signature"), raw, process.env.ATHERON_WEBHOOK_SECRET!);
  if (!ok) return new Response("bad signature", { status: 400 });
  const event = JSON.parse(raw) as WebhookEvent;
  if (event.type === "consent.revoked") {
    // Delete the refresh token you hold for event.data.sub, and stop using what you read.
  }
  return new Response(null, { status: 204 });
}

Pregunte a Atlas

Asistente de IA

Pregunte lo que quiera sobre Iniciar sesión con Atheron, la API o el portal. La respuesta sale de nuestra documentación, con enlaces a las páginas usadas.