Download the PHP package casdoor/casdoor-php-sdk without Composer

On this page you can find all versions of the php package casdoor/casdoor-php-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package casdoor-php-sdk

Casdoor PHP SDK

semantic-release GitHub Workflow Status (branch) GitHub Release Latest Stable Version Total Downloads PHP Version Require

license GitHub issues GitHub stars GitHub forks Casdoor

Casdoor PHP SDK is the official PHP client library for Casdoor. It lets your PHP backend (Laravel, Symfony, plain PHP, ...) sign users in with Casdoor (OAuth 2.0 / OIDC), verify the JWT tokens issued by Casdoor, and manage users, organizations, applications, roles, permissions and all the other Casdoor objects through the Casdoor APIs.

The SDK has the same features as casdoor-go-sdk.

📋 Table of Contents

✨ Features

📦 Installation

🚀 Quick Start

⚙️ Configuration

Configuration Parameters

Parameter Required Description
endpoint Yes Casdoor server URL, such as http://localhost:8000
clientId Yes Client ID of the Casdoor application
clientSecret Yes Client secret of the Casdoor application
certificate Yes x509 certificate (PEM) of the application's cert, used to verify JWT tokens
organizationName Yes Name of the Casdoor organization
applicationName Yes Name of the Casdoor application
customHeaders No HTTP headers added to all the API requests, e.g. ['Accept-Language' => 'de']

Getting the Configuration from Casdoor

  1. endpoint: the URL of your Casdoor server
  2. clientId and clientSecret: the application's edit page in the Casdoor admin panel
  3. certificate: the certificate of the cert selected in the application's "Cert" field (Certs page → the cert → "Certificate")
  4. organizationName: the organization that owns your users
  5. applicationName: the name of your application

Custom HTTP Headers

The Authorization header is always managed by the SDK.

Return Values and Errors

🔐 Authentication

OAuth 2.0 Flow

Step 1: Redirect the User to Casdoor

getSignupUrl($enablePassword, $redirectUri), getUserProfileUrl($userName, $accessToken) and getMyProfileUrl($accessToken) build the URLs of the other Casdoor pages.

Step 2: Handle the Callback

Casdoor redirects back to your application with code and state. Exchange the code for the tokens and verify the access token:

getOAuthToken() returns a league/oauth2-client AccessToken. parseJwtToken() verifies the signature and the expiration of the token with the certificate, and throws an exception when the token is invalid.

Password Grant, Impersonation and Token Refresh

Calling APIs With the User's Access Token

By default, the SDK calls the Casdoor APIs as the application itself: it authenticates with the client ID and client secret, so the calls have the application's (admin) permissions.

To call the APIs on behalf of the signed-in user instead, use withAccessToken() with the user's access token. It returns a new client that sends the Authorization: Bearer <access_token> header, so Casdoor treats the requests as being made by that user and the user's own permissions apply:

The original client is not changed, so it's safe to create one such client per incoming HTTP request.

Note: a non-admin user can only access their own data. If an API throws a permission error, the user simply isn't allowed to call it — use the application's client (without withAccessToken()) for admin operations.

Logout

📦 Resource Management

Object Owner

Every object in Casdoor is identified by an ID of the form owner/name, where the owner is an organization (role, group, user, product, ldap, ...) or the built-in admin owner (organization, application, token).

By default the SDK fills in the owner for you: the organizationName of the client, or admin for the object types listed above. You can address an object in another organization by passing a qualified owner/name ID instead of a plain name, and by setting the owner field explicitly when creating or updating an object:

[!IMPORTANT] Behavior change: addXxx(), updateXxx() and deleteXxx() used to overwrite the owner field of the object with the client's organization, and to ignore any owner set by the caller. They now only fill owner in when it is empty. If your code sets owner to a value other than the client's organization (for example the literal 'admin'), the request is now sent to that owner instead of being silently redirected, so clear the field or set it to the intended organization.

Method Patterns

Most objects have the same methods:

Users

Permissions and Enforcement

Enforcers and Policies

Billing: Products, Orders, Payments and Transactions

Email, SMS and Notifications

Resources (File Upload)

LDAP

Multi-Factor Authentication

📚 API Reference

Object Methods
Auth getOAuthToken, getOAuthTokenByPassword, impersonateUser, refreshOAuthToken, introspectToken, parseJwtToken, logout, logoutCurrentSession, withAccessToken, getAccount
URL getSigninUrl, getSignupUrl, getUserProfileUrl, getMyProfileUrl
User CRUD + pagination, getUserByEmail, getUserByPhone, getUserByUserId, getSortedUsers, getGlobalUsers, getUserCount, updateUserForColumns, updateUserById, updateUserByUserId, checkUserPassword, setPassword
Organization CRUD, getOrganizationNames
Application CRUD, getOrganizationApplications
Group CRUD + pagination
Cert CRUD, getGlobalCerts
Provider CRUD + pagination
Role CRUD + pagination, updateRoleForColumns
Permission CRUD + pagination, updatePermissionForColumns, getPermissionsByRole
Model / Adapter / Enforcer CRUD + pagination
Policy getPolicies, getFilteredPolicies, addPolicy, updatePolicy, removePolicy
Enforce enforce, batchEnforce
Session CRUD + pagination, updateSessionForColumns
Token CRUD + pagination, updateTokenForColumns, introspectToken
Product CRUD + pagination
Order CRUD + pagination, getUserOrders, placeOrder, payOrder, buyProduct, cancelOrder
Payment CRUD + pagination, getUserPayments, notifyPayment, invoicePayment
Plan / Pricing / Subscription CRUD + pagination
Transaction CRUD + pagination, getUserTransactions, addTransactionWithDryRun
Invitation CRUD + pagination, updateInvitationForColumns, getInvitationInfo
LDAP CRUD, getLdapUsers, syncLdapUsers, syncLdapUsersFromServer
Syncer / Webhook CRUD + pagination
Resource getResources, getPaginationResources, getResource, getResourceEx, addResource, updateResource, uploadResource, uploadResourceEx, deleteResource, deleteResourceWithTag
Record getRecords, getPaginationRecords, getRecord, addRecord
Email / SMS / Notification sendEmail, sendEmailByProvider, sendSms, sendSmsByProvider, sendNotification
MFA initiate, verify, enable, setPreferred, delete
Low-level getUrl, doGetResponse, doGetBytes, doGetBytesRaw, doPost, doPostBytesRaw to call any other Casdoor API

💡 Examples

🛠 Development

The tests run against a real Casdoor server. CI starts one with Docker and the data in .ci/casdoor/init_data.json:

Set CASDOOR_TEST_ENDPOINT, CASDOOR_TEST_CLIENT_ID, CASDOOR_TEST_CLIENT_SECRET, CASDOOR_TEST_ORGANIZATION and CASDOOR_TEST_APPLICATION to run the tests against another server.

Releases are tagged automatically by semantic-release when commits are pushed to master, and Packagist picks up the tags.

📖 Documentation

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


All versions of casdoor-php-sdk with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
guzzlehttp/guzzle Version ^7.3
league/oauth2-client Version ^2.6
firebase/php-jwt Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package casdoor/casdoor-php-sdk contains the following files

Loading the files please wait ...