get Access Token
Returns the access token of the current session, or null when no member is signed in or the session could not be renewed.
Intended for host apps that need to call Advanta-protected endpoints outside the SDK — e.g. attaching an Authorization: Bearer header to a WKWebView / WebView request. The token is served ready to use: when the persisted token is expired (or within its refresh lead time) the SDK refreshes it first — the same refresh path its own HTTP client uses — and returns the renewed token. A null from a signed-in session means the refresh failed; a definitive rejection also emits SessionState.SESSION_EXPIRED on sessionState, so keep observing it for re-authentication routing.
Interim API. Handing out the raw bearer token is a temporary escape hatch for the apps' authenticated WebViews, not the long-term design — the SDK should vend an authenticated web session/URL instead of the token itself. This getter remains functional for now but will be deprecated and removed in a future release once that mechanism exists; callers must opt in via AFCoreExperimentalApi.
Android (Kotlin)
lifecycleScope.launch {
val token = AFCore.authentication().getAccessToken()
token?.let { webView.loadUrl(url, mapOf("Authorization" to "Bearer $it")) }
}iOS (Swift)
Task {
if let token = try await AFCore.shared.authentication().getAccessToken() {
var request = URLRequest(url: url)
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
webView.load(request)
}
}Return
The current access token, refreshed first when it was expired or about to expire; null when logged out or when the refresh failed.