Authentication
AFCore.authentication() signs members in, creates accounts on first sign-in and signs them out. After a successful sign-in the SDK stores the session securely on the device, attaches it to every request and refreshes it automatically, so your app signs a member in once and simply observes the session state afterwards.
What you can do
- Sign in with username and password issued by the member's organization. No client credentials are needed: the configured realm routes the member and the platform finds their organization.
- Sign in or create a member from your own identity provider (SSO, SAML, custom) with an external user id, optionally seeding the new member's profile. This uses your organization's
clientIdandclientSecretfrom AIDE. - Adopt a session your backend already issued by handing the SDK an access and refresh token pair, so no client secret ships in the app.
- Sign out, clearing the member's data from the device.
Key APIs
| Call | What it is for |
|---|---|
authenticateWithCredentials(username, password) | Username + password sign-in |
signInOrCreateMember(externalUserId, ...) | Sign in or create a member by external id; optional fields (name, email, date of birth, address, attributes) seed the profile on creation |
authenticateWithTokens(accessToken, refreshToken) | Adopt a token pair from your backend; call it again with a fresh pair on SESSION_EXPIRED |
logout() | End the session and clear the member's data |
Sign-in calls return an AFResult: status tells you whether the member is signed in, and statusMessage is safe to show when they are not. A network failure throws an AFException -- see Error Handling.
Example
- Android (Kotlin)
- iOS (Swift)
lifecycleScope.launch {
try {
val result = AFCore.authentication().authenticateWithCredentials(
username = username,
password = password,
)
if (result.status) navigateToHome() else showError(result.statusMessage)
} catch (e: AFException) {
showError(e.message)
}
}
Task {
do {
let result = try await AFCore.shared.authentication().authenticateWithCredentials(
username: username,
password: password
)
if result.status { navigateToHome() } else { showError(result.statusMessage) }
} catch {
showError(error.localizedDescription)
}
}
In Swift, signInOrCreateMember takes every optional profile field explicitly: pass nil for the ones you skip.
Good to know
- Sign in once: the stored session survives app restarts, and token refresh is automatic.
logout()also stops visit detection and SmartWalking auto-sync and removes this install's push registration. Callmessaging().deleteToken(...), if you use it, beforelogout().
Learn more
See the API Reference for every parameter. Complete integration guides are in AIDE Docs.