auth_flutter
A flutter plug-in for the native Auth-Core library (Android and iOS).
Installation
First, add auth_flutter as a dependency in your pubspec.yaml file.
Android
Add TekoGoogleRegistryToken to local.properties of this project (contact trung.cs@teko.vn to get
the token).
// android/local.properties
TekoGoogleRegistry.password=<your-token>
In project build.grade. Add the following code:
allprojects {
repositories {
...
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
maven {
setUrl("https://asia-southeast1-maven.pkg.dev/teko-development/teko-mobile-sdks")
authentication {
basic(BasicAuthentication)
}
credentials {
username = "_json_key_base64"
password = properties.getProperty('TekoGoogleRegistry.password')
}
}
}
}
iOS
Setup github access token for accessing Teko iOS frameworks (contact trung.cs@teko.vn to get the token)..
- Open terminal:
touch /.bash_profile; open /.bash_profile(a text editor will be opened) - Add a new line:
export GITHUB_USER_TOKEN="<your-token>" - Save file and go back to terminal:
source ~/.bash_profile
Library usage
Get an Auth instance
Static Method: `TerraAuth.getInstance(String appName) → Future
Should be called in initialize phase of your app and must be called after initilizing TerraApp successful.
This also initialises reCaptcha: the tenant's recaptchaConfig (keyId, isEnabled,
timeoutMilliseconds) is read from the Terra IAM service config and handed to the native
reCaptcha Enterprise SDK. It runs once per Terra app, needs no host app change, and is a no-op
when the tenant has no reCaptcha config or has it disabled. Failure never blocks
authentication — reCaptcha is anti-abuse hardening, not a login precondition.
iOS only. Android's auth-core exposes a getRecaptchaToken entry point, but this plugin
does not wire it up yet; the Android OTP paths send no token.
Check login state
Method: isAuthorized() -> Future<Result<bool, Exception>>
Check whether current app is authorized or not
Get access token
Method: getAccessToken() -> Future<Result<IamToken, Exception>>
Get saved access token.
Refresh token
Method: refreshToken() -> Future<Result<IamToken, Exception>>
Refresh current token (Should call this function after the current token is expired) Return new access token if success.
Exchange token
Method: exchangeToken() -> Future<Result<IdToken, Exception>>
Create a new id-token from iamAudience that was set on IAM console
Request otp
Method: requestOtp() -> Future<Result<Object, Exception>>
request send a OTP to a specific phone number to login.
On iOS the request carries a reCaptcha token for the LOGIN action, obtained from the SDK
initialised by getInstance. If reCaptcha is unavailable or disabled the request still goes
out, with an empty token.
The same applies to verifyPhone, which sends a token for the VERIFY action. reCaptcha
guards the steps that trigger an SMS — requestOtp and verifyPhone — and not the OTP
confirmation steps (confirmPhone, confirmEmail), which the code itself already limits.
The email paths carry no token: the native SDK has no such parameter for them.
Login with credential
Method: loginWithCredential(LoginCredential credential) -> Future<Result<bool, Exception>>
There are 6 types of credential:
- AppleCredential (should be created from
AppleProvider.createCredential(String accessToken)) - FacebookCredential (should be created from
FacebookProvider.createCredential(String accessToken)) - GoogleCredential (should be created from
GoogleProvider.createCredential(String accessToken)) - PhoneOtpCredential (should be created from
PhoneOtpProvider.createCredential(String phoneNumber, String otp)) - UsernamePasswordCredential (should be created from
UsernamePasswordProvider.createCredential(String username, String password)) - CustomCredential (should be created from
CustomProvider.createCredential(String idToken))
Login Google directly
Method: loginWithGoogle() -> Future<Result<bool, Exception>>
Login Facebook directly
Method: loginWithFacebook() -> Future<Result<bool, Exception>>
Login Apple directly
Method: loginWithApple() -> Future<Result<bool, Exception>>
Logout
Method: `logout() -> Future<Result<bool, Exception>>
Perform logging out.
Libraries
- credential/apple_credential
- credential/custom_credential
- credential/facebook_credential
- credential/google_credential
- credential/login_credential
- credential/phone_otp_credential
- credential/username_password_credential
- model/iam_token
- model/id_token
- model/user_info
- provider/apple_provider
- provider/custom_token_provider
- provider/facebook_provider
- provider/google_provider
- provider/phone_otp_provider
- provider/username_password_provider
- result/result
- terra_auth