auth_flutter 2.0.0 auth_flutter: ^2.0.0 copied to clipboard
A flutter plug-in for the native Auth library (Android and iOS).
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.
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.
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.