Skip to main content

Crate casdoor_rust_sdk

Crate casdoor_rust_sdk 

Source
Expand description

Casdoor’s SDK for Rust, it lets an application use Casdoor as its authentication and authorization system, without having to implement one from scratch.

Everything is done through the Client, which is created from the config of a Casdoor application:

use casdoor_rust_sdk::Client;

let client = Client::new(
    "http://localhost:8000",
    "<client-id>",
    "<client-secret>",
    "<certificate>",
    "built-in",
    "app-built-in",
);

// Redirect the user to this URL to sign in.
let signin_url = client.get_signin_url("http://localhost:9000/callback");

// In the callback, exchange the code for an access token and read the user.
let token = client.get_oauth_token("<code>").await?;
let claims = client.parse_jwt_token(&token.access_token)?;
println!("signed in as {}", claims.user.name);

// Call the APIs as the application itself.
let users = client.get_users().await?;

The SDK is kept in sync with the Go SDK, one Rust module per Go file, so that the two are easy to compare.

Structs§

AccountItem
Adapter
Adapter has the same definition as https://github.com/casdoor/casdoor/blob/master/object/adapter.go.
Address
Application
Application has the same definition as https://github.com/casdoor/casdoor/blob/master/object/application.go.
AuthConfig
AuthConfig is the core configuration of the SDK, it has the same fields as the AuthConfig struct of the Casdoor Go SDK.
CasbinRule
CasbinRule is one policy rule stored by a Casbin adapter. Its JSON fields are capitalized, as the Casbin xorm adapter defines them without JSON tags.
Cert
Cert has the same definition as https://github.com/casdoor/casdoor/blob/master/object/cert.go.
Claims
Claims is the payload of the JWT token issued by Casdoor, it embeds the User the token was issued to.
Client
Client is the Casdoor client, it holds the config of the Casdoor application and sends all the API requests to the Casdoor server.
ConsentRecord
Enforcer
Enforcer has the same definition as https://github.com/casdoor/casdoor/blob/master/object/enforcer.go.
FaceId
Group
Group has the same definition as https://github.com/casdoor/casdoor/blob/master/object/group.go.
Header
IntrospectTokenResult
The result of the RFC 7662 token introspection.
Invitation
Invitation has the same definition as https://github.com/casdoor/casdoor/blob/master/object/invitation.go.
JwtItem
Ldap
Ldap has the same definition as https://github.com/casdoor/casdoor/blob/master/object/ldap.go.
LdapUser
One user read from an LDAP server.
LdapUsersResponse
The response of Client::get_ldap_users().
ManagedAccount
MfaAccount
MfaInitiateData
The data of the response of Client::initiate_mfa().
MfaItem
MfaProps
MfaRequest
Model
Model has the same definition as https://github.com/casdoor/casdoor/blob/master/object/model.go.
OAuthToken
The OAuth token returned by the Casdoor server.
Order
Order has the same definition as https://github.com/casdoor/casdoor/blob/master/object/order.go.
Organization
Organization has the same definition as https://github.com/casdoor/casdoor/blob/master/object/organization.go.
Payment
Payment has the same definition as https://github.com/casdoor/casdoor/blob/master/object/payment.go.
Permission
Permission has the same definition as https://github.com/casdoor/casdoor/blob/master/object/permission.go.
PermissionRule
PermissionRule has the same definition as https://github.com/casdoor/casdoor/blob/master/object/permission_rule.go.
Plan
Plan has the same definition as https://github.com/casdoor/casdoor/blob/master/object/plan.go.
PolicyFilter
A filter used by Client::get_filtered_policies().
Pricing
Pricing has the same definition as https://github.com/casdoor/casdoor/blob/master/object/pricing.go.
Product
Product has the same definition as https://github.com/casdoor/casdoor/blob/master/object/product.go.
ProductInfo
One product of an Order.
Provider
Provider has the same definition as https://github.com/casdoor/casdoor/blob/master/object/provider.go.
ProviderItem
Record
Record has the same definition as https://github.com/casdoor/casdoor/blob/master/object/record.go.
Resource
Resource has the same definition as https://github.com/casdoor/casdoor/blob/master/object/resource.go.
Response
Response is the general response returned by the Casdoor server APIs.
Role
Role has the same definition as https://github.com/casdoor/casdoor/blob/master/object/role.go.
SamlItem
ScopeDescription
ScopeItem
Session
Session has the same definition as https://github.com/casdoor/casdoor/blob/master/object/session.go.
SigninItem
SigninMethod
SignupItem
Subscription
Subscription has the same definition as https://github.com/casdoor/casdoor/blob/master/object/subscription.go.
SyncLdapUsersResponse
The response of Client::sync_ldap_users().
Syncer
Syncer has the same definition as https://github.com/casdoor/casdoor/blob/master/object/syncer.go.
TableColumn
ThemeData
ThirdPartyLink
Token
Token has the same definition as https://github.com/casdoor/casdoor/blob/master/object/token.go.
Transaction
Transaction has the same definition as https://github.com/casdoor/casdoor/blob/master/object/transaction.go.
User
User has the same definition as https://github.com/casdoor/casdoor/blob/master/object/user.go.
Userinfo
The user info returned by the OIDC /api/userinfo API.
Webhook
Webhook has the same definition as https://github.com/casdoor/casdoor/blob/master/object/webhook.go.

Enums§

CasdoorError
The error type returned by all the SDK APIs.
PostBody
The body of a POST request sent to the Casdoor server.

Constants§

CASDOOR_APPLICATION
The name of the built-in Casdoor application.
CASDOOR_ORGANIZATION
The name of the built-in Casdoor organization.
MFA_RECOVERY_CODES_SESSION
The name of the session that holds the MFA recovery codes.
MFA_TYPE_APP
The MFA type of an authenticator app (TOTP).
MFA_TYPE_EMAIL
The MFA type sent by email.
MFA_TYPE_SMS
The MFA type sent by SMS.
SUB_STATE_ACTIVE
The subscription is running.
SUB_STATE_ERROR
The subscription failed.
SUB_STATE_EXPIRED
The subscription has ended.
SUB_STATE_PENDING
The subscription is waiting for its payment.
SUB_STATE_SUSPENDED
The subscription was suspended by the admin.
SUB_STATE_UPCOMING
The subscription has not started yet.

Functions§

get_current_time
Get the current time in RFC 3339 format (UTC), e.g. 2026-01-02T15:04:05Z, which is the format Casdoor uses for fields like created_time.

Type Aliases§

CasbinRequest
A Casbin request, such as ["alice", "data1", "read"].
CasdoorConfigDeprecated
The old name of AuthConfig, kept to ease the migration from the 1.x versions.
CasdoorUserDeprecated
The old name of User, kept to ease the migration from the 1.x versions.
Result
The result type returned by all the SDK APIs.