Guides
Continue as
The browser’s own sign-in prompt on your pages, with a small loginos window everywhere else.
The loginos SDK signs people in on your own pages, without a redirect. In Chrome and Edge the browser itself asks “Continue as Jane?” (this is FedCM); in other browsers a small loginos window opens and closes itself. Either way your page gets the same kind of one-time code as the redirect flow, and your server exchanges it.
Sign in to your-app.example with loginos.io
Jane Doe
jane@example.com
Add the SDK
Load it on the pages where signed-out people land. The page must be on one of your platform’s domains.
<button id="sign-in">Sign in with loginos</button>
<script src="https://loginos.io/sdk/v1.js"></script>
<script>
const loginos = Loginos.init({ appKey: "YOUR_APP_KEY" });
// On page load: Chrome and Edge ask "Continue as …?" when the visitor is signed in to
// loginos, and sign returning members in by themselves. Resolves null anywhere else.
loginos.prompt().then(finish);
// Your own button works in every browser (a small loginos window where there's no prompt).
document.querySelector("#sign-in").onclick = () => loginos.signIn().then(finish);
async function finish(result) {
if (!result) return; // dismissed, or not signed in to loginos
const res = await fetch("/api/auth/login/single/token", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify(result),
});
if (res.ok) location.reload();
}
</script>Exchange the code
The same exchange as a callback code, without redirect_uri and without code_verifier. Check that the ID token carries the nonce you got:
// app/api/auth/login/single/token/route.ts
import { NextResponse, type NextRequest } from "next/server";
export async function POST(req: NextRequest) {
const { code, nonce } = await req.json();
const res = await fetch("https://loginos.io/oauth/token", {
method: "POST",
body: new URLSearchParams({
grant_type: "authorization_code",
code,
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 });
const { user, id_token } = await res.json();
// The token came straight from loginos over TLS; the nonce ties it to this page's request.
const claims = JSON.parse(Buffer.from(id_token.split(".")[1], "base64url").toString());
if (claims.nonce !== nonce) return new Response("Sign-in failed.", { status: 401 });
const done = new NextResponse(null, { status: 204 });
await startYourSession(done, user); // your own session
return done;
}API
| Call | Returns | |
|---|---|---|
Loginos.init({ appKey }) | a client | appKey is your 32-character app key. Any option below can be set here as a default. |
prompt(options?) | Promise<{ code, nonce, via, auto } | null> | The browser’s prompt only. Call it on page load; null where the browser has none or the visitor dismisses it. auto is true when the browser signed a returning member in by itself. |
signIn(options?) | Promise<{ code, nonce, via } | null> | Call it from a click. The browser’s prompt where there is one, otherwise a loginos window. |
signOut() | Promise<void> | Call it before you sign someone out, so the browser doesn’t sign them straight back in. |
disconnect(accountHint?) | Promise<boolean> | Removes your site’s access from the visitor’s loginos account (browsers with the prompt). |
canPrompt | boolean | Whether this browser has its own prompt. |
| Option | |
|---|---|
nonce | Your own nonce. A random one is made otherwise and returned with the code. |
scope | Default openid profile email. |
lang | The language of the loginos window, one of the 16 languages (de, ja, …). |
loginHint | An email or username to preselect in the browser’s prompt. |
context | The prompt’s wording: signin (default), signup, use or continue. |
auto | false stops the browser from signing returning members in by itself. |
via is fedcm or popup, if you want to know which one ran.
Good to know
- Your page learns nothing about the visitor unless they continue.
- The loginos window needs a user gesture: call
signIn()directly in the click handler, not after anawait. - Don’t send
Cross-Origin-Opener-Policy: same-originon pages that use the SDK: it cuts the loginos window off from your page.same-origin-allow-popupsis fine. - Codes from the SDK are exchanged like any other code and count as a sign-in on the domain the page is on.
- People the browser signs in by itself (
auto: true) still approved your platform before. To ask every time, passauto: false.