AuthProvider typedef

AuthProvider = Future<Auth> Function()

Async authentication provider callback.

Called before each (re-)connection attempt to obtain fresh credentials. Ideal for implementing refresh-token flows.

The returned Auth is usually Auth.jwt or Auth.none. Returning Auth.basic is also supported: the client will exchange the Basic credentials for a JWT before the first query or WebSocket connect.

Future<KalamClient> create() async {
  return KalamClient.connect(
    url: 'https://db.example.com',
    authProvider: () async {
      final token = await myApp.getOrRefreshJwt();
      return Auth.jwt(token);
    },
  );
}

Implementation

typedef AuthProvider = Future<Auth> Function();