定制 gathern/casdoor-api 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gathern/casdoor-api

最新稳定版本:v0.5.3

Composer 安装命令:

composer require gathern/casdoor-api

包简介

A skeleton repository for my packages

README 文档

README

This package provides a wonderful Casdoor-api integration for PHP projects.

Requires PHP 8.1+

Installation

You can install the package via composer:

composer require gathern/casdoor-api

Usage

$connector = new \Gathern\CasdoorAPI\CasdoorConnector();

Available Endpoints

User API

// Create a new user
$response = $connector->userApi()->apiControllerAddUser(
    name: 'username'
);

// Update user password
$response = $connector->userApi()->apiControllerSetUserPassword(
    userName: 'username',
    newPassword: 'new_password'
);

Login API

// Login with username and password
$response = $connector->loginApi()->apiControllerLogin(
    application: 'your-app-name',
    username: 'username',
    signinMethod: \Gathern\CasdoorAPI\Enum\SignInMethod::PASSWORD,
    password: 'password'
);

// Get JWT token using client credentials
$response = $connector->TokenApi()->apiControllerGetOauthToken(
    clientId: 'your-client-id',
    clientSecret: 'your-client-secret',
    grantType: \Gathern\CasdoorAPI\Enum\GrantType::CLIENT_CREDENTIALS
);

Role API

// Get all roles
$response = $connector->roleApi()->apiControllerGetRoles();

// Get role details
$response = $connector->roleApi()->apiControllerGetRole(id: 'role-name');

// Add a new role
$response = $connector->roleApi()->apiControllerAddRole(
    name: 'new-role',
    displayName: 'New Role'
);

// Update a role
$response = $connector->roleApi()->apiControllerUpdateRole(
    id: 'role-name',
    displayName: 'Updated Role Name'
);

// Update role from role data object
$roleDetails = $connector->roleApi()->apiControllerGetRole(id: 'role-name')->dto();
$response = $connector->roleApi()->apiControllerUpdateRoleFromRoleData(
    $roleDetails->data,
    displayName: 'Updated Role Name'
);

Group API

// Get all groups
$response = $connector->groupApi()->apiControllerGetGroups('organization-name');

// Get group details
$response = $connector->groupApi()->apiControllerGetGroup(id: 'group-name');

// Add a new group
$response = $connector->groupApi()->apiControllerAddGroup(
    name: 'new-group'
);

// Update a group
$response = $connector->groupApi()->apiControllerUpdateGroup(
    id: 'group-name',
    name: 'updated-group-name'
);

Handling Responses

All API methods return a response object with the following methods:

// Get the response as a DTO
$responseDto = $response->dto();

// Check the status of the response
if ($responseDto->status === \Gathern\CasdoorAPI\Enum\ResponseStatus::OK) {
    // Success
    $data = $responseDto->data;
} else {
    // Error
    $errorMessage = $responseDto->msg;
}

🧹 Keep a modern codebase with Pint:

composer lint

✅ Run refactors using Rector

composer refacto

⚗️ Run static analysis using PHPStan:

composer test:types

✅ Run unit tests using PEST

composer test:unit

🚀 Run the entire test suite:

composer test

统计信息

  • 总下载量: 208
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-02