loginos

Get started

Quickstart

Add “Sign in with loginos” to an app with a server: create a platform, redirect, exchange the code.

This guide adds “Sign in with loginos” to an app with a server. It is the standard OpenID Connect authorization code flow with PKCE, so if you use an OIDC library, point it at https://loginos.io/.well-known/openid-configuration and skip to step 3 for what you get back.

1. Create a platform

  1. Create a loginos account and open the developer console.
  2. Choose New platform, give it a name and your first domain: app.example.com, or localhost:3001 while you build.
  3. Copy the app secret now. It is shown once; you can rotate it later in Settings.

Add the rest of your domains in the Domains tab. They all share the same people.

Keep both credentials in your server’s environment:

.env
LOGINOS_APP_KEY=your 32-character app key
LOGINOS_APP_SECRET=lsk_…

2. Send people to loginos

When someone clicks “Sign in with loginos”, create a random state and a PKCE code_verifier, keep both in an HttpOnly cookie or your session, and redirect the browser:

Request
GET https://loginos.io/oauth/authorize
  ?client_id=YOUR_APP_KEY
  &redirect_uri=https://app.example.com/api/auth/login/single/callback
  &response_type=code
  &scope=openid profile email
  &state=RANDOM_STATE
  &code_challenge=BASE64URL(SHA256(code_verifier))
  &code_challenge_method=S256

Someone who is signed in to loginos and has used your platform before comes straight back. Everyone else signs in, or creates an account on the spot, and approves what you get, once. Add ui_locales=de (or any of the 16 languages) to choose the language of the loginos pages.

3. Exchange the code

loginos sends the browser back to your callback with ?code=…&state=…. Check that state matches the one you stored, then exchange the code from your server:

curl
curl -X POST https://loginos.io/oauth/token \
  -u "YOUR_APP_KEY:YOUR_APP_SECRET" \
  -d grant_type=authorization_code \
  -d code=THE_CODE \
  -d redirect_uri=https://app.example.com/api/auth/login/single/callback \
  -d code_verifier=THE_VERIFIER

The answer carries the tokens and the person, so one request is enough to sign them in:

Response
{
  "access_token": "lat_…",
  "token_type": "Bearer",
  "expires_in": 3600,
  "scope": "openid profile email",
  "id_token": "eyJhbGciOiJSUzI1NiIs…",
  "user": {
    "sub": "9b1f6c2e-5d1a-4b7e-9a51-0e6f3f6c1d2a",
    "preferred_username": "jane",
    "name": "Jane Doe",
    "picture": "https://loginos.io/api/avatars/9b1f6c2e-…?v=…",
    "email": "jane@example.com",
    "email_verified": false,
    "roles": ["member"],
    "permissions": ["posts:read"]
  }
}

Find or create your local user by sub (it never changes), then start your own session. Codes work once and expire after five minutes. If the person cancels, your callback gets ?error=access_denied&state=… instead.

Complete examples

The same flow in three stacks. Each has the redirect route and the callback; startYourSession stands for your own session code.

// app/api/auth/login/single/route.ts
import { createHash, randomBytes } from "node:crypto";
import { NextResponse, type NextRequest } from "next/server";

const LOGINOS = "https://loginos.io";
const b64url = (b: Buffer) => b.toString("base64url");

export function GET(req: NextRequest) {
  const state = b64url(randomBytes(16));
  const verifier = b64url(randomBytes(32));
  const url = new URL("/oauth/authorize", LOGINOS);
  url.search = new URLSearchParams({
    client_id: process.env.LOGINOS_APP_KEY!,
    redirect_uri: `${req.nextUrl.origin}/api/auth/login/single/callback`,
    response_type: "code",
    scope: "openid profile email",
    state,
    code_challenge: b64url(createHash("sha256").update(verifier).digest()),
    code_challenge_method: "S256",
  }).toString();
  const res = NextResponse.redirect(url);
  res.cookies.set("lo_flow", `${state}.${verifier}`, { httpOnly: true, secure: true, sameSite: "lax", maxAge: 600 });
  return res;
}

// app/api/auth/login/single/callback/route.ts
export async function GET(req: NextRequest) {
  const [state, verifier] = (req.cookies.get("lo_flow")?.value ?? "").split(".");
  if (!state || req.nextUrl.searchParams.get("state") !== state)
    return new Response("Sign-in expired, try again.", { status: 400 });

  const res = await fetch(`${LOGINOS}/oauth/token`, {
    method: "POST",
    body: new URLSearchParams({
      grant_type: "authorization_code",
      code: req.nextUrl.searchParams.get("code") ?? "",
      redirect_uri: `${req.nextUrl.origin}/api/auth/login/single/callback`,
      code_verifier: verifier,
      client_id: process.env.LOGINOS_APP_KEY!,
      client_secret: process.env.LOGINOS_APP_SECRET!,
    }),
  });
  if (!res.ok) return new Response("Sign-in failed.", { status: 401 });

  // { sub, preferred_username, name, picture, email, roles, permissions }
  const { user } = await res.json();
  const done = NextResponse.redirect(new URL("/", req.url));
  done.cookies.delete("lo_flow");
  await startYourSession(done, user); // your own session cookie
  return done;
}

Signing out

Clear your own session. That is usually all: the person stays signed in to loginos, as with any identity provider. To end their loginos session too, send the browser to:

Sign out of loginos
GET https://loginos.io/oauth/logout?client_id=YOUR_APP_KEY&post_logout_redirect_uri=https://app.example.com/

post_logout_redirect_uri must be on one of your domains; otherwise the person lands on the loginos sign-in page.

Many domains

There is no limit on how many domains a platform has, and all of them share the same people. Add them in the console one at a time or as a pasted list, register them from your server when a customer connects one, cover every subdomain with a wildcard like *.example.com, or let loginos ask your server the first time a new one is used. See Domains.

Next steps

  • Already have accounts? Link them instead of creating duplicates.
  • Continue as: sign people in without sending them away.
  • Domains: lists, wildcards, and domains your server confirms as people sign in.
  • Roles and permissions: decide who can do what, once, for every domain.
  • Build with AI: the same integration as a prompt for your coding agent.