tinkoff_id_flutter 1.0.0 tinkoff_id_flutter: ^1.0.0 copied to clipboard
Tinkoff ID Native Android And iOS Flutter Realization
tinkoff_id_flutter #
Tinkoff ID Native Android And iOS SDK Flutter Realization
Features #
The plugin allows you:
- to receive a set of social tokens from the Tinkoff ID system of Tinkoff Bank.
- update token via refreshToken
- logout from Tinkoff ID
Getting started #
Android requirements:
- minSdkVersion >= 21
Usage #
Add to Info.plist in your app so your app can open Tinkoff Bank App:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>tinkoffiddebug</string>
<string>tinkoffbank</string>
</array>
Add to Info.plist in your app so Tinkoff Bank App can open your app with incoming link:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>tru</string> /// scheme
<string>redirecturi</string> ///host
<string>everylounge</string>
</array>
</dict>
</array>
Use all methods of in your app:
class SignInWithTinkoffIdUseCase {
final TinkoffIdFlutter _tinkoffId;
SignInWithTinkoffIdUseCase(this._tinkoffId);
Future<Result<List<String>>> getTokenFromTinkoffId() async {
const redirectUri = "rdu://rduhost";
const clientId = "tid_client_id";
///Init client
await _tinkoffId.init(clientId, redirectUri, false);
///Check whether app installed or not
final bool isAvailable = await _tinkoffId.isTinkoffAuthAvailable();
if (!isAvailable) {
return Result.failure("Tinkoff Bank application not found or not installed.");
}
///Start listen first link
final appLinkFuture = AppLinks().stringLinkStream.first;
///Launch Tinkoff Bank App
await _tinkoffId.startTinkoffAuth(redirectUri);
///Wait for first incoming link
late final String url;
try {
url = await appLinkFuture.timeout(seconds(120));
} catch (e) {
return Result.failure("120 seconds have passed, but the link has not arrived.");
}
///Get token from incoming link
late final TokenPayload payload;
try {
payload = await _tinkoffId.getTokenPayload(url);
} on PlatformException catch (e, s) {
return Result.failure("Failed to get token from Tinkoff Bank app: ${e.message!}");
}
///Update tokens by refreshToken
late final TokenPayload payloadNew;
try {
payloadNew = await _tinkoffId.updateToken(payload.refreshToken);
} on PlatformException catch (e, s) {
return Result.failure("Failed to exchange refresh otken for access token: ${e.message!}");
}
///Sign out by refresh token
final bool success = await _tinkoffId.signOutByRefreshToken(payloadNew.refreshToken);
if (!success) {
return Result.failure("Failed to log out.");
}
return Result.success([
payload.accessToken,
payload.refreshToken,
payloadNew.accessToken,
payloadNew.refreshToken
]);
}
}
Additional information #
For more information, support, or to report bugs or suggest new features. https://github.com/kodefabrique/tinkoff_id_flutter