Quickstart
Sign-in on a website, end to end: from creating the app to a protected API. About ten minutes.
1. Create the app
- Sign in at account.novren.net/console. The console asks you to turn on two-factor authentication first: it creates credentials that open your users' data. See Access, 2FA and sudo mode.
- Press New app and give it a name. Your users see this name and the logo on the consent page.
- You get an app id such as
app-0123456789abcdef0123. It is theaudof your tokens.
2. Add a client
A client is one way into your app: your website, your desktop app, your staging site. Each has its own callback URL, where the user comes back after signing in.
- In the app, open Clients → New client.
- Write the callback URL of your site, for example
https://myapp.example/callback. During developmenthttp://localhost:5173/callbackworks too. - You get a client id such as
cl-0123456789abcdef0123.
Rules for callback URLs are in Create apps and clients.
3. Install the SDK
npm install @novren/id-client @novren/id-verifier4. Add the sign-in button
On any page of your site:
import { beginLogin } from '@novren/id-client/app'
async function signIn() {
const { url } = await beginLogin({
accountUrl: 'https://account.novren.net',
clientId: 'cl-0123456789abcdef0123', // your client, from the console
redirectUri: 'https://myapp.example/callback', // registered on that client
})
location.assign(url)
}beginLogin prepares the request (PKCE, a random state, an ephemeral key pair), keeps the secret part in sessionStorage for this tab, and returns the address of the Novren ID sign-in page.
5. Complete the sign-in on the callback page
On the page at your callback URL:
import { completeLogin, LoginRejected } from '@novren/id-client/app'
async function onCallbackPage() {
// The user pressed "Deny" on the consent page.
const params = new URLSearchParams(location.search)
if (params.get('error') === 'access_denied') {
history.replaceState(null, '', location.pathname)
return showMessage('Sign-in cancelled.')
}
try {
const login = await completeLogin({
idServerUrl: 'https://id.novren.net',
clientId: 'cl-0123456789abcdef0123',
redirectUri: 'https://myapp.example/callback', // exactly the one used in beginLogin
})
// login.accountId the user's Novren ID (stable: use it as your user id)
// login.email to show in the UI; it never reached any server
// login.tokens access token (5 minutes) + refresh token
// login.productKey your app's key for this user (non-extractable CryptoKey)
startSession(login)
} catch (error) {
if (error instanceof LoginRejected) return showMessage('Sign-in failed, please try again.')
throw error // network error or Novren ID unavailable: offer a retry
}
}completeLogin checks the state, opens the sealed key with the ephemeral key, exchanges the one-time code for tokens and removes everything from the address bar.
6. Protect your API
Create a service token in the console (the app's Service token tab). It is shown once: put it in your server's environment as NOVREN_ID_SERVICE_TOKEN. Then:
import { createTokenVerifier, TokenRejected } from '@novren/id-verifier'
const verifier = createTokenVerifier({
idServerUrl: 'https://id.novren.net',
product: 'app-0123456789abcdef0123', // your app id, from the console
serviceToken: process.env.NOVREN_ID_SERVICE_TOKEN!, // never in the browser
})
await verifier.start() // first read of the revocations, then every 5 secondsasync function handle(request: Request): Promise<Response> {
const header = request.headers.get('authorization') ?? ''
const token = header.startsWith('Bearer ') ? header.slice(7) : undefined
try {
const claims = await verifier.verify(token)
const userId = claims.sub // the Novren ID account id
return Response.json(await loadNotes(userId))
} catch (error) {
if (error instanceof TokenRejected) {
// invalid / revoked: the client refreshes or signs in again.
// unavailable: we could not read the revocations for 60 s; fail closed.
const status = error.reason === 'unavailable' ? 503 : 401
return new Response(null, { status, headers: { 'www-authenticate': 'Bearer' } })
}
throw error
}
}7. Try it
- Open your site and press the button: you land on
account.novren.net. - Create an account or sign in, then press Allow.
- You are back on your callback page with
accountId,email,tokensandproductKey. - Call your API with
Authorization: Bearer <access_token>.
In the console, the app's Log tab, under Sign-ins, shows the consent and the token exchange you just made.
Next steps
- Keep users signed in: refresh tokens and logout.
- Encrypt user data with
productKey. - Deleted accounts: erase data when a user leaves.