MainViewModel
ViewModel that bootstraps authentication on first launch.
Responsible for the one-time credential provisioning sequence:
Check/create API user — verifies the sandbox user exists; creates it if not.
Create API key — skipped if one is already stored in CredentialStorage.
Fetch access token — skipped if a non-expired token is already stored.
Fetch OAuth2 token — skipped if a non-expired token is already stored.
All credentials are written to CredentialStorage (EncryptedSharedPreferences) and then read back on every SDK request via io.rekast.sdk.network.interfaces.CredentialProvider. Expired tokens are refreshed automatically by io.rekast.sdk.app.network.TokenAuthenticator on 401 — no manual re-bootstrap is needed after first launch.
Each step uses a cold kotlinx.coroutines.flow.Flow from io.rekast.sdk.repository.DefaultRepository. Flows emit io.rekast.sdk.repository.data.NetworkResult.Loading first, then a terminal io.rekast.sdk.repository.data.NetworkResult.Success or io.rekast.sdk.repository.data.NetworkResult.Error.
isBootstrapComplete is a StateFlow that becomes true when the bootstrap chain terminates — either because all steps succeeded or because a step failed with no further retry. Observers (such as io.rekast.sdk.sample.views.home.HomeScreenFragment) should wait for the first true emission before making API calls, ensuring they never race against credential provisioning.
Constructors
Functions
Initiates a backchannel (CIBA) authorization request and stores the resulting auth_req_id and loginHint for use by getOauthAccessToken.
Checks whether the API user exists and, if not, creates it — then advances to createApiKey.