SDK reference · Flutter SDK / Flutter Getting Started

Token-based Setup

Token-based setup is the recommended way to initialize the SDK. Instead of exposing your API key on the client side, your back end uses the key to create an onboarding session and returns a session token to the client. The client then uses that token to initialize the SDK and start onboarding for that specific session. This approach improves security by keeping your API key on the server and reducing the risk of unauthorized API access.

Initialize the SDK without an API key by providing only an apiUrl to the init method, then using a session token to configure your onboarding session.

Prerequisites

  • A session token issued by your backend.
  • The apiUrl provided by Incode.

Set up the SDK with a token

Token-based setup has three steps: initialize the SDK with only an apiUrl, configure your session with a token, then start onboarding or set up a section-based flow.

1. Initialize the SDK without an API key

Provide only the apiUrl to the init method. Omit apiKey.

IncodeOnboardingSdk.init(
  apiUrl: 'https://demo-api.incodesmile.com/0/',
  onError: (String error) {
    print('Incode SDK init failed: $error');
  },
  onSuccess: () {
    // Update UI, safe to start Onboarding
    print('Incode initialize successfully!');
  },
);

2. Configure the session with a token

In your onSuccess callback, create an OnboardingSessionConfiguration and pass your session token.

OnboardingSessionConfiguration sessionConfiguration = OnboardingSessionConfiguration(
  token: 'YOUR_TOKEN',
);

3. Start onboarding or set up a section-based flow

Pass the configured OnboardingSessionConfiguration to startOnboarding, setupOnboardingSession, or any of the online-configured flow methods. Token-based setup works with all three Common Implementation Patterns.

Token expiration

Tokens are long-lived, so expiration during a session is unlikely. If a token does expire mid-session, the backend returns a 401 error, which is propagated to the SDK. Tokens cannot be refreshed; the user must start a new onboarding session, which generates a new token.

Was this page helpful?