PHP code example of casdoor / casdoor-php-sdk

1. Go to this page and download the library: Download casdoor/casdoor-php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

casdoor / casdoor-php-sdk example snippets




namespace Casdoor\Tests;

use PHPUnit\Framework\TestCase;
use Casdoor\Auth\Jwt;
use Casdoor\Auth\Token;
use Casdoor\Auth\User;

class OauthTest extends TestCase
{
  public function xxx(){}
}

public function initConfig()
  {
    $endpoint = 'http://127.0.0.1:8000';
    $clientId = 'c64b12723aefb65a88ce';
    $clientSecret = 'c0c9d483a87332751b2564635765d71c9f6a2e83';
    $certificate = file_get_contents(dirname(__FILE__) . '/public_key.pem');
    $organizationName = 'built-in';
    $applicationName = 'testApp';
    User::initConfig($endpoint, $clientId, $clientSecret, $certificate, $organizationName, $applicationName);
  }

public $code = "cc78dc9953ca6ae6ab58";
public $state = "casdoor";
public function testGetOauthToken()
{
    $this->initConfig();
    $token = new Token();
    $accessToken = $token->getOAuthToken($this->code, $this->state);
    $this->assertIsString($accessToken->getToken());
}

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

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);
}

composer