Authentication and two-step verification
Machine clients skip this page: they sign in with their client credentials (Getting started → Services and integrations).
Use sdk.auth to sign in and complete authentication challenges. Start with a configured sdk from Getting started. Kotlin examples run in a coroutine; TypeScript examples run in an async function.
People sign in with one field, an email address or a phone number. determineLoginType() sorts the value: anything with @ is an email; a phone number is in E.164 form (+4712345678, +358401234567, +12025550123) or 8 to 12 digits without a country code. Then they sign in with a code (the default), a password or a passkey. Two-step verification is an authenticator app (TOTP) or passkeys; email and SMS are sign-in methods only, never a second factor.
Authentication flows
Password login
Password login uses SRP by default. fcmDevice tells Solibo Home which kind of client is signing in, so it knows where push notifications may go: ANDROID or IOS in mobile apps, WEB for browsers, servers and command-line tools.
import no.solibo.oss.sdk.api.gen.models.FcmDeviceType
import no.solibo.oss.sdk.auth.Credentials
val result = sdk.auth.initiateAuth(
fcmDevice = FcmDeviceType.ANDROID, // Use IOS on iOS
creds = Credentials(login = "user@example.com", pwd = "your-password")
)
import { Credentials, FcmDeviceType } from '@solibo/solibo-sdk';
const result = await sdk.auth.initiateAuth(
FcmDeviceType.WEB,
new Credentials('user@example.com', 'your-password'),
);
initiateAuth returns null for every failure. signInWithPassword says why instead: its SignInResult is signed in (signedIn), challenged (challenge, see below), an MCP redirect (redirectUrl), or a failure. signInWithCode, signInWithPasskey and answerTwoStepChallenge answer the same way.
SignInFailure | Meaning |
|---|---|
CREDENTIAL_REJECTED | Wrong login, password or code, or an expired code. |
PASSWORD_OR_PASSKEY_REQUIRED | The email or SMS code was right, but this person’s authenticator app was set up outside Solibo: offer the password or a passkey. Not a wrong code. |
RATE_LIMITED | Too many attempts; ask the person to wait. |
DEVICE_REJECTED | The password was accepted but the app’s remembered device was not; sign in again. |
NO_PASSKEY, PASSKEY_CANCELLED, PASSKEYS_UNSUPPORTED | Passkey sign-in only; see below. |
CLIENT_RETIRED | The sign-in named an MCP app client Solibo Home retired; it takes no new sign-ins. Forget it and start the MCP authorization again, which hands out the current client. |
UNSUPPORTED_CHALLENGE | The server asked for a step this SDK build does not know; nobody was signed in. Ask the person to update the app. |
FAILED | Anything else; error holds what the SDK caught. |
reason holds the server’s FailureReason when it sent one this build knows; a newer one is null there, and SoliboSDKError.rawReason (on error) still carries it. Only cancellation throws.
val result = sdk.auth.signInWithPassword(FcmDeviceType.ANDROID, Credentials(login, password))
when {
result.signedIn -> showHome()
result.challenge == AuthChallengeType.TOTF_MFA -> askForAuthenticatorCode()
result.failure == SignInFailure.RATE_LIMITED -> showTryLater()
else -> showWrongPassword()
}
import { Credentials, FcmDeviceType, SignInFailure } from '@solibo/solibo-sdk/core';
const result = await sdk.auth.signInWithPassword(
FcmDeviceType.WEB,
new Credentials(login, password),
);
if (result.failure === SignInFailure.RATE_LIMITED) showTryLater();
MCP sign-ins
When the sign-in page serves an MCP client (Claude, ChatGPT), pass the state and redirect_uri it was opened with as an McpAuthorization to initiateAuth, loginByCode, signInWithPassword, signInWithPasskey and answerMfaChallenge. The last step then ends in a redirect to the MCP client with an authorization code instead of a session: SignInResult.redirectUrl, or a thrown RedirectException from the calls that return SoliboAuthentication.
Email or SMS code
Request a code, then submit it after the user receives it. loginByCode returns the SoliboAuthentication and throws for a refused code; signInWithCode(login, code, fcmDevice, mcp) returns a SignInResult instead, so a wrong code (CREDENTIAL_REJECTED) is told from a person who must use a password or passkey (PASSWORD_OR_PASSKEY_REQUIRED).
sdk.auth.initiateAuth(
fcmDevice = FcmDeviceType.ANDROID,
creds = Credentials(login = "user@example.com"),
usePassword = false
)
// After the user enters the code:
val result = sdk.auth.loginByCode(
login = "user@example.com",
code = "123456",
fcmDevice = FcmDeviceType.ANDROID
)
import { Credentials, FcmDeviceType } from '@solibo/solibo-sdk';
await sdk.auth.initiateAuth(
FcmDeviceType.WEB,
new Credentials('user@example.com'),
false /* usePassword: send a one-time code instead */,
);
// After the user enters the code:
const result = await sdk.auth.loginByCode(
'user@example.com',
'123456',
FcmDeviceType.WEB,
);
For someone with the authenticator app, a right code ends in a TOTF_MFA challenge. The SDK keeps it and its session, so answer with the code alone (answerMfaChallenge or answerTwoStepChallenge, below).
loginByCode throws SoliboSDKError with the server’s reason for a refused code (CREDENTIAL_REJECTED, PASSWORD_OR_PASSKEY_REQUIRED), RateLimitException for a rate limit and RedirectException for a finished MCP sign-in. The SDK never retries a sign-in the attempt limit refused: RateLimitException arrives at once, and retryAfterSeconds (or SignInResult.retryAfterSeconds) says how long to wait before the next try, when the server said.
Apps (token mode) keep the code’s session in the SDK’s settings. A browser (cookie mode) keeps none in storage: the server holds it in an HttpOnly cookie, so a code typed in another tab or after a reload works, and a challenge’s session that follows is kept in memory only, never in localStorage.
OAuth
Pass the authorization code and state from your configured provider’s callback.
val result = sdk.auth.loginByOAuth(code, state, FcmDeviceType.ANDROID)
import { FcmDeviceType } from '@solibo/solibo-sdk';
const result = await sdk.auth.loginByOAuth(code, state, FcmDeviceType.WEB);
Handling authentication results
Check the returned SoliboAuthentication: tokens indicates a completed login; challenge requires another step. A missing result is not a successful login. Handle thrown errors in your login UI too.
| Challenge type | Next step |
|---|---|
NEW_PASSWORD | Ask for a new password, confirm it, then log in again. |
TOTF_MFA | Ask for the code from the authenticator app and call answerMfaChallenge. |
| Anything else | Should not happen: show an error and report it. |
A challenge type newer than the SDK build reads as null instead of failing the response. It is never a sign-in: the calls returning SoliboAuthentication throw UnsupportedChallengeException, and a SignInResult has the failure UNSUPPORTED_CHALLENGE with that exception as its error. Its challengeName is the type exactly as the server sent it, for the app to report. Ask the person to update the app.
TOTF_MFA is the contract’s name for the authenticator-app (TOTP) step. SMS and email are never a second factor, so answerMfaChallenge answers TOTF_MFA only.
Call sdk.auth.clearSession() when the user cancels a challenge.
Two sign-in failures are not wrong credentials, and only apps (token mode) see them. DeviceRegistrationException means the device Cognito issued could not be registered. DeviceRejectedException means the server could not verify the device the sign-in was challenged for, after the code was accepted. The code is spent, so start the sign-in again: the SDK has forgotten that device, and the next email or SMS sign-in finishes without a device challenge.
Remembered devices and browsers
After the first authenticator-code sign-in on a device, Cognito remembers it and asks that device for a device challenge instead of the code.
- Apps (token mode) keep the device key, group and secret in the SDK’s settings and answer the challenge themselves. Password (SRP and direct), email or SMS code and passkey sign-ins name the device the app holds (
deviceKey) when that device last signed in with the same login, also when nobody is signed in any more, as after a refused refresh. Cognito then answers with the device challenge instead of the authenticator step and mints no new device. Another login on the same app never names it, andlogout()forgets it. - A stale device never fails a password sign-in. When the server refuses the device (
DEVICE_REJECTED), or the app no longer holds all of it, the SDK forgets it and signs in again with the password, without a device. After an email or SMS code the code is spent by then, so that sign-in ends inDeviceRejectedException(SignInFailure.DEVICE_REJECTED); the next one goes without the device. - Browsers (cookie mode) store no device key: the browser’s auth cookies name its device. A backend with server-side device SRP keeps the device’s secret, answers its challenges and names no device to the browser, so the SDK never sees a
DEVICE_SRPchallenge and registers nothing. An older backend hands the browser the challenge, naming the device from its cookie, and the SDK answers it with the secret incognitoDevicePass(the one the legacy web login or an earlier registration left inlocalStorage), and registers a device that backend issues with that secret, as 1.51 did. The SDK keepscognitoDevicePassreadable for as long as a backend may send a browser a device challenge. A challenge without a secret to answer it with ends inDeviceRejectedException, and the next sign-in tells the server the browser holds none.
Required new password (NEW_PASSWORD)
Use the same login that started the challenge. Confirmation returns a Boolean, so start a fresh login after success. The form supplies login and newPassword below.
if (sdk.auth.confirmNewPassword(login, newPassword)) {
val result = sdk.auth.initiateAuth(
FcmDeviceType.ANDROID,
Credentials(login, newPassword)
)
// Check result for tokens or another challenge.
}
import { Credentials, FcmDeviceType } from '@solibo/solibo-sdk';
if (await sdk.auth.confirmNewPassword(login, newPassword)) {
const result = await sdk.auth.initiateAuth(
FcmDeviceType.WEB,
new Credentials(login, newPassword),
);
// Check result for tokens or another challenge.
}
If confirmation fails, start a fresh login before retrying.
Forgotten password
forgotPassword sends a reset code by email or SMS, depending on the login. Pass that code to confirmNewPassword, then log in again with the new password.
if (sdk.auth.forgotPassword(login)) {
// After the user enters the code:
sdk.auth.confirmNewPassword(login, newPassword, code)
}
if (await sdk.auth.forgotPassword(login)) {
// After the user enters the code:
await sdk.auth.confirmNewPassword(login, newPassword, code);
}
Passkeys
A passkey signs a person in on its own; for someone with two-step verification it counts as both factors. The platform prompt runs through a WebAuthnClient:
| Platform | Client |
|---|---|
| Browser | BrowserWebAuthnClient (WebAuthn JSON helpers where the browser has them, its own base64url conversion where not) |
| Android | AndroidWebAuthnClient { currentActivity } over Credential Manager, API 28 and newer; older versions report UNSUPPORTED |
| iOS | The app’s own, over ASAuthorizationController; from Swift implement WebAuthnCallbacks and pass CallbackWebAuthnClient(callbacks) |
| Your own JavaScript prompt | new PromiseWebAuthnClient({ prompt }), where prompt.get/prompt.create return Promises |
The page or app must belong to the relying party: home.solibo.no in production, rearden.dev.solibo.io on dev. localhost cannot use passkeys.
Signing in with a passkey
val result = sdk.auth.signInWithPasskey(
login = "user@example.com",
fcmDevice = FcmDeviceType.ANDROID,
webAuthn = AndroidWebAuthnClient { currentActivity },
)
when (result.failure) {
null -> if (result.signedIn) showHome()
SignInFailure.NO_PASSKEY -> offerCodeOrPassword()
SignInFailure.PASSKEY_CANCELLED -> Unit
else -> showError()
}
import { BrowserWebAuthnClient, FcmDeviceType, SignInFailure } from '@solibo/solibo-sdk/core';
const result = await sdk.auth.signInWithPasskey(
login,
FcmDeviceType.WEB,
new BrowserWebAuthnClient(),
);
if (result.failure === SignInFailure.NO_PASSKEY) offerCodeOrPassword();
NO_PASSKEY is also the answer for an unknown login, so it reveals nothing about who has an account.
Managing passkeys
registerPasskey(webAuthn) adds a passkey for the signed-in person and returns REGISTERED, CANCELLED (the prompt was dismissed), UNSUPPORTED (this device cannot), UNAVAILABLE (Solibo Home has passkeys switched off; hide the option), REJECTED (the server did not accept the new passkey) or RECENT_SIGN_IN_REQUIRED (sign the person in again, then retry; asked before any prompt). listPasskeys() lists them and deletePasskey(credentialId) removes one; the last passkey of someone in the passkeys-only mode cannot be removed (SoliboSDKError with reason PASSKEY_REQUIRED), and removing one can ask for a recent sign-in too (RECENT_SIGN_IN_REQUIRED).
Two-step verification
security() returns the signed-in person’s SecuritySummary: twoStepMode (OFF, AUTHENTICATOR_APP, PASSKEYS_ONLY), whether it is required for them, whether their authenticator app is set up (authenticatorAppConfigured), whether passkeysOnlyAvailable, passkeyCount, and whether they sign in through SSO (federated). Read it after every sign-in; when required and the mode is OFF, show the set-up screen first.
AUTHENTICATOR_APPwithauthenticatorAppConfiguredfalse means the authenticator has to be set up again: the server has none it can check. Offer the set-up below.twoStepModeisnullfor a mode newer than the SDK build (an unknown value no longer fails the whole summary). Treat it as on, never asOFF, and ask the person to update the app.
Answering the authenticator challenge
val result = sdk.auth.answerMfaChallenge(code = "123456")
const result = await sdk.auth.answerMfaChallenge('123456');
The SDK remembers the challenge and its session, after a password, a code or a passkey; when the server asks again under a new session, it keeps that one. A wrong or expired code throws SoliboSDKError with reason CREDENTIAL_REJECTED and keeps the session, so the person can try again; PASSWORD_OR_PASSKEY_REQUIRED after a code sign-in means this person must use a password or passkey; a rate limit throws RateLimitException. answerTwoStepChallenge(code) returns the same as a SignInResult.
Turning on the authenticator app
Show the association secret as a QR code (otpauth://totp/Solibo%20Home:<login>?secret=…&issuer=Solibo%20Home) and as text, verify a code from the person’s app, then switch the mode. A signed-in person needs no session for the verification. Setting up an authenticator needs a recent sign-in: createTOTPMfa and verifyCreateTOTPMfa throw SoliboSDKError with reason RECENT_SIGN_IN_REQUIRED otherwise, before anything changes, so sign the person in again and start over.
val association = sdk.auth.createTOTPMfa()
// Show association.secret in your set-up UI.
// After the person enters a code:
if (sdk.auth.verifyCreateTOTPMfa(code = "123456", deviceName = "My phone").verified) {
sdk.auth.setTwoStepMode(TwoStepMode.AUTHENTICATOR_APP)
}
import { TwoStepMode } from '@solibo/solibo-sdk/core';
const association = await sdk.auth.createTOTPMfa();
// Show association.secret in your set-up UI.
// After the person enters a code:
const { verified } = await sdk.auth.verifyCreateTOTPMfa('123456', 'My phone');
if (verified) await sdk.auth.setTwoStepMode(TwoStepMode.AUTHENTICATOR_APP);
setTwoStepMode needs a sign-in within the last ten minutes (RECENT_SIGN_IN_REQUIRED); it refuses AUTHENTICATOR_APP before the authenticator is set up (TOTP_NOT_SET_UP) and PASSKEYS_ONLY where that mode is not offered (PASSKEYS_ONLY_UNAVAILABLE). Every change signs the person out everywhere. A browser loses its auth cookies with the answer, so in cookie mode the SDK forgets the signed-in person as well: send them to sign in again. setTwoStepMode(TwoStepMode.OFF) turns two-step verification off.
Remembered devices and sessions
rememberedDevices() lists the devices that skip the authenticator step (deviceKey, name, lastAuthenticatedAt, and current for this one); forgetRememberedDevice(deviceKey) makes a device ask again. revokeAllSessions() signs the person out everywhere: every refresh token stops working, MCP grants included, while access tokens already issued last until they expire.
Deprecated calls
verifySMSMfa, verifyEmailMfa, verifyEmailOtp, createMfaSelection, createMfaSelectionConfirmation, createMfaPreference and removeMfa are deprecated and go away in the next major version. Use answerMfaChallenge and setTwoStepMode.
Sign out
logout() revokes the session on the server and clears the stored session.
- Token mode revokes the refresh token and this device. It returns
falsewhen no one is signed in, or when the server could not revoke the token; the stored tokens are then kept. - Cookie mode revokes the refresh cookie at the origin’s
/auth/implicit/refresh/revoke, where the browser sends it, and under/apiwhen that fails; the server also expires the auth cookies. The SDK forgets the session either way and returns whether the server accepted the revoke.
val signedOut = sdk.auth.logout()
const signedOut = await sdk.auth.logout();
Cookie sessions from another solibo.no host
A cookie session relies on the HttpOnly SOLIBO_HOME_* cookies that Solibo Home sets for home.solibo.no under /api; your code never sees them. Configure the client as in Pages Solibo hosts on solibo.no (the raw builder’s switch is setCredentials('include')). Sign-in itself happens on home.solibo.no: send people to https://home.solibo.no/auth/login?next=<page URL> and they return signed in. The login page returns only to pages on developers, swagger and async.solibo.no.
Browser threat protection
Cognito scores sign-ins with data from Amazon’s advanced-security script. Pass a CognitoAdvancedSecurityFingerprinter(userPoolId, clientId, region) as the client’s fingerprinter: it loads the script for the pool’s region and hands its data to every sign-in, refresh and password request. region defaults to the pool id’s <region>_ prefix, or eu-west-1 for an id without one. Allow the script’s origin (https://amazon-cognito-assets.<region>.amazoncognito.com) in the page’s script-src.
Creating the fingerprinter loads nothing, so pages that never sign anyone in never run Amazon’s script. It loads on first use: load(), or the first request that asks for its data (a sign-in, a password request or a refresh), which goes without the data while it loads. Await load() on the sign-in page, before the first sign-in, to send the data with it; a blocked script never keeps anyone from signing in.
Secure storage on mobile
The SDK keeps tokens and the device secret in plain multiplatform-settings by default. An app opts into secure storage by passing other settings and moving the old values once:
// Android: values AES-GCM encrypted with a key that never leaves the Android Keystore.
val secure = AndroidSecureSettings.create(context)
// iOS: the Keychain.
// val secure = IosSecureSettings.create()
SettingsMigration.migrate(from = plainSettings, to = secure)
// Build the SDK with settings = secure.
SettingsMigration moves only the SDK’s own keys and does it once. It never throws and can be resumed: a key is removed from the plain settings only after the secure ones stored it, the MIGRATED_MARKER is written last, and a key the secure store refuses for now stays in plain settings for the next call. SettingsMigration.isMigrated(secure) says whether the move is done; remove leftover plain SDK keys only then. A key both settings hold keeps the secure value: it was moved by an earlier call or written by the SDK since, so it is the newer one. To restore a plain value on purpose, write it to the secure settings yourself.
Both secure settings are BufferedSettings: a write the store refuses (an Android Keystore that fails to encrypt, the iOS Keychain before the first unlock after a restart) never throws. The value is held in memory, reads see it, and it is stored at the next access or retryPendingWrites(), so a rotated refresh token is not lost while the app runs. isStored(key) says whether a value reached the store.
- Android: exclude the preferences file from backups: a restored copy cannot be decrypted and reads as signed out.
- iOS: items are
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly, so a background refresh on a locked device works and no backup moves them to another device. Items stored under the Keychain’s default accessibility by an earlier build are rewritten under it once, when the settings are created, or when protected data becomes available if the device was locked then. Before the first unlock after a restart the Keychain has nothing to give, and a read orhasKeythrowsSecureStorageUnavailableExceptionrather than reading as signed out.- Create the SDK once
IosSecureSettings.isReadable()is true: from the first unlock on, locked or not, when every item has the after-first-unlock accessibility, and otherwise while the device is unlocked. Do not wait forUIApplication.protectedDataAvailable: it is false whenever the device is locked, which would stop the background refresh these settings allow. IosSecureSettings.create(service)returns the same settings for a service on every call, and one observer for the whole app retries held writes when protected data becomes available.
- Create the SDK once
React integration (solibo-react)
Inside a SoliboProvider, access sdk.auth through useSoliboApi(). Hooks from @solibo/solibo-react (options from @solibo/solibo-query):
useSignInWithPassword(),useSignInWithPasskey()anduseSignInWithCode()resolve to aSignInResult. All takemcp: { state, redirectUri }; the passkey hook uses the browser’s prompt unless given awebAuthnwith Promise-returninggetandcreate.useAnswerTwoStepChallenge()submits the authenticator code and resolves to aSignInResult;useAnswerMfaChallenge()does the same and resolves to theSoliboAuthentication(both takemcpfor MCP sign-ins).useSecurity(),useSetTwoStepMode(),useCreateTOTPMfa()anduseVerifyCreateTOTPMfa()manage two-step verification.usePasskeys(),useRegisterPasskey()anduseDeletePasskey()manage passkeys.useRememberedDevices(),useForgetRememberedDevice()anduseRevokeAllSessions()manage devices and sessions.useCreateMfaPreference(),useRemoveMfa()and the selection hooks are deprecated.
See Getting started for provider setup.