@novren/id-client/app
The browser SDK for apps: starts and completes the sign-in, refreshes and revokes tokens, shows the embedded form, checks directory entries. It never sees the password or the root key.
import { beginLogin, completeLogin, refreshTokens, revokeTokens } from '@novren/id-client/app'Requirements: a browser (or runtime) with Web Crypto, fetch and URL. beginLogin and completeLogin also need sessionStorage and history.
Sign-in with a redirect
beginLogin(input)
Prepares the sign-in and keeps the pending request in sessionStorage (key novren-id/pending-login, this tab only).
| Parameter | Type | Meaning |
|---|---|---|
accountUrl | string | https://account.novren.net |
clientId | string | your client id (cl-…) |
redirectUri | string | a callback URL registered on the client, written exactly |
locale | string? | language of the page, as ui_locales (details) |
Returns Promise<{ url: string }>: the address to navigate to.
A second beginLogin in the same tab replaces the previous pending request.
completeLogin(input)
On the callback page: completes the sign-in.
| Parameter | Type | Meaning |
|---|---|---|
idServerUrl | string | https://id.novren.net |
clientId | string | the same as in beginLogin |
redirectUri | string | the same as in beginLogin |
location | Location? | for tests; default window.location |
Returns Promise<LoginResult>.
Side effects: removes the pending request from sessionStorage and code/fragment from the address bar, even when it fails: a failed attempt can't be retried, start again with beginLogin.
Throws LoginRejected when: there is no pending request in this tab; it was made for another client or callback URL ("another app's sign-in"); state doesn't match; code, envelope, account or app are missing (also after a Deny); Novren ID refuses the code. Network errors propagate as they are.
LoginResult
| Field | Type | Meaning |
|---|---|---|
accountId | string | the account id (UUID). Stable: use it as your user id |
email | string | the account's email, to display. It came in the fragment: no server saw it |
product | string | your app id |
tokens | Tokens | see below |
productKey | CryptoKey | AES-GCM 256, non-extractable, encrypt and decrypt |
identity | ProductIdentity | encryptionSeed, encryptionPublicKey (X-Wing) and signing (Ed25519 key pair). The seeds are secrets: memory only |
Tokens
{ access_token: string; refresh_token: string; expires_in: number; token_type: 'Bearer' }expires_in is in seconds (300).
Tokens
refreshTokens(input)
| Parameter | Type | Meaning |
|---|---|---|
idServerUrl | string | https://id.novren.net |
clientId | string | your client id |
refreshToken | string | the latest refresh token |
Returns Promise<Tokens | null>:
Tokens: new access and refresh token. Store the new refresh token: the old one is dead;null: Novren ID answered 400 or 401, the chain is closed. Sign in again.
Throws Error for any other status (5xx, 429) and for network errors: retry later, don't sign the user out.
Reusing an old refresh token closes the whole chain: never run two refreshes with the same token. See Keep users signed in.
revokeTokens(input)
Same parameters as refreshTokens. Closes the chain (logout). Never throws and resolves even offline: logout must always succeed locally. Novren ID answers 200 even for unknown tokens (RFC 7009).
Embedded form
embedLogin(options)
Shows the sign-in form inside container and completes the sign-in. Options in Embedded sign-in form.
Returns Promise<EmbeddedLogin>:
result: Promise<LoginResult>: resolves when the sign-in is complete; rejects withLoginRejectedif the exchange fails;destroy(): void: removes the iframe and stops listening.
Throws before showing anything if redirectUri is not on the page's origin.
embedLoginFrame(options)
The lower level: shows the form for a sign-in URL prepared elsewhere (with createLoginRequest) and gives back only the return address. For extensions and native hosts.
| Option | Type | Meaning |
|---|---|---|
loginUrl | string | the url from createLoginRequest |
container | HTMLElement | where to put the iframe (its content is replaced) |
accent | string? | hex colour of the buttons |
locale | string? | language |
title | string? | accessible title of the iframe |
onOpen | (url) => void | opens account-page links; default a new tab |
Returns EmbeddedFrame: { returnUrl: Promise<string>; destroy(): void }. Complete with finishLoginResponse.
Only messages from that iframe and the account page's origin are accepted; links the form asks to open must be on the account page's origin; the return address must start with the request's redirect_uri.
Sign-in in separate steps
createLoginRequest(input)
Like beginLogin but stores nothing. Same parameters.
Returns Promise<{ url: string; pending: PendingLogin }>. pending contains state, the PKCE verifier and challenge, the ephemeral key's seed, clientId and redirectUri. It is a secret: keep it in memory for the few seconds of the sign-in, never on disk.
finishLoginResponse(input)
| Parameter | Type | Meaning |
|---|---|---|
idServerUrl | string | https://id.novren.net |
returnUrl | string | the full callback address, with query and fragment |
pending | PendingLogin | from createLoginRequest |
Returns Promise<LoginResult>. Throws LoginRejected like completeLogin. The ephemeral seed is wiped from memory at the end.
Directory
verifyDirectoryEntry(entry, pinnedFingerprint?)
Checks a public identity read from the directory before encrypting something for another user.
| Parameter | Type | Meaning |
|---|---|---|
entry | DirectoryLookup | the answer of GET /api/directory/lookup (HTTP API) |
pinnedFingerprint | string? | the fingerprint your app remembered for that person, if any |
Returns Promise<{ encryptionKey, signingKey, fingerprint, changed }>:
encryptionKey,signingKey:Uint8Array, the verified public keys;fingerprint: the fingerprint of the account's signing key, to compare outside the server (in person, on the phone) and then remember;changed:trueif a fingerprint was pinned and it's different now. Stop and ask the user, don't encrypt silently.
Throws DirectoryEntryInvalid if the entry isn't signed by that account's key: don't use it.
Errors
LoginRejected
Error with name === 'LoginRejected'. The sign-in can't be completed and must start again. The message is for logs (currently in Italian), not for users.
DirectoryEntryInvalid
Error with name === 'DirectoryEntryInvalid': a directory entry whose signature doesn't verify.
Constants
EMBED_PATH
'/incorporato/accedi': the path of the embeddable form on the account page.
EMBED_MESSAGE
The postMessage types between the form and your page. You don't need them unless you write your own embedding:
| Key | Value | Payload |
|---|---|---|
size | 'novren-id/embed-size' | { type, height } |
result | 'novren-id/embed-result' | { type, returnUrl } |
open | 'novren-id/embed-open' | { type, url } |