Options

Every option of the UnetId client, signIn, the API client, realtime streams and the server-side checks: type, default, units and meaning, from the source.

Times are in milliseconds unless a name says otherwise. A default of "none" means the option is off or not set.

UnetId

new UnetId(options). Throws UnetIdError with code config if clientId or redirectUri is missing, or if issuer is not an https address (http is accepted only for localhost, 127.0.0.1 and [::1]).

OptionTypeDefaultMeaning
clientIdstringrequiredThe App ID of a public app from the console.
redirectUristringrequiredThe page that calls handleRedirectCallback(). It must be registered as a return URL, character for character.
scopesstring[]["openid", "profile"]Permissions to ask for. openid is added if you leave it out. Add offline_access for a refresh token.
issuerstringhttps://api.unet.ovh/oidcThe OpenID provider. A trailing slash is removed. Use the test server's address for tests.
storage"session", "local", "memory", or a KeyValueStore"session"Where the session lives. "session": cleared when the tab closes. "local": survives restarts and is shared and synchronised between tabs, but readable by any script on your origin. "memory": lost on reload.
fetchtypeof fetchglobal fetchThe function every request goes through. For tests and special environments.
apiBasestringthe issuer without its /oidc endingThe address of the UNET API that unet.api and avatar addresses use.
onTrace(trace: Trace) => voidnoneCalled after every HTTP request the SDK makes, with secrets shortened. See Trace.
navigate(url: string) => voidlocation.assignHow the browser is sent to unet.social. Mostly for tests.
timeoutMsnumber60000A JSON request that takes longer fails with NetworkError. 0 turns it off. File uploads, media downloads and realtime streams have no timeout.
retriesnumber0How often the SDK retries an API request that got a 429 (any call: it was not processed) or a 5xx (GET calls only). Token requests are not retried.
maxRetryDelayMsnumber30000The longest wait before one retry. The wait is Retry-After for a 429 when the server sends it, otherwise it doubles each time (1 s, 2 s, 4 s, ...; for a 5xx it starts at 0.5 s).

Methods with options

CallOptionDefaultMeaning
restore(options)revalidatetruefalse: trust the cached profile and make no request on startup. The tokens still refresh on first use.
getAccessToken(force)forcefalsetrue: refresh now, even if the token is still valid.

KeyValueStore

Pass your own object as storage to keep the session somewhere else. All three methods are synchronous.

MethodMeaning
get(key: string): string or nullRead a value.
set(key: string, value: string): voidWrite a value.
remove(key: string): voidDelete a value.

MemoryStore is the in-memory implementation. The SDK's keys start with unet-id: followed by the App ID.

signIn

unet.signIn(options). Every field is optional.

OptionTypeDefaultMeaning
returnTostring"/"Where your app sends the person after the callback. The SDK keeps it while they are away and returns it from handleRedirectCallback().
prompt"none", "login", "consent", "select_account""consent" if offline_access is in scopes, otherwise noneThe OpenID Connect prompt. "consent" shows the permission screen again, for when you now ask for more. "none" shows no screen and fails if one would be needed.
loginHintstringnonePre-fills the account on the sign-in page.
extraParamsRecord<string, string>noneMore parameters for the authorization request. The protocol ones (client_id, redirect_uri, response_type, scope, state, code_challenge, code_challenge_method) cannot be overridden.

The API client

unet.api takes its settings from UnetId (timeoutMs, retries, maxRetryDelayMs). unet.api.withSignal(signal) returns an API client that also carries an AbortSignal:

OptionTypeDefaultMeaning
retriesnumber0As above.
maxRetryDelayMsnumber30000As above.
signalAbortSignalnoneAborting it cancels the call and rejects it with the abort error, not a NetworkError.

Realtime

unet.api.realtime(options). At least one of notifications, posts and feeds should be given.

OptionTypeDefaultMeaning
notificationsbooleanfalseNew notifications for the person. Needs notifications:read.
postsnumber[]nonePosts you are showing. Up to 12, each one the person may see. Needs content:read.
feedsArray<"global" or "following">noneA new post appeared in the feed. Needs content:read.
minDelayMsnumber1000The first wait before a reconnect.
maxDelayMsnumber30000The wait doubles each time up to this.

Server-side checks

verifyAccessToken

verifyAccessToken(accessToken, options): for the server of a website app. Resolves to the user (with scopes and expiresAt, in epoch milliseconds), or null.

OptionTypeDefaultMeaning
clientIdstringrequiredYour App ID.
clientSecretstringrequiredYour App Secret. Keep it on the server.
issuerstringhttps://api.unet.ovh/oidcThe provider.
fetchtypeof fetchglobal fetchFor tests or another runtime.
profilebooleantruefalse skips the profile request, so you get sub, scopes and expiresAt only.

A token longer than 2048 characters is null without a request.

verifyIdToken

verifyIdToken(idToken, options): for the server of a single-page site or app. Resolves to the claims, or null.

OptionTypeDefaultMeaning
clientIdstringrequiredThe App ID the token must have been made for.
issuerstringhttps://api.unet.ovh/oidcThe provider.
fetchtypeof fetchglobal fetchFor tests or another runtime.
clockToleranceSecondsnumber60How much clock difference is accepted on exp, iat and nbf, in seconds.
now() => numberDate.nowThe clock, in milliseconds. For tests.

A token longer than 8192 characters is null without a request. The signing keys are cached for 10 minutes. An unknown key id triggers at most one new fetch every 30 seconds. clearIdTokenKeyCache() empties the cache.

Trace

The object onTrace receives for each request.

FieldTypeMeaning
idnumberA counter, from 1.
atnumberWhen the request started, in epoch milliseconds.
msnumberHow long it took.
sdkstringWhich SDK call caused it, such as api.feed() or token (refresh_token).
method, urlstringThe request.
requestHeaders, requestBodyThe request, with the token shortened. Files are described, never included.
status, oknumber, booleanThe answer. status is 0 if there was none.
responseHeaders, responseBodyThe answer. Media files are not read.
errorstringSet when the request failed without an answer.

Tokens, codes, verifiers and secrets are shortened to their first characters and their length.