casauth

A third Flutter client SDK for casdoor. Support follow platform:
| platform | tested | example |
|---|---|---|
| iOS | ✅ | - |
| macOS | ✅ | Download |
| linux | - |
- |
| Windows | - |
- |
Prepare
You need install self's casdoor first. And I only test this SDK with a little version.
| CASAuth Version | Casdoor Version | Tested |
|---|---|---|
| v1.1.0 | v1.97.0 | ✅ |
| v1.1.0 | v1.123.0 | ✅ |
| v1.2.0 | v1.223.0 | ✅ |
Usage
In the example folder has a full app example develop with Flutter v3.3.0 and Casdoor. If casdoor server response status is error or code not 200, the SDK will thorws AuthClientError.
I will show howto use this SDK follow:
initiate
import 'package:casauth/casauth.dart';
String appId = "some-app-id";
String appName = "app-example";
String orgnazationName = "casbin";
String server = "https://door.casdoor.com";
try {
CASAuth(
appName,
appId,
server,
orgnazationName,
);
await CASAuth.init();
} catch (e) {
debugPrint("init casauth SDK failed: $e");
}
login
AuthResult resp = AuthClient.loginByUserName(username, password);
register
Register new user only with username and password. If displayName is required by casdoor, it will be same with username.
AuthResult resp = await AuthClient.registerByUserName(username, password);
Regsiter new user with email and verification code, username, password and displayName is optional. if username adn password is required by casdoor, it will be filled with random string.
AuthResult resp = await AuthClient.registerByEmail(
email,
verifyCode,
username: username,
password: password,
);
Regsiter new user with phone and verification code, username, password and displayName is optional.
AuthResult resp = await AuthClient.registerByPhone(
phone,
verifyCode,
username: username,
password: password,
);
APIs
Authentication APIs
Register by username
static Future<AuthResult> registerByUserName(
String username,
String password, {
String displayName = "",
}) async
Register by email
static Future<AuthResult> registerByEmail(
String email,
String code, {
String username = '',
String password = '',
String displayName = '',
}) async
Register by phone
static Future<AuthResult> registerByPhone(
String phone,
String code, {
String username = '',
String password = '',
String displayName = '',
String countryCode = "86",
}) async
Login by username
static Future<AuthResult> loginByUserName(
String username,
String password, {
bool autoSignin = false,
}) async
Login by verification code
static Future<AuthResult> loginByCode(
String phoneOrEmail,
String code, {
AccountType type = AccountType.phone,
bool autoSignin = false,
String countryCode = "86",
}) async
Logout
static Future<AuthResult?> logout() async
Get Captcha
static Future<CaptchaResult> getCaptcha() async
Send verification code
If method is empty or not method, casdoor server will check user is exists.
static Future<AuthResult> sendCode(
String dest, {
AccountType? type = AccountType.phone,
String? checkId = "",
String? checkKey = "",
String? checkType = "none",
String? checkUser = "",
String? method = "signup",
}) async
Fetch current user info
static Future<User?> userInfo() async