Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/casdoor/casdoor-php-sdk

PHP client SDK for Casdoor
https://github.com/casdoor/casdoor-php-sdk

auth authentication authn casdoor oauth oidc php saml sso

Last synced: about 1 month ago
JSON representation

PHP client SDK for Casdoor

Awesome Lists containing this project

README

        

# casdoor-php-sdk

[![Latest Stable Version](http://poser.pugx.org/casdoor/casdoor-php-sdk/v)](https://packagist.org/packages/casdoor/casdoor-php-sdk) [![Total Downloads](http://poser.pugx.org/casdoor/casdoor-php-sdk/downloads)](https://packagist.org/packages/casdoor/casdoor-php-sdk) [![Latest Unstable Version](http://poser.pugx.org/casdoor/casdoor-php-sdk/v/unstable)](https://packagist.org/packages/casdoor/casdoor-php-sdk) [![License](http://poser.pugx.org/casdoor/casdoor-php-sdk/license)](https://packagist.org/packages/casdoor/casdoor-php-sdk) [![PHP Version Require](http://poser.pugx.org/casdoor/casdoor-php-sdk/require/php)](https://packagist.org/packages/casdoor/casdoor-php-sdk)

Casdoor PHP SDK will allow you to easily connect your application to Casdoor authentication system without having to start from scratch.

# Step 1: Composer install casdoor-php-sdk

In your php application directory, run the following command:

```
composer require casdoor/casdoor-php-sdk
```

Or use composer.json to add the following code:

```
{
"require": {
"vendor/package": "*",
}
}
```

Then run composer install to make it take effect.
Create a OauthTest. Php file and import the SDK package.

```php
initConfig();
$token = new Token();
$accessToken = $token->getOAuthToken($this->code, $this->state);
$this->assertIsString($accessToken->getToken());
}
```

The JWT token represents the user's identity and has the right to call relevant APIs.

# Step 4: verify and parse the user token

When a user passes in a JWT token, testParseJwtToken function calls the public key to verify the JWT token. If the verification is passed, the Array object is returned, which contains the account information of the user.

```php
public function testParseJwtToken()
{
$this->initConfig();
$token = "eyJhxxxx"; // from testGetOauthToken()
$jwt = new Jwt();
$result = $jwt->parseJwtToken($token, User::$authConfig);
$this->assertIsArray();
}
```

# Step 5: update user information

testModifyUser call the application configuration (non-user token) as the update permission to perform CURD operations on user information.

```php
public function testModifyUser()
{
$this->initConfig();
$user = new User();

# Delete User
$user->name = 'user_hn99qa';
$response = $user->deleteUser($user);
$this->assertTrue($response);

# Add User
$response = $user->addUser($user);
$this->assertTrue($response);

# Update User
$user->phone = 'phone';
$user->displayName = 'display name';
$response = $user->updateUser($user);
$this->assertTrue($response);
}
```

# Others: User interaction

- User::getUser() , obtain User information by User name
- User::getUsers() to obtain information about all users.
- User::getUserCount() to obtain the current number of users.