Flutter Plugin reference
The following reference guides exist for the Flutter Plugin.
authenticateUser
Starts authentication flow. On success, the function will return a OWRegistrationResponse
.
Parameter | Type | Description |
---|---|---|
profileId | String | ProfileId of the user that you want to authenticate. |
authenticatorType | OWAuthenticatorType? | Optional authenticatorType to use for authentication. |
Future<OWRegistrationResponse> authenticateUser(
String profileId,
OWAuthenticatorType? authenticatorType,
)
var registrationResponse = await Onegini.instance.userClient
.authenticateUser(context, profileId, authenticatorType);
authenticateUserImplicitly
You can use implicit authentication to authenticate users based on their client credentials. This means you can assume the user has successfully completed the registration process in the past. After authenticating implicitly, you can fetch resources which require implicit authentication. Implicit authentication requires no user interaction like asking for their PIN or fingerprint.
Future<void> authenticateUserImplicitly(String profileId, List<String>? scopes)
- Used to authenticate a user implicitly.
- Returns the
userProfileId
that was used for the authentication on success. - Throws a
PlatformException
on error.
Description | Default | Description |
---|---|---|
profileId | ~ | A profile ID created when the user profile is registered |
scopes | registration scopes | An array of scopes the user will authenticate with (optional) |
Onegini.instance.userClient.authenticateUserImplicitly("profileId", ["read"]);
changePin
Start the change PIN flow to change a user's PIN.
Future<void> changePin()
During the change PIN flow, the following events
will be fired after which changePin
will resolve:
OpenPinAuthenticationEvent
; answer using theOneginiPinAuthenticationCallback().acceptAuthenticationRequest("pin")
ClosePinAuthenticationEvent
OpenPinRegistrationEvent
; answer usingOneginiPinRegistrationCallback().acceptAuthenticationRequest("newPin")
ClosePinRegistrationEvent
await Onegini.instance.userClient
.changePin()
.catchError((error) {
if (error is PlatformException) {
print("Pin change failed");
}
});
Custom objects
OWUserProfile
Object representing information regarding a user profile.
Attribute | Type |
---|---|
profileId | String |
OWCustomInfo
Custom info can be used to give the user some additional information regarding requests.
Attribute | Type |
---|---|
status | int |
data | String? |
OWIdentityProvider
Object used to represent information regarding an identity provider.
Attribute | Type |
---|---|
id | String |
name | String |
OWCustomIdentityProvider
Object used to represent information regarding an custom identity provider.
Attribute | Type |
---|---|
id | String |
name | String |
isTwoSteo | bool |
OWAuthenticator
Object representing information regarding an authenticator.
Attribute | Type |
---|---|
id | String |
name | String |
isRegistered | bool |
isPreferred | bool |
authenticatorType | OWAuthenticatorType |
OWAppToWebSingleSignOn
Object used during single sign-on.
Attribute | Type |
---|---|
token | String |
redirectUrl | String |
OWRegistrationResponse
Object containing information regarding the registration and the freshly registered user.
Attribute | Type |
---|---|
userProfile | OWUserProfile |
customInfo | OWCustomInfo? |
OWAuthenticationAttempt
Object that gives information regarding an authentication attempt.
Attribute | Type |
---|---|
failedAttempts | int |
maxAttempt | int |
remainingAttempts | int |
OWAuthenticatorType
Enum for specifying the authenticator type.
enum OWAuthenticatorType {
pin,
biometric,
}
RequestDetails
This object is used to configure your resource request.
Attribute | Type |
---|---|
path | String |
method | HttpRequestMethod |
headers | Map |
body | String |
RequestResponse
Object used to represent the information related to the response of the resource request.
Attribute | Type |
---|---|
headers | Map |
body | String |
ok | bool |
status | int |
deregisterBiometricAuthenticator
deregisterBiometricAuthenticator
will remove the ability to authenticate using biometrics on the device for the authenticated user.
Future<void> deregisterBiometricAuthenticator()
await Onegini.instance.userClient
.deregisterBiometricAuthenticator();
deregisterUser
Deregistration is the process of removing a user (profile) from the device and server.
To obtain a list of potential profiles that can be removed from the device use getUserProfiles
.
Future<void> deregisterUser(String profileId)
await Onegini.instance.userClient
.deregisterUser(profileId)
.catchError((error) {
print("Deregistration failed: " + error.message);
});
enrollMobileAuthentication
Authenticated users can enroll for mobile authentication, allowing them to execute mobile authentication with OTP. See mobile authentication with OTP for more information on mobile authentication. In the scenario that the enrollment fails, a PlatformException
will be thrown.
Future<void> EnrollMobileAuthentication()
await Onegini.instance.userClient.enrollMobileAuthentication();
getAccessToken
Returns the access token for the currently authenticated user as a string.
Future<String> getAccessToken()
var accessToken = await Onegini.instance.userClient.getAccessToken()
getAppToWebSingleSignOn
Single sign-on the user web page and returns a OWAppToWebSingleSignOn
on success.
Future<OWAppToWebSingleSignOn> getAppToWebSingleSignOn(String url)
var oneginiAppToWebSingleSignOn = await Onegini.instance.userClient
.getAppToWebSingleSignOn(
"https://login-mobile.test.onegini.com/personal/dashboard")
.catchError((error) {
print("Single sign on failed: " + error.message);
});
getAuthenticatedUserProfile
Method to retrieve the currently authenticated userProfile
(OWUserProfile).
Future<OWUserProfile> getAuthenticatedUserProfile()
var profile = await Onegini.instance.userClient.getAuthenticatedUserProfile();
getBiometricAuthenticator
Attempts to get the biometric authenticator for the supplied userProfile
.
Future<OWAuthenticator> getBiometricAuthenticator(String profileId)
await Onegini.instance.userClient
.getBiometricAuthenticator();
getIdentityProviders
Returns a list of available identity providers (OWIdentityProvider
).
Future<List<OWIdentityProvider>> getIdentityProviders()
var identityProviders = await Onegini.instance.userClient.getIdentityProviders()
getPreferredAuthenticator
Attempts to get the preferred authenticator for the supplied userProfile
.
Future<OWAuthenticator> getPreferredAuthenticator(String profileId)
await Onegini.instance.userClient
.getPreferredAuthenticator();
getRedirectUrl
Returns current redirect URL used in registration with browser IdP. See Registration with browser IdP for more details.
Future<String> getRedirectUrl()
var redirectUrl = await Onegini.instance.userClient.getRedirectUrl();
getUserProfiles
The Flutter plugin maintains a set of profiles that you have created. This method allows you to retrieve all existing profiles. It will return a List of OWUserProfile
.
Future<List<OWUserProfile>> getUserProfiles()
val userProfiles = await Onegini.instance.userClient.getUserProfiles();
handleMobileAuthWithOtp
Starts mobile authentication using OTP as described in mobile authentication with OTP.
Caveats:
- A user needs to be authenticated.
- Only one OTP mobile authentication flow can occur at a given moment.
Future<void> handleMobileAuthWithOtp(String data)
await Onegini.instance.userClient
.handleMobileAuthWithOtp(data)
.catchError((error) {
print("OTP Mobile authentication request failed: " + error.message);
});
logout
Method for log out.
Future<void> logout()
await Onegini.instance.userClient
.logout()
.catchError((error) {
print("Logout failed: " + error.message);
});
registerBiometricAuthenticator
registerBiometricAuthenticator
will attempt to register a biometric authenticator that can then be used for authentication. If the a biometric authenticator is available, a PIN authentication flow will be triggered before the authenticator will be registered.
Future<void> registerBiometricAuthenticator()
await Onegini.instance.userClient
.registerBiometricAuthenticator();
registerUser
Start registration flow.
If identityProviderId
is null, it starts standard browser registration. Use your scopes
for registration. By default it is "read".
Future<OWRegistrationResponse> registerUser(String? identityProviderId, List<String>? scopes)
var owRegistrationResponse = await Onegini.instance.userClient
.registerUser(context, identityProviderId, "read")
.catchError((error) {
print("Registration failed: " + error.message);
});
resourceRequest
Resources can be fetched using user authentication, implicit authentication, and anonymous authentication, or while being unauthenticated. Refer to secure resource access for more information about the differences between these types of requests.
Future<RequestResponse> requestResource(type: ResourceRequestType, details: RequestDetails): RequestResponse
Additionally, the functions directly perform the different types of resource requests using:
requestResourceAuthenticated(details: RequestDetails): RequestResponse
( requires user authentication)requestResourceImplicit(details: RequestDetails): RequestResponse
(requires implicit authentication)requestResourceAnonymous(details: RequestDetails): RequestResponse
(requires anonymous authentication)requestResourceUnauthenticated(details: RequestDetails): RequestResponse
(requires no authentication)
Example using the resourceRequest method to perform a anonymous GET request:
var response = await Onegini.instance.resourcesMethods.resourceRequest(ResourceRequestType.anonymous, RequestDetails(path: "application-details", method: HttpRequestMethod.get));
As described in secure resource access, there are multiple modes to request resources that might require the user to be authenticated. The mode can be set using the ResourceRequestType
enum type:
enum ResourceRequestType {
authenticated,
implicit,
anonymous,
unauthenticated
}
setPreferredAuthenticator
Sets the preferred authenticator of the currently authenticated user.
Future<void> setPreferredAuthenticator(OWAuthenticatorType authenticatorType)
Parameter | Description |
---|---|
authenticatorType | OWAuthenticatorType enum either biometric or PIN |
await Onegini.instance.userClient.setPreferredAuthenticator(OWAuthenticatorType.pin)
startApplication
The first thing that needs to be done when the app starts is to initialize the Flutter Plugin. This will perform a few checks and report an error in case of trouble.
Function Signature
Future<List<RemovedUserProfile>> startApplication(
{
String? securityControllerClassName,
String? configModelClassName,
List<Map<String, Object>>? customIdentityProviderConfigs,
int? connectionTimeout,
int? readTimeout,
List<String>? additionalResourceUrls,
}
)
Example
var removedUserProfiles = await Onegini.instance
.startApplication(
securityControllerClassName:
"com.onegini.mobile.onegini_example.SecurityController",
configModelClassName:
"com.onegini.mobile.onegini_example.OneginiConfigModel",
customIdentityProviderConfigs: [
{"providerId": "2-way-otp-api", "isTwoStep": true}
],
connectionTimeout: 5,
readTimeout: 25,
additionalResourceUrls: [])
validatePinWithPolicy
Validates the supplied PIN against the PIN policy enforced by the Mobile Identity module, the policy will be checked on the device and the PIN will never be sent over the internet. If the PIN is not valid, a PlatformException
will be thrown.
Future<void> validatePinWithPolicy(String pin);
await Onegini.instance.userClient
.validatePinWithPolicy(pin)
.catchError((error) {
if (error is PlatformException) {
clearAllDigits();
showFlutterToast(error.message);
}
});