casauth 1.1.2
casauth: ^1.1.2 copied to clipboard
A third Flutter client SDK for casdoor.
casauth #
[CASAuth Logo]
A third Flutter client SDK for casdoor. Support follow platform:
| platform | tested | example |
|---|---|---|
| iOS | ✅ | App Store |
| 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 | ✅ |
Usage #
In the example folder has a full app example develop with Flutter v3.3.0 and Casdoor. 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";
CASAuth(
appName,
appId,
server,
orgnazationName,
);
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);
if (resp.status == "error") {
// handle error
log("signup failed, error: ${resp.message}, body: ${resp.jsonBody}");
} else {
// that's ok
}
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,
);
if (resp.status == "error") {
// handle error
log("signup failed, error: ${resp.message}, body: ${resp.jsonBody}");
} else {
// that's ok
}
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,
);
if (resp.status == "error") {
// handle error
log("signup failed, error: ${resp.message}, body: ${resp.jsonBody}");
} else {
// that's ok
}
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 #
static Future<AuthResult> sendCode(
String dest, {
AccountType? type = AccountType.phone,
String? checkId = "",
String? checkKey = "",
String? checkType = "none",
String? checkUser = "",
}) async
Fetch current user info #
static Future<void> userInfo() async