Flutter plugin
This documentation contains information about the Flutter Plugin and integrating the Flutter Plugin with the Mobile SDK.
Obtain the plugin
The plugin and example application are available in the OneWelcome Identity Platform repository. Download the plugin and example application.
Obtain the Mobile SDK
To begin, ensure you have access to the Mobile SDK. To obtain credentials, navigate to the Customer Support Portal and submit a request for access.
Configure your project
Configure your native project for the Flutter Plugin to start work.
Project requirements
- Android: Minimum API level 23
- iOS: Minimum iOS version 13
- Flutter: Minimum Flutter version 1.12.0
Add the plugin to your project
To start using the plugin, you need to add the plugin to your project.
- Open
pubspec.yaml
file in your project - Add dependency -
Onegini: ^x.y.z
. - Run
flutter pub get
command.
Initialize Flutter Plugin
Initialize the Flutter Plugin by calling the startApplication
method.
Example code to initialize the plugin
await Onegini.instance
.startApplication(
twoStepCustomIdentityProviderIds: ["2-way-otp-api"],
connectionTimeout: 5,
readTimeout: 25,
additionalResourceUrls: [])
.catchError((error) {
print("Initialization failed: " + error.message);
});
Configure the Flutter SDK
The Flutter SDK is a wrapper for the Android and iOS SDKs. For this reason, the wrapper SDKs require access to the native SDKs to function, which can be done through the following steps:
- Navigate to the Customer Support Portal and submit a request for access.
- Use the SDK Configurator to configure the Flutter SDK on your application.
Integrate with Android
To integrate the Flutter Plugin with your Android project:
-
Modify the
android/app/build.gradle
android
section:lintOptions { abortOnError false }
-
Add to the
android
->defaultConfig
section:minSdkVersion 23 multiDexEnabled true
-
Add to
android/app/proguard-rules.pro
.-keep class com.onegini.mobile.SecurityController { *; }
-
Add to
android/build.gradle [allprojects.repositories]
allprojects { repositories { google() jcenter() maven { url "https://repo.onewelcome.com/artifactory/onegini-sdk" credentials { username 'YOUR_USERNAME' password 'YOUR_PASSWORD' } } } }
-
Set up the OneWelcome Identity Platform configuration. Generate a
OneginiConfigModel
andkeystore.bks
with the Mobile SDK Configurator. -
Set up the
SecurityController
(not required). To change security options, you should create your own instance ofSecurityController
and handle it to the plugin. By default, security options are brought fromcom.onegini.mobile.SecurityController
. -
In your
MainActivity
class, in theonCreate()
method, you must addOneginiConfigModel
andSecurityController
.override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) OneginiSDK.oneginiClientConfigModel = OneginiConfigModel() OneginiSDK.oneginiSecurityController = SecurityController::class.java }
Note
The Flutter Plugin uses deep links for communication between web pages and your app.
-
Modify
android/app/src/main/AndroidManifest.xml
. Add<intent-filter>
to yourMainActivity
for listening browser redirects. Updatescheme="oneginiexample"
to use the scheme you generated usingonegini-sdk-configurator
.<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="oneginiexample" /> </intent-filter>
Integrate with iOS
-
The Flutter Plugin is uploaded to the OneWelcome Identity Platform Artifactory repository. To let CocoaPods use an Artifactory repository, you need to install the
cocoapods-art
plugin.`gem install cocoapods-art
-
The OneWelcome Identity Platform repository is not a public repository. You must provide credentials to access the repo. Create a file named
.netrc
in your Home folder(~/)
and add the following contents to it:machine repo.onewelcome.com login <username> password <password>
-
Add the OneWelcome Identity Platform CocoaPods repository to your machine:
pod repo-art add onegini htps://repo.onewelcome.com/artifactory/api/pods/cocoapods-public
-
To update the repository, you must manually perform the following update:
pod repo-art add onegini https://repo.onewelcome.com/artifactory/api/pods/cocoapods-public
-
Add next to
ios/Podfile
(before app target):plugin 'cocoapods-art', :sources => [ 'onegini' ]
-
Run
pod install
.
Linking native iOS code
For iOS versions 12.0 and later, to link native code in the xCode project, execute:
cd ios && pod install