Offline Login
Offline login allows an already activated user to authenticate by validating stored offline tokens. If the token is valid, the MC (Master Controller) returns a status OK
. If the offline token is invalid or the login fails, it is recommended to initiate an IDP login with the same authentication method used previously.
Example Flow:
- If biometric login is enabled:
Offline login fails → Trigger an IDP login → Perform login using biometric authentication mode.
For repeated login failures (e.g., unrecognized fingerprints), prompt the user for an alternative authentication method.
Shift Lite - Offline Login Flow
The following event flow diagram illustrates the sequence of events during the Offline Login process for KOBIL Shift Lite:
Implementation Examples
Swift/iOS
The Offline Login function validates the token stored on the device. It sends the necessary request (tenantId and clientId) to validate the user session on the IDP.
Here's an example for triggering the Offline Login flow in Swift/iOS:
public func performOfflineLogin(
userIdentifier: KsUserIdentifier,
completion: @escaping ((KSMOfflineLoginResultEvent) -> Void?)
) {
let offlineLoginEvent = KSMOfflineLoginEvent(
userIdentifier: userIdentifier,
authenticationMode: KSMAuthenticationMode.no
)
self.masterControllerAdapter.sendEvent2MasterController(offlineLoginEvent) { event in
guard let macroEvent = event as? KsMacroEvent else { return }
guard let resultEvent = macroEvent as? KSMOfflineLoginResultEvent else { return }
completion(resultEvent)
}
}
Android/Kotlin
The Offline Login flow in Kotlin follows a similar structure, validating the offline token and prompting for re-authentication if necessary.
Here's an example for triggering the Offline Login flow in Kotlin:
fun triggerOfflineLoginEvent(userIdentifier: UserIdentifier) {
val offlineLoginEvent = OfflineLoginEvent(userIdentifier)
mcEventHandler?.postEvent(offlineLoginEvent)?.then {
logDebug("Received OfflineLoginResultEvent: $it", "triggerOfflineLoginEvent")
// Handle result
}
}
Flutter/Dart
For Flutter, the offline login can be implemented using the McWrapperApi:
Future<void> performOfflineLogin(String username) async {
try {
// user identifier for the offline login
final userIdentifier = UserIdentifierT()
..userId = username
..tenantId = Environment.current.appConfig.tenantId;
final offlineLoginEvent = OfflineLoginEventT(
userIdentifier: userIdentifier
);
// Get McWrapperApi from service locator
final mcApi = locator<McWrapperApi>();
// Send offline login event
final response = await mcApi.send(offlineLoginEvent);
response.fold(
(error) {
print("❌ Offline login error: $error");
// Fallback to regular IDP login...
},
(result) {
if (result is OfflineLoginResultEventT) {
if (result.status == StatusType.ok) {
print("✅ Offline login successful");
// User is logged in, proceed to main app...
} else {
print("⚠️ Offline login failed, status: ${result.status}");
// Perform regular IDP login with same auth mode as before...
}
}
},
);
} catch (e) {
print("❌ Offline login exception: $e");
// Handle exception and fallback to regular IDP login...
}
}
// Usage example
void handleAppResume() {
performOfflineLogin("user@example.com");
}
Request Parameters
The Offline Login flow requires a UserIdentifier consisting of these two parameters:
userId: The unique user identifier for the user attempting to log in.
tenantId: The tenant associated with the user.
Notes on Authentication Modes
In Shift Lite, you can configure various authentication modes. For more details, refer to the section on authentication modes.
Summary
With these steps, users can use their valid tokens to remain authenticated with the IDP. If offline tokens are invalid, the fallback IDP login ensures continuous access. The provided code examples for both iOS/Swift and Android/Kotlin offer straightforward integration paths for mobile apps to leverage Shift Lite Connect offline login capabilities.