Authentication
The Authentication module in AFCore centralizes sign-in, sign-up (create-if-not-exists), token refresh and logout flows. Its goal is to provide a single, reliable interface for the app to obtain and maintain an authenticated session so AFCore can send authentication tokens with every request to AdvantaHealth services.
Key responsibilities:
- Sign in or create a member: Attempt to sign in an existing member, or create a new member and sign them in automatically.
- Logout: Terminate the current session and revoke tokens.
After a successful sign-in or create, AFCore stores the credentials/tokens in its secure storage and attaches the access token to outgoing requests. This allows the SDK to communicate with protected AdvantaHealth services on behalf of the authenticated member.
Create / Sign In Member
Create or sign in a member using an external identity source (SAML/SSO/Custom ID). This overload accepts optional profile attributes so the backend can create/seed a member profile the first time the external ID is seen.
Parameters:
externalUserId: String — Unique external identifier for this user in your identity provider.- Optional:
email—StringfirstName—StringmiddleName—StringlastName—Stringgender—StringdateOfBirth—String(ISO-8601YYYY-MM-DD)phoneNumber—Stringaddress1—Stringaddress2—Stringcity—Stringstate—Stringzip—String
attributes—Map<String, String?>?— Additional freeform key/value attributes to seed or update the server-side profile.
Android (Kotlin)
lifecycleScope.launch {
val result = try {
AFCore.authentication().signInOrCreateMember(
externalUserId = "auth01234567890",
email = "alex@example.com",
firstName = "Alex",
lastName = "Rivera",
dateOfBirth = "1988-07-12",
attributes = mapOf("groupId" to "GR-2504")
)
if (ok.status) {
navigateToHome()
} else {
showError("Invalid credentials.")
}
} catch (t: Throwable) {
showError("Sign in failed: ${t.message}")
}
}
iOS (Swift)
do {
let result = try await AFCore.authentication().signInOrCreateMember(
externalUserId: "auth01234567890",
email: "alex@example.com",
firstName: "Alex",
lastName: "Rivera",
dateOfBirth: "1988-07-12",
attributes: ["groupId": "GR-2504"]
)
if (result.status) {
navigateToHome()
} else {
showError("Invalid credentials.")
}
} catch {
showError("Sign in failed: \(error.localizedDescription)")
}
Logout (clear storage and tokens)
Use logout() to delete SDK key–value storage and remove tokens for the current member.
Android (Kotlin)
lifecycleScope.launch {
val result = AFCore.authentication().logout()
if (ok.status) navigateToSignIn()
}
iOS (Swift)
Task {
let result = try await AFCore.shared.authentication().logout()
if (result.ok) navigateToSignIn()
}
Document updated: 2025-11-20