Using Single Factor Auth Flutter SDK
After successfully installing and initializing SingleFactorAuth, you can use it to authenticate your users and obtain their private and public keys.
Note
Web3Auth SFA Flutter SDK only works for users who have not enabled MFA. For MFA enabled users, you'll see an Error message.
The SingleFactorAuth instance natively provides the following methods:
- connect - Use to login user and retrive private key pair.
- initialize - This method helps to achieve session management. It authenticates user if the session is present, avoiding re-logging.
Login User
To obtain a user's private key using the Web3Auth SFA Flutter SDK, you can call the connect
method. The method accepts LoginParams
, and returns SFAKey
.
Parameters
- Table
- Class
Parameter | Description |
---|---|
verifier | The verifier parameter takes the name of the ustom verifier from the Web3Auth Dashboard. This is a required field that must be a String . If you're using an aggregate verifier, make sure to pass the sub-verifier name. |
verifierId | The verifierID takes the JWT verifier ID to be used for JWT/ID token verification. It can be an email, sub, or custom value available in the JWT token. |
idToken | The idToken accepts a JWT token obtained from the user's login provider. |
aggregateVerifier? | The aggregateVerifier parameter takes the name of the Aggregate verifier from the Web3Auth Dashboard. |
class LoginParams {
final String verifier;
final String verifierId;
final String idToken;
final String? aggregateVerifier;
LoginParams({
required this.verifier,
required this.verifierId,
required this.idToken,
this.aggregateVerifier,
});
Map<String, dynamic> toJson() {
return {
'verifier': verifier,
'verifierId': verifierId,
'idToken': idToken,
'aggregateVerifier': aggregateVerifier,
};
}
}
Usage
- Single verifier
- Aggregate verifier
Future<SFAKey> connect() {
return _singleFactorAuthFlutterPlugin.connect(LoginParams(
verifier: 'YOUR_VERIFIER_NAME',
verifierId: 'YOUR_VERIFIER_ID',
idToken: 'YOUR_ID_TOKEN',
),
);
}
Future<SFAKey> connect() {
return _singleFactorAuthFlutterPlugin.connect(LoginParams(
verifier: 'YOUR_VERIFIER_NAME',
verifierId: 'YOUR_VERIFIER_ID',
idToken: 'YOUR_ID_TOKEN',
aggregateVerifier: 'YOUR_AGGREGATE_VERIFIER_NAME',
));
}
Session Management
We have included Session Management in this SDK, so calling the initialize function to get the SFAKey value without re-logging in the user if a user has an active session will return the SFAKey, otherwise, it will throw an error.
Usage
try {
final SFAKey? torusKey = await _singleFactorAuthFlutterPlugin.initialize();
} catch (e) {
// Handle error
}