¶ OIDC API
¶ Auth by code
After OIDC authentication, we will get an authorization code. Use this API to get user's access token & id token. Note that since we are front end, we cannot set OIDC client secret, instead, we have to use PKCE to get the code.
static Future<AuthResult> authByCode(String code, String codeVerifier, String redirectUrl) async
params
- code authorization code
- codeVerifier PKCE code verifier
- redirectUrl a valid url set in Authing console
example
AuthResult result = await AuthClient.authByCode("P6FENDfGSH72PxgJQk17FoGMWY3oL1G0D2PQ1AfyDeo",
"fu6IivbcEb7DFCytjLmoAICRtFLbG9zkk5QdDbNd0gG",
"https://guard.authing/redirect");
String ak = result.user?.accessToken;
String idToken = result.user?.token;
¶ Use email and password registration
Use the email registration, the mailbox is not case sensitive and the only userpool is unique. This interface does not require the user to verify the mailbox, after the user registration, the emailVerified field will be false.
static Future<AuthResult> registerByEmail(String email, String password) async
Parameter
- email email address
- password password
example
AuthResult result = await OIDCClient.registerByEmail("email", "password");
User user = result.user; // get user info
Error Code
2003
Illegal email address2026
Registered mailbox
¶ Register using username
Use the username to register, the username is case sensitive and the only user pool.
static Future<AuthResult> registerByUserName(String username, String password) async
Parameter
- username username
- password password
Example
AuthResult result = await OIDCClient.registerByUserName("username", "password");
User user = result.user; // get user info
Error Code
2026
Registered mailbox
¶ Use mobile phone number registration
Use your mobile phone number to register, you can set the initial password of the account at the same time. You can pass sendSmsCode method sends SMS verification code.
static Future<AuthResult> registerByPhoneCode(String phone, String code, String password) async
Parameter
- phone The phone number
- code SMS verification code
- password initial password, it can be null
Example
AuthResult result = await OIDCClient.registerByPhoneCode("phone", "code", "password");
User user = result.user; // get user info
Error Code
2001
SMS verification code error2026
Cell phone number registered
¶ OIDC Login by account and password
static Future<AuthResult> loginByAccount(String account, String password) async
params
- account can be one of the following: phone number / email / user name
- password clear text password
example
AuthResult results = await OIDCClient.loginByAccount("your account", "your password");
User user = result.user; // user info
¶ OIDC Login by phone code
login by phone number and a verification code. Must call sendSms method to get an SMS verification code before calling this method.
static Future<AuthResult> loginByPhoneCode(String phone, String code) async
params
- phone phone number
- code SMS code
example
AuthResult result = await OIDCClient.loginByPhoneCode("phone", "code");
User user = result.user; // get user info
¶ Build authorize URL
The buildAuthorizeUrl method can be used to build the login URL, load the URL in your WebView.
static Future<AuthResult> buildAuthorizeUrl(AuthRequest authRequest) async
params
- authRequest Sets the custom parameters.Valid parameters include 'scope','redirectUrl','state'.For a detailed list, check the AuthRequest().
example
AuthRequest authRequest = AuthRequest();
authRequest.createAuthRequest();
// authRequest.scope = "scope";
// authRequest.redirectUrl = "redirectUrl";
String url = await OIDCClient.buildAuthorizeUrl(authRequest);
¶ Token Change user information
Use Access token to get user information.
static Future<AuthResult> getUserInfoByAccessToken(String accessToken, [Map? data]) async
params
- accessToken Access token
example
AuthResult result = await OIDCClient.getUserInfoByAccessToken("accessToken");
User user = result.user; // get user info
¶ Refresh Access Token
Get new Access Token with Refresh token.
static Future<AuthResult> getNewAccessTokenByRefreshToken(String refreshToken) async
params
- refreshToken Refresh Token
example
AuthResult result = await OIDCClient.getNewAccessTokenByRefreshToken("refreshToken");
User user = result.user; // get user info