Russian guide: doc/README.ru.md
Flutter plugin for Sber ID on iOS and Android. It wraps the native SDKs:
Support the project: SberBank Online collection
- Android: SIDSDK_CORE and, when needed, ELK
- iOS: SIDSDK via Swift Package Manager or CocoaPods
- SDK setup:
clientId,redirectUri, scopes, stand - PKCE login: Dart receives
authCode,state,nonce, andcodeVerifier - Login modes:
standard,web(OIDC / Custom Tab),webView,autoAuth,seamless - Seamless sign-in from the SberBank app (
extractSsoBaseUrl,loginSeamless, cold-start deeplink on Android) - Native Sber ID button (
SBerIdButton, platform view) - Native personal cabinet (
SBerIdElkContainer, platform view) - Check whether the SberBank app is installed
- Logout
| Platform | Minimum | Native SDK |
|---|---|---|
| iOS | 15.0+ | SIDSDK ~> 4.0.2 |
| Android | API 26+ | SIDSDK_CORE 1.8.0, SIDSDK_ELK 1.8.0 |
dependencies:
sber_id_sdk: ^0.2.3From GitHub, when you need a specific revision. Put a commit in ref.
dependencies:
sber_id_sdk:
git:
url: https://github.com/Mihalcov/sber_id.git
ref: <commit>The plugin builds with Swift Package Manager (preferred on Flutter 3.24+) and with CocoaPods.
flutter config --enable-swift-package-managerSPM manifest: ios/sber_id_sdk/Package.swift. SIDSDK and FlutterFramework are linked at build time.
-
Deployment target 15.0+ (
ios/Podfileor Xcode). - The URL scheme in
Info.plistmust matchredirectUri:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>yourapp</string>
</array>
</dict>
</array>-
LSApplicationQueriesSchemes and NSAppTransportSecurity for
id.sber.ru. See the project setup guide. -
AppToken / ELK (optional):
AppIdentifierPrefixand the Keychain groupru.sid.iphone.shared. See the iOS ELK guide. - If the app uses UIScene (the example does), add a SceneDelegate.
application(_:open:options:)is not called, the plugin never sees the redirect, andlogin()finishes withAUTH_CANCELLED. Pass the URL to the plugin, then callsuper, so another SDK can handle its own link:
import sber_id_sdk
override func scene(
_ scene: UIScene,
openURLContexts URLContexts: Set<UIOpenURLContext>
) {
for context in URLContexts {
if SberIdPlugin.handleURL(context.url) { return }
}
super.scene(scene, openURLContexts: URLContexts)
}Before production, register clientId and redirectUri with Sber ID: support_sberid@sber.ru.
-
minSdk 26 in
android/app/build.gradle. -
MainActivityextendsFlutterFragmentActivity, notFlutterActivity. The standard login callsSIDLogin.loginWithID, which needs aFragmentActivity. WithFlutterActivitythe plugin returnsNO_ACTIVITY/AUTH_ERRORand the Sber sheet does not open. -
Package visibility (
<queries>). On Android 11+ the Sber app is invisible until you declare it. ThenisSBerIdInstalled()isfalseand native login does not open the bank app:
<queries>
<package android:name="ru.sberbankmobile" />
<package android:name="ru.sberbank_sbbol" />
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sberbankidexternallogin" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="sbolidexternallogin" />
</intent>
</queries>-
Deeplink on
MainActivity(quick start, section 5.1).android:launchMode="singleTop". Scheme and host must matchSBerIdConfig.redirectUri(the example usessberidexample://auth):
<activity
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
...>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="yourapp"
android:host="auth" />
</intent-filter>
</activity>-
ELK (optional): pass
partnerProfileUrlinSBerIdConfig. Android callsSIDELK.setProfileUrl. iOS callsapplyMainPreferences(partnerProfileUrl:). - If you override
onNewIntent, callsetIntent(intent)beforesuper.onNewIntent(intent). Otherwise the redirect stays on the old intent,login()returnsAUTH_CANCELLED, and the code is only available fromtakePendingAuthResult().
ELK does not replace the login screen: the user signs in with Sber ID first. For AppToken and the jump to the partner site, add the mapp_sso scope and follow the docs:
- Android: ELK Android SDK
- iOS: ELK guide (Keychain group
ru.sid.iphone.shared,AppIdentifierPrefixin Info.plist)
await SBerId.instance.initialize(
SBerIdConfig(
clientId: '...',
redirectUri: 'yourapp://auth',
partnerName: 'Your app',
partnerProfileUrl: 'https://your-profile-url-from-sber',
userId: 'optional at init',
scopes: ['openid', 'name', 'email', 'mapp_sso'],
),
);
// After login: OIDC sub or the partner user id for ELK widgets
await SBerId.instance.setUserId(userSub);
SBerIdElkContainer(
containerName: 'offer', // Android: ELKContainerView; iOS: additionalPath
containerVersion: 3,
height: 400,
onEvent: (e) => debugPrint('ELK: ${e.type} ${e.widgetName}'),
);| Parameter | Android | iOS |
|---|---|---|
partnerProfileUrl |
SIDELK.setProfileUrl during init |
applyMainPreferences |
userId |
SID.Settings.setMainSettings(userID) |
applyMainPreferences(userID:) |
partnerName |
SID 1.8 has no settings field for it; the Dart parameter is still required | applyMainPreferences(partnerName:) |
setUserId() |
updates the user id after login | same |
Example screen: ELK demo (example/lib/elk_screen.dart).
import 'package:sber_id_sdk/sber_id_sdk.dart';
await SBerId.instance.initialize(
SBerIdConfig(
clientId: 'your-client-id',
redirectUri: 'yourapp://auth',
partnerName: 'Your app',
partnerProfileUrl: 'https://your-profile-url', // optional, for ELK
),
);
// Standard login: Sber app, otherwise web
final response = await SBerId.instance.login(
options: SBerIdLoginOptions(mode: SBerIdLoginMode.standard),
);
// Web / OIDC
await SBerId.instance.login(
options: SBerIdLoginOptions(
mode: SBerIdLoginMode.web,
customTabRedirectUri: 'yourapp://auth',
),
);
// Native button: your own onPressed, or automatic login
SBerIdButton(
clientId: 'your-client-id',
onPressed: () async {
final r = await SBerId.instance.login();
// handle r
},
);
// Without onPressed, a tap calls login(mode: SBerIdLoginMode.standard)
if (response?.isSuccess == true) {
await yourBackend.exchange(
authCode: response!.authCode!,
codeVerifier: response.codeVerifier!,
state: response.state,
nonce: response.nonce,
redirectUri: 'yourapp://auth',
);
}OAuth step 2 (exchange the code for tokens on your server): see doc/OAUTH_BACKEND.md. It covers PKCE, state / nonce, and typical invalid_grant errors.
Dart SBerIdLoginMode
|
Android | iOS |
|---|---|---|
standard |
SIDLogin.loginWithID |
SID.login.auth |
web |
loginWithIDToCustomTab |
webAuth |
webView |
loginWithIDToWebView |
loginWithIDToWebView |
autoAuth |
autoAuth |
autoAuth |
seamless |
getSeamlessUriScheme + autoAuth
|
SIDUtils.getSSOUrlStringFrom + autoAuth
|
If the user opened your app from SberBank by a deeplink with sberIDRedirect, use seamless login:
// Base SSO URL from the deeplink (optional: loginSeamless does this itself)
final sso = await SBerId.instance.extractSsoBaseUrl(deeplink);
final response = await SBerId.instance.loginSeamless(
seamlessDeeplink: deeplink,
);
// Android cold start: deeplink from the launch intent
final launchDeeplink = await SBerId.instance.getLaunchSeamlessDeeplink();
if (launchDeeplink != null) {
await SBerId.instance.loginSeamless(seamlessDeeplink: launchDeeplink);
}On iOS the return URL must reach SberIdPlugin.handleURL (see SceneDelegate above). getLaunchSeamlessDeeplink exists only on Android. On iOS it returns null.
The native SDK often finishes login with AUTH_CANCELLED before the redirect arrives, or Android recreates the activity and login() does not resume. The code is still stored natively. Do not send a code to the backend without codeVerifier. Read the stored result after login(), and again when the app becomes active:
final pending = await SBerId.instance.takePendingAuthResult();
if (pending != null &&
pending.isSuccess &&
pending.hasAuthCode &&
(pending.codeVerifier?.isNotEmpty ?? false)) {
// exchange pending.authCode + pending.codeVerifier
}takePendingAuthResult() returns the result once. On iOS it does nothing (null) until a result has been stored. The example in this repo polls Android for a few seconds after a cancel.
cd example
flutter runlogin() always completes with a [SBerIdAuthResponse] and does not throw when sign-in fails. Check isSuccess, errorCode, and isCancelled.
errorCode |
Meaning |
|---|---|
AUTH_CANCELLED |
The user closed web or Safari, or the flow ended without a redirect |
LOGIN_SUPERSEDED |
A new login() replaced one that had not finished |
INVALID_REDIRECT |
Scheme or host of the incoming URL does not match redirectUri
|
NOT_INITIALIZED |
initialize() was not called |
NO_ACTIVITY / NO_VIEW_CONTROLLER
|
No foreground Activity or view controller |
AUTH_ERROR |
The SDK or the server rejected the login |
initialize(), setUserId(), and logout() throw [SBerIdException] on a platform error.
final r = await SBerId.instance.login();
if (r?.isCancelled == true) {
// the user closed the login
} else if (r?.isSuccess != true) {
debugPrint('${r?.errorCode}: ${r?.error}');
}SberBank Online collection for this plugin:
https://messenger.sbrf.ru/sl/XMNhVd5RNSjvfnHRu
- Plugin issues: GitHub
- Sber ID SDK: support_sberid@sber.ru
Plugin code: MIT (LICENSE).
The Sber ID native SDKs (SIDSDK, SIDSDK_CORE, SIDSDK_ELK) are third-party libraries with their own licenses: sid-sdk and Maven Central. Check them before you ship an app that depends on this plugin.