Skip to main content

Client

Struct Client 

Source
pub struct Client {
    pub config: AuthConfig,
    pub custom_headers: HashMap<String, String>,
    pub access_token: Option<String>,
    /* private fields */
}
Expand description

Client is the Casdoor client, it holds the config of the Casdoor application and sends all the API requests to the Casdoor server.

use casdoor_rust_sdk::Client;

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

let users = client.get_users().await?;

Fields§

§config: AuthConfig

The config of the Casdoor application.

§custom_headers: HashMap<String, String>

The extra HTTP headers added to every request sent to the Casdoor server.

§access_token: Option<String>

The user’s access token. If it’s not empty, all the API requests sent by this client are authenticated as the user who owns the access token (via the Authorization: Bearer header), instead of as the application itself (via the client ID and client secret’s Basic Auth). Use Client::with_access_token() to get such a client.

Implementations§

Source§

impl Client

Source

pub async fn get_adapters(&self) -> Result<Vec<Adapter>>

Get the adapters of the client’s organization.

Source

pub async fn get_pagination_adapters( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Adapter>, i32)>

Get one page of the adapters of the client’s organization, together with the total number of the adapters.

Source

pub async fn get_adapter(&self, name: &str) -> Result<Option<Adapter>>

Get one adapter by name.

Source

pub async fn add_adapter(&self, adapter: &Adapter) -> Result<bool>

Add an adapter.

Source

pub async fn update_adapter(&self, adapter: &Adapter) -> Result<bool>

Update an adapter.

Source

pub async fn delete_adapter(&self, adapter: &Adapter) -> Result<bool>

Delete an adapter.

Source§

impl Client

Source

pub async fn get_applications(&self) -> Result<Vec<Application>>

Get all the applications.

Source

pub async fn get_organization_applications(&self) -> Result<Vec<Application>>

Get the applications of the client’s organization.

Source

pub async fn get_application(&self, name: &str) -> Result<Option<Application>>

Get one application by name.

Source

pub async fn add_application(&self, application: &Application) -> Result<bool>

Add an application.

Source

pub async fn update_application( &self, application: &Application, ) -> Result<bool>

Update an application.

Source

pub async fn delete_application( &self, application: &Application, ) -> Result<bool>

Delete an application.

Source§

impl Client

Source

pub async fn get_oauth_token(&self, code: &str) -> Result<OAuthToken>

Get the pivotal and necessary secret to interact with the Casdoor server, by exchanging the authorization code that Casdoor sent back to the redirect URI.

Source

pub async fn refresh_oauth_token( &self, refresh_token: &str, ) -> Result<OAuthToken>

Refresh the OAuth token with a refresh token.

Source

pub async fn get_oauth_token_by_password( &self, username: &str, password: &str, ) -> Result<OAuthToken>

Get the OAuth token via the password grant type, i.e. the “Resource Owner Password Credentials Grant” of OAuth 2.0. The password grant type must be enabled in the application’s “Grant types” in Casdoor.

The username is the user’s name inside the application’s organization, like alice instead of my-org/alice.

Source

pub async fn impersonate_user( &self, username: &str, master_password: &str, ) -> Result<OAuthToken>

Get an OAuth token which acts as the given user, so that an admin can call the APIs on behalf of the user, without knowing the user’s own password. It’s the SDK equivalent of the “Impersonation” button in Casdoor’s Web UI.

The master_password is the “Master password” of the user’s organization, it needs to be set in Casdoor first: “Organizations” -> Edit the organization -> “Master password”. See https://casdoor.org/docs/user/impersonation.

Source§

impl Client

Source

pub async fn get_global_certs(&self) -> Result<Vec<Cert>>

Get the certs shared by all the organizations.

Source

pub async fn get_certs(&self) -> Result<Vec<Cert>>

Get the certs of the client’s organization.

Source

pub async fn get_cert(&self, name: &str) -> Result<Option<Cert>>

Get one cert by name.

Source

pub async fn add_cert(&self, cert: &Cert) -> Result<bool>

Add a cert.

Source

pub async fn update_cert(&self, cert: &Cert) -> Result<bool>

Update a cert.

Source

pub async fn delete_cert(&self, cert: &Cert) -> Result<bool>

Delete a cert.

Source§

impl Client

Source

pub fn new( endpoint: impl Into<String>, client_id: impl Into<String>, client_secret: impl Into<String>, certificate: impl Into<String>, organization_name: impl Into<String>, application_name: impl Into<String>, ) -> Self

Create a new client from the 6 config values.

Source

pub fn from_config(config: AuthConfig) -> Self

Create a new client from an AuthConfig.

Source

pub fn from_toml(path: &str) -> Result<Self>

Create a new client from a TOML config file, see AuthConfig::from_toml().

Source

pub fn with_access_token(&self, access_token: impl Into<String>) -> Self

Return a copy of the client that calls all the Casdoor APIs as the user who owns the given access token, rather than as the application. The access token is the user’s OAuth access token returned by Client::get_oauth_token(), Client::refresh_oauth_token(), Client::get_oauth_token_by_password() or Client::impersonate_user().

The returned client is independent from the original one, so the original client keeps using the application’s client ID and client secret, and it’s safe to create one client per user request:

let token = client.get_oauth_token(code).await?;
let user = client.with_access_token(token.access_token).get_account().await?;

Note that the APIs are still subject to Casdoor’s permission check, so a non-admin user can only access their own data.

Source

pub fn with_custom_header( &self, key: impl Into<String>, value: impl Into<String>, ) -> Self

Return a copy of the client that adds the given HTTP header to every request.

Source

pub fn with_http_client(&self, http: Client) -> Self

Return a copy of the client that uses the given reqwest::Client, so that the timeout, the proxy, the TLS options, etc. can be customized.

Source

pub fn get_url(&self, action: &str, query: &[(&str, &str)]) -> String

Return the URL of an API action, such as http://localhost:8000/api/get-user?id=built-in%2Fadmin.

Source

pub fn get_id(&self, name: &str) -> String

Return the Casdoor object ID ("owner/name") of an object owned by an organization. If name is already a qualified "owner/name" ID, it is returned as-is, so that a client can also address objects that live outside of its own organization. Object names never contain a slash in Casdoor.

Source

pub async fn do_get_response(&self, url: &str) -> Result<Response>

The general function to send a GET request and get the whole Response.

Source

pub async fn do_get_bytes_raw(&self, url: &str) -> Result<Vec<u8>>

The general function to send a GET request and get the raw response body.

Source

pub async fn do_post( &self, action: &str, query: &[(&str, &str)], body: PostBody<'_>, ) -> Result<Response>

The general function to send a POST request and get the whole Response.

Source

pub async fn do_post_bytes_raw( &self, url: &str, body: PostBody<'_>, ) -> Result<Vec<u8>>

The general function to send a POST request and get the raw response body.

Source§

impl Client

Source

pub async fn send_email( &self, title: &str, content: &str, sender: &str, receivers: &[&str], ) -> Result<()>

Send an email with the default email provider of the organization.

Source

pub async fn send_email_by_provider( &self, title: &str, content: &str, sender: &str, provider: &str, receivers: &[&str], ) -> Result<()>

Send an email with the given email provider.

Source§

impl Client

Source

pub async fn enforce( &self, permission_id: &str, model_id: &str, resource_id: &str, enforcer_id: &str, owner: &str, casbin_request: &CasbinRequest, ) -> Result<bool>

Check whether a Casbin request is allowed by a permission, a model, a resource or an enforcer. Only one of permission_id, model_id, resource_id and enforcer_id needs to be given, the others can be empty.

Source

pub async fn batch_enforce( &self, permission_id: &str, model_id: &str, resource_id: &str, enforcer_id: &str, owner: &str, casbin_requests: &[CasbinRequest], ) -> Result<Vec<Vec<bool>>>

Check a batch of Casbin requests at once, the returned matrix has one row per permission and one column per request.

Source§

impl Client

Source

pub async fn get_enforcers(&self) -> Result<Vec<Enforcer>>

Get the enforcers of the client’s organization.

Source

pub async fn get_pagination_enforcers( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Enforcer>, i32)>

Get one page of the enforcers of the client’s organization, together with the total number of the enforcers.

Source

pub async fn get_enforcer(&self, name: &str) -> Result<Option<Enforcer>>

Get one enforcer by name.

Source

pub async fn add_enforcer(&self, enforcer: &Enforcer) -> Result<bool>

Add an enforcer.

Source

pub async fn update_enforcer(&self, enforcer: &Enforcer) -> Result<bool>

Update an enforcer.

Source

pub async fn delete_enforcer(&self, enforcer: &Enforcer) -> Result<bool>

Delete an enforcer.

Source§

impl Client

Source

pub async fn get_groups(&self) -> Result<Vec<Group>>

Get the groups of the client’s organization.

Source

pub async fn get_pagination_groups( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Group>, i32)>

Get one page of the groups of the client’s organization, together with the total number of the groups.

Source

pub async fn get_group(&self, name: &str) -> Result<Option<Group>>

Get one group by name.

Source

pub async fn add_group(&self, group: &Group) -> Result<bool>

Add a group.

Source

pub async fn update_group(&self, group: &Group) -> Result<bool>

Update a group.

Source

pub async fn delete_group(&self, group: &Group) -> Result<bool>

Delete a group.

Source§

impl Client

Source

pub async fn get_invitations(&self) -> Result<Vec<Invitation>>

Get the invitations of the client’s organization.

Source

pub async fn get_pagination_invitations( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Invitation>, i32)>

Get one page of the invitations of the client’s organization, together with the total number of the invitations.

Source

pub async fn get_invitation(&self, name: &str) -> Result<Option<Invitation>>

Get one invitation by name.

Source

pub async fn get_invitation_info( &self, code: &str, application_name: &str, ) -> Result<Option<Invitation>>

Get the invitation of an invitation code in an application.

Source

pub async fn add_invitation(&self, invitation: &Invitation) -> Result<bool>

Add an invitation.

Source

pub async fn update_invitation(&self, invitation: &Invitation) -> Result<bool>

Update an invitation.

Source

pub async fn update_invitation_for_columns( &self, invitation: &Invitation, columns: &[&str], ) -> Result<bool>

Update only the given columns of an invitation.

Source

pub async fn delete_invitation(&self, invitation: &Invitation) -> Result<bool>

Delete an invitation.

Source§

impl Client

Source

pub fn parse_jwt_token(&self, token: &str) -> Result<Claims>

Parse and verify a JWT token issued by Casdoor with the application’s certificate, and return its claims. The RSA (RS256, RS384, RS512, PS256, PS384, PS512) and the ECDSA (ES256, ES384) signing methods are supported.

Source§

impl Client

Source

pub async fn get_ldaps(&self) -> Result<Vec<Ldap>>

Get all the LDAP servers.

Source

pub async fn get_ldap(&self, id: &str) -> Result<Option<Ldap>>

Get one LDAP server by ID.

Source

pub async fn add_ldap(&self, ldap: &Ldap) -> Result<bool>

Add an LDAP server.

Source

pub async fn update_ldap(&self, ldap: &Ldap) -> Result<bool>

Update an LDAP server.

Source

pub async fn delete_ldap(&self, ldap: &Ldap) -> Result<bool>

Delete an LDAP server.

Source

pub async fn get_ldap_users( &self, id: &str, ) -> Result<Option<LdapUsersResponse>>

Get the users of an LDAP server, together with the UUIDs that already exist in Casdoor.

Source

pub async fn sync_ldap_users( &self, id: &str, users: &[LdapUser], ) -> Result<Option<SyncLdapUsersResponse>>

Sync the given LDAP users into Casdoor.

Source

pub async fn sync_ldap_users_from_server( &self, id: &str, ) -> Result<Option<SyncLdapUsersResponse>>

Read the users of an LDAP server and sync them all into Casdoor.

Source§

impl Client

Source

pub async fn logout(&self, access_token: &str) -> Result<()>

Log out the user that owns the access_token by calling the /api/sso-logout API. It performs a single sign-out: all the sessions of the user across all the applications of the organization are deleted and all the access tokens issued to the user are expired.

The access_token is the user’s access token returned by Client::get_oauth_token().

Source

pub async fn logout_current_session(&self, access_token: &str) -> Result<()>

Like Client::logout(), but only ends the session that the access_token belongs to, so the user stays signed in on their other devices and browsers.

Source§

impl Client

Source

pub async fn initiate_mfa( &self, owner: &str, mfa_type: &str, name: &str, ) -> Result<MfaInitiateData>

Start the setup of an MFA method for a user, the returned secret and URL are used to show the QR code of the authenticator app.

Source

pub async fn verify_mfa( &self, owner: &str, mfa_type: &str, name: &str, secret: &str, passcode: &str, ) -> Result<bool>

Verify the passcode of an MFA method that is being set up.

Source

pub async fn enable_mfa( &self, owner: &str, mfa_type: &str, name: &str, secret: &str, recovery_code: &str, ) -> Result<bool>

Enable a verified MFA method for a user.

Source

pub async fn set_preferred_mfa( &self, owner: &str, mfa_type: &str, name: &str, secret: &str, ) -> Result<()>

Set an MFA method as the preferred one of a user.

Source

pub async fn delete_mfa(&self, owner: &str, name: &str) -> Result<()>

Delete all the MFA methods of a user.

Source§

impl Client

Source

pub async fn get_models(&self) -> Result<Vec<Model>>

Get the models of the client’s organization.

Source

pub async fn get_pagination_models( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Model>, i32)>

Get one page of the models of the client’s organization, together with the total number of the models.

Source

pub async fn get_model(&self, name: &str) -> Result<Option<Model>>

Get one model by name.

Source

pub async fn add_model(&self, model: &Model) -> Result<bool>

Add a model.

Source

pub async fn update_model(&self, model: &Model) -> Result<bool>

Update a model.

Source

pub async fn delete_model(&self, model: &Model) -> Result<bool>

Delete a model.

Source§

impl Client

Source

pub async fn send_notification( &self, content: &str, recipient: &str, ) -> Result<()>

Send a notification with the notification provider of the organization. recipient can be empty to use the default recipient of the provider.

Source§

impl Client

Source

pub async fn get_orders(&self) -> Result<Vec<Order>>

Get the orders of the client’s organization.

Source

pub async fn get_pagination_orders( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Order>, i32)>

Get one page of the orders of the client’s organization, together with the total number of the orders.

Source

pub async fn get_user_orders(&self, user_name: &str) -> Result<Vec<Order>>

Get the orders of one user.

Source

pub async fn get_order(&self, name: &str) -> Result<Option<Order>>

Get one order by name.

Source

pub async fn add_order(&self, order: &Order) -> Result<bool>

Add an order.

Source

pub async fn update_order(&self, order: &Order) -> Result<bool>

Update an order.

Source

pub async fn delete_order(&self, order: &Order) -> Result<bool>

Delete an order.

Source

pub async fn cancel_order(&self, name: &str) -> Result<bool>

Cancel an order by name.

Source§

impl Client

Source

pub async fn place_order( &self, product_infos: &[ProductInfo], user_name: &str, ) -> Result<Order>

Place an order for the given products. user_name can be empty to place the order for the user that the client is authenticated as.

Source

pub async fn pay_order( &self, order_name: &str, provider_name: &str, ) -> Result<Payment>

Pay an order with a payment provider, the returned payment holds the pay_url the user has to be redirected to.

Source

pub async fn buy_product(&self, name: &str, user_name: &str) -> Result<Order>

Place an order of one product, kept for compatibility with the old buy-product API.

Source§

impl Client

Source

pub async fn get_organization(&self, name: &str) -> Result<Option<Organization>>

Get one organization by name.

Source

pub async fn get_organizations(&self) -> Result<Vec<Organization>>

Get all the organizations.

Source

pub async fn get_organization_names(&self) -> Result<Vec<Organization>>

Get all the organizations, with only their names filled in.

Source

pub async fn add_organization( &self, organization: &Organization, ) -> Result<bool>

Add an organization.

Source

pub async fn update_organization( &self, organization: &Organization, ) -> Result<bool>

Update an organization.

Source

pub async fn delete_organization( &self, organization: &Organization, ) -> Result<bool>

Delete an organization.

Source§

impl Client

Source

pub async fn get_payments(&self) -> Result<Vec<Payment>>

Get the payments of the client’s organization.

Source

pub async fn get_pagination_payments( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Payment>, i32)>

Get one page of the payments of the client’s organization, together with the total number of the payments.

Source

pub async fn get_payment(&self, name: &str) -> Result<Option<Payment>>

Get one payment by name.

Source

pub async fn get_user_payments(&self, user_name: &str) -> Result<Vec<Payment>>

Get the payments of one user.

Source

pub async fn add_payment(&self, payment: &Payment) -> Result<bool>

Add a payment.

Source

pub async fn update_payment(&self, payment: &Payment) -> Result<bool>

Update a payment.

Source

pub async fn delete_payment(&self, payment: &Payment) -> Result<bool>

Delete a payment.

Source

pub async fn notify_payment(&self, payment: &Payment) -> Result<bool>

Notify Casdoor that a payment was made, so that it queries the payment provider and updates the state of the payment.

Source

pub async fn invoice_payment(&self, payment: &Payment) -> Result<bool>

Ask the payment provider to issue the invoice of a payment.

Source§

impl Client

Source

pub async fn get_permissions(&self) -> Result<Vec<Permission>>

Get the permissions of the client’s organization.

Source

pub async fn get_permissions_by_role( &self, name: &str, ) -> Result<Vec<Permission>>

Get the permissions of a role.

Source

pub async fn get_pagination_permissions( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Permission>, i32)>

Get one page of the permissions of the client’s organization, together with the total number of the permissions.

Source

pub async fn get_permission(&self, name: &str) -> Result<Option<Permission>>

Get one permission by name.

Source

pub async fn add_permission(&self, permission: &Permission) -> Result<bool>

Add a permission.

Source

pub async fn update_permission(&self, permission: &Permission) -> Result<bool>

Update a permission.

Source

pub async fn update_permission_for_columns( &self, permission: &Permission, columns: &[&str], ) -> Result<bool>

Update only the given columns of a permission.

Source

pub async fn delete_permission(&self, permission: &Permission) -> Result<bool>

Delete a permission.

Source§

impl Client

Source

pub async fn get_plans(&self) -> Result<Vec<Plan>>

Get the plans of the client’s organization.

Source

pub async fn get_pagination_plans( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Plan>, i32)>

Get one page of the plans of the client’s organization, together with the total number of the plans.

Source

pub async fn get_plan(&self, name: &str) -> Result<Option<Plan>>

Get one plan by name.

Source

pub async fn add_plan(&self, plan: &Plan) -> Result<bool>

Add a plan.

Source

pub async fn update_plan(&self, plan: &Plan) -> Result<bool>

Update a plan.

Source

pub async fn delete_plan(&self, plan: &Plan) -> Result<bool>

Delete a plan.

Source§

impl Client

Source

pub async fn get_policies( &self, enforcer_name: &str, adapter_id: &str, ) -> Result<Vec<CasbinRule>>

Get the policies of an enforcer. adapter_id can be empty to use the adapter of the enforcer.

Source

pub async fn get_filtered_policies( &self, enforcer_id: &str, filters: &[PolicyFilter], ) -> Result<Vec<CasbinRule>>

Get the policies of an enforcer, filtered by the field index and the field values.

Source

pub async fn add_policy( &self, enforcer: &Enforcer, policy: &CasbinRule, ) -> Result<bool>

Add one policy to an enforcer.

Source

pub async fn update_policy( &self, enforcer: &Enforcer, old_policy: &CasbinRule, new_policy: &CasbinRule, ) -> Result<bool>

Update one policy of an enforcer.

Source

pub async fn remove_policy( &self, enforcer: &Enforcer, policy: &CasbinRule, ) -> Result<bool>

Remove one policy from an enforcer.

Source§

impl Client

Source

pub async fn get_pricings(&self) -> Result<Vec<Pricing>>

Get the pricings of the client’s organization.

Source

pub async fn get_pagination_pricings( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Pricing>, i32)>

Get one page of the pricings of the client’s organization, together with the total number of the pricings.

Source

pub async fn get_pricing(&self, name: &str) -> Result<Option<Pricing>>

Get one pricing by name.

Source

pub async fn add_pricing(&self, pricing: &Pricing) -> Result<bool>

Add a pricing.

Source

pub async fn update_pricing(&self, pricing: &Pricing) -> Result<bool>

Update a pricing.

Source

pub async fn delete_pricing(&self, pricing: &Pricing) -> Result<bool>

Delete a pricing.

Source§

impl Client

Source

pub async fn get_products(&self) -> Result<Vec<Product>>

Get the products of the client’s organization.

Source

pub async fn get_pagination_products( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Product>, i32)>

Get one page of the products of the client’s organization, together with the total number of the products.

Source

pub async fn get_product(&self, name: &str) -> Result<Option<Product>>

Get one product by name.

Source

pub async fn add_product(&self, product: &Product) -> Result<bool>

Add a product.

Source

pub async fn update_product(&self, product: &Product) -> Result<bool>

Update a product.

Source

pub async fn delete_product(&self, product: &Product) -> Result<bool>

Delete a product.

Source§

impl Client

Source

pub async fn get_providers(&self) -> Result<Vec<Provider>>

Get the providers of the client’s organization.

Source

pub async fn get_provider(&self, name: &str) -> Result<Option<Provider>>

Get one provider by name.

Source

pub async fn get_pagination_providers( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Provider>, i32)>

Get one page of the providers of the client’s organization, together with the total number of the providers.

Source

pub async fn add_provider(&self, provider: &Provider) -> Result<bool>

Add a provider.

Source

pub async fn update_provider(&self, provider: &Provider) -> Result<bool>

Update a provider.

Source

pub async fn delete_provider(&self, provider: &Provider) -> Result<bool>

Delete a provider.

Source§

impl Client

Source

pub async fn get_records(&self) -> Result<Vec<Record>>

Get the records of the client’s organization.

Source

pub async fn get_pagination_records( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Record>, i32)>

Get one page of the records of the client’s organization, together with the total number of the records.

Source

pub async fn get_record(&self, name: &str) -> Result<Option<Record>>

Get one record by name, None if it doesn’t exist. Casdoor has no API to get a single record, so it searches the records by name. Like the other APIs that read records, it needs the access token of an admin user, see Client::with_access_token().

Source

pub async fn add_record(&self, record: &Record) -> Result<bool>

Add a record.

Source§

impl Client

Source

pub async fn get_resource(&self, id: &str) -> Result<Option<Resource>>

Get one resource by its owner/name ID.

Source

pub async fn get_resource_ex( &self, owner: &str, name: &str, ) -> Result<Option<Resource>>

Get one resource by its owner and name.

Source

pub async fn get_resources( &self, owner: &str, user: &str, field: &str, value: &str, sort_field: &str, sort_order: &str, ) -> Result<Vec<Resource>>

Get the resources that match the given filters.

Source

pub async fn get_pagination_resources( &self, owner: &str, user: &str, field: &str, value: &str, page_size: i32, page: i32, sort_field: &str, sort_order: &str, ) -> Result<Vec<Resource>>

Get one page of the resources that match the given filters.

Source

pub async fn upload_resource( &self, user: &str, tag: &str, parent: &str, full_file_path: &str, file_bytes: &[u8], ) -> Result<(String, String)>

Upload a file to Casdoor, the returned values are the URL and the name of the created resource.

Source

pub async fn upload_resource_ex( &self, user: &str, tag: &str, parent: &str, full_file_path: &str, file_bytes: &[u8], created_time: &str, description: &str, ) -> Result<(String, String)>

Like Client::upload_resource(), but also sets the created time and the description of the resource.

Source

pub async fn add_resource(&self, resource: &Resource) -> Result<bool>

Add a resource.

Source

pub async fn update_resource(&self, resource: &Resource) -> Result<bool>

Update a resource.

Source

pub async fn delete_resource(&self, resource: &Resource) -> Result<bool>

Delete a resource.

Source

pub async fn delete_resource_with_tag( &self, resource: &Resource, tag: &str, ) -> Result<bool>

Delete a resource that has the given tag.

Source§

impl Client

Source

pub async fn get_roles(&self) -> Result<Vec<Role>>

Get the roles of the client’s organization.

Source

pub async fn get_pagination_roles( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Role>, i32)>

Get one page of the roles of the client’s organization, together with the total number of the roles.

Source

pub async fn get_role(&self, name: &str) -> Result<Option<Role>>

Get one role by name.

Source

pub async fn add_role(&self, role: &Role) -> Result<bool>

Add a role.

Source

pub async fn update_role(&self, role: &Role) -> Result<bool>

Update a role.

Source

pub async fn update_role_for_columns( &self, role: &Role, columns: &[&str], ) -> Result<bool>

Update only the given columns of a role.

Source

pub async fn delete_role(&self, role: &Role) -> Result<bool>

Delete a role.

Source§

impl Client

Source

pub async fn get_sessions(&self) -> Result<Vec<Session>>

Get the sessions of the client’s organization.

Source

pub async fn get_pagination_sessions( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Session>, i32)>

Get one page of the sessions of the client’s organization, together with the total number of the sessions.

Source

pub async fn get_session( &self, name: &str, application: &str, ) -> Result<Option<Session>>

Get the session of a user in an application.

Source

pub async fn add_session(&self, session: &Session) -> Result<bool>

Add a session.

Source

pub async fn update_session(&self, session: &Session) -> Result<bool>

Update a session.

Source

pub async fn update_session_for_columns( &self, session: &Session, columns: &[&str], ) -> Result<bool>

Update only the given columns of a session.

Source

pub async fn delete_session(&self, session: &Session) -> Result<bool>

Delete a session.

Source§

impl Client

Source

pub async fn send_sms(&self, content: &str, receivers: &[&str]) -> Result<()>

Send an SMS with the default SMS provider of the organization.

Source

pub async fn send_sms_by_provider( &self, content: &str, provider: &str, receivers: &[&str], ) -> Result<()>

Send an SMS with the given SMS provider.

Source§

impl Client

Source

pub async fn get_subscriptions(&self) -> Result<Vec<Subscription>>

Get the subscriptions of the client’s organization.

Source

pub async fn get_pagination_subscriptions( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Subscription>, i32)>

Get one page of the subscriptions of the client’s organization, together with the total number of the subscriptions.

Source

pub async fn get_subscription(&self, name: &str) -> Result<Option<Subscription>>

Get one subscription by name.

Source

pub async fn add_subscription( &self, subscription: &Subscription, ) -> Result<bool>

Add a subscription.

Source

pub async fn update_subscription( &self, subscription: &Subscription, ) -> Result<bool>

Update a subscription.

Source

pub async fn delete_subscription( &self, subscription: &Subscription, ) -> Result<bool>

Delete a subscription.

Source§

impl Client

Source

pub async fn get_syncers(&self) -> Result<Vec<Syncer>>

Get the syncers of the client’s organization.

Source

pub async fn get_pagination_syncers( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Syncer>, i32)>

Get one page of the syncers of the client’s organization, together with the total number of the syncers.

Source

pub async fn get_syncer(&self, name: &str) -> Result<Option<Syncer>>

Get one syncer by name.

Source

pub async fn add_syncer(&self, syncer: &Syncer) -> Result<bool>

Add a syncer.

Source

pub async fn update_syncer(&self, syncer: &Syncer) -> Result<bool>

Update a syncer.

Source

pub async fn delete_syncer(&self, syncer: &Syncer) -> Result<bool>

Delete a syncer.

Source§

impl Client

Source

pub async fn get_tokens(&self) -> Result<Vec<Token>>

Get all the tokens.

Source

pub async fn get_pagination_tokens( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Token>, i32)>

Get one page of the tokens, together with the total number of the tokens.

Source

pub async fn get_token(&self, name: &str) -> Result<Option<Token>>

Get one token by name.

Source

pub async fn add_token(&self, token: &Token) -> Result<bool>

Add a token.

Source

pub async fn update_token(&self, token: &Token) -> Result<bool>

Update a token.

Source

pub async fn update_token_for_columns( &self, token: &Token, columns: &[&str], ) -> Result<bool>

Update only the given columns of a token.

Source

pub async fn delete_token(&self, token: &Token) -> Result<bool>

Delete a token.

Source

pub async fn introspect_token( &self, token: &str, token_type_hint: &str, ) -> Result<IntrospectTokenResult>

Introspect an access token or a refresh token, token_type_hint is "access_token" or "refresh_token".

Source§

impl Client

Source

pub async fn get_transactions(&self) -> Result<Vec<Transaction>>

Get the transactions of the client’s organization.

Source

pub async fn get_pagination_transactions( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Transaction>, i32)>

Get one page of the transactions of the client’s organization, together with the total number of the transactions.

Source

pub async fn get_transaction(&self, name: &str) -> Result<Option<Transaction>>

Get one transaction by name.

Source

pub async fn get_user_transactions( &self, user_name: &str, ) -> Result<Vec<Transaction>>

Get the transactions of one user.

Source

pub async fn add_transaction( &self, transaction: &Transaction, ) -> Result<(bool, String)>

Add a transaction, the returned string is the ID of the created transaction.

Source

pub async fn add_transaction_with_dry_run( &self, transaction: &Transaction, dry_run: bool, ) -> Result<(bool, String)>

Add a transaction, or only check whether it would succeed when dry_run is true.

Source

pub async fn update_transaction( &self, transaction: &Transaction, ) -> Result<bool>

Update a transaction.

Source

pub async fn delete_transaction( &self, transaction: &Transaction, ) -> Result<bool>

Delete a transaction.

Source§

impl Client

Source

pub fn get_signup_url( &self, enable_password: bool, redirect_uri: &str, ) -> String

Return the URL of the Casdoor sign-up page. redirect_uri can be empty when enable_password is true, since only the password based sign-up page is needed then.

Source

pub fn get_signin_url(&self, redirect_uri: &str) -> String

Return the URL of the Casdoor sign-in page, the user is redirected to redirect_uri with an authorization code after signing in.

Source

pub fn get_user_profile_url( &self, user_name: &str, access_token: Option<&str>, ) -> String

Return the URL of a user’s profile page.

Source

pub fn get_my_profile_url(&self, access_token: Option<&str>) -> String

Return the URL of the account page of the user who owns the access token.

Source§

impl Client

Source

pub async fn get_global_users(&self) -> Result<Vec<User>>

Get the users of all the organizations.

Source

pub async fn get_users(&self) -> Result<Vec<User>>

Get the users of the client’s organization.

Source

pub async fn get_sorted_users( &self, sorter: &str, limit: i32, ) -> Result<Vec<User>>

Get the users of the client’s organization, sorted by sorter and limited to limit results.

Source

pub async fn get_pagination_users( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<User>, i32)>

Get one page of the users of the client’s organization, together with the total number of the users.

Source

pub async fn get_user_count(&self, is_online: &str) -> Result<i32>

Get the number of the users of the client’s organization. is_online can be "" for all the users, "1" for the online ones and "0" for the offline ones.

Source

pub async fn get_user(&self, name: &str) -> Result<Option<User>>

Get one user by name, or by the owner/name ID for a user of another organization.

Source

pub async fn get_account(&self) -> Result<Option<User>>

Get the user that the client is authenticated as, by calling the /api/get-account API. It’s meant to be used with a client returned by Client::with_access_token(), so that the owner of an access token can be retrieved.

Source

pub async fn get_user_by_email(&self, email: &str) -> Result<Option<User>>

Get one user of the client’s organization by email.

Source

pub async fn get_user_by_phone(&self, phone: &str) -> Result<Option<User>>

Get one user of the client’s organization by phone.

Source

pub async fn get_user_by_user_id(&self, user_id: &str) -> Result<Option<User>>

Get one user of the client’s organization by the user’s id field.

Source

pub async fn set_password( &self, owner: &str, name: &str, old_password: &str, new_password: &str, ) -> Result<bool>

Set the password of a user. old_password is not required, just pass an empty string when you don’t need it.

Source

pub async fn add_user(&self, user: &User) -> Result<bool>

Add a user.

Source

pub async fn update_user(&self, user: &User) -> Result<bool>

Update a user.

Source

pub async fn update_user_for_columns( &self, user: &User, columns: &[&str], ) -> Result<bool>

Update only the given columns of a user.

Source

pub async fn update_user_by_id(&self, id: &str, user: &User) -> Result<bool>

Update the user addressed by the given owner/name ID.

Source

pub async fn update_user_by_user_id( &self, owner: &str, user_id: &str, user: &User, ) -> Result<bool>

Update the user of owner whose id field is user_id.

Source

pub async fn delete_user(&self, user: &User) -> Result<bool>

Delete a user.

Source

pub async fn check_user_password(&self, user: &User) -> Result<bool>

Check whether the password field of the given user is the user’s password.

Source§

impl Client

Source

pub async fn get_webhooks(&self) -> Result<Vec<Webhook>>

Get the webhooks of the client’s organization.

Source

pub async fn get_pagination_webhooks( &self, p: i32, page_size: i32, query: &[(&str, &str)], ) -> Result<(Vec<Webhook>, i32)>

Get one page of the webhooks of the client’s organization, together with the total number of the webhooks.

Source

pub async fn get_webhook(&self, name: &str) -> Result<Option<Webhook>>

Get one webhook by name.

Source

pub async fn add_webhook(&self, webhook: &Webhook) -> Result<bool>

Add a webhook.

Source

pub async fn update_webhook(&self, webhook: &Webhook) -> Result<bool>

Update a webhook.

Source

pub async fn delete_webhook(&self, webhook: &Webhook) -> Result<bool>

Delete a webhook.

Trait Implementations§

Source§

impl Clone for Client

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Client

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more