承接 codemonster-ru/auth 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

codemonster-ru/auth

最新稳定版本:v1.0.0

Composer 安装命令:

composer require codemonster-ru/auth

包简介

Framework-agnostic authentication primitives for Annabel applications.

README 文档

README

Framework-agnostic authentication primitives for Annabel applications.

Installation

composer require codemonster-ru/auth

Concepts

  • AuthenticatableInterface describes a user object.
  • UserProviderInterface retrieves and validates users.
  • PasswordHasherInterface hashes and verifies passwords.
  • AuthorizerInterface checks abilities and policies.
  • SessionGuard stores the authenticated user id in codemonster-ru/session.
  • Authenticate middleware rejects guests with 401 or redirects them.
  • Authorize middleware rejects requests that fail a gate ability check.

Example

use Codemonster\Auth\Guards\SessionGuard;
use Codemonster\Auth\Hashing\NativePasswordHasher;
use Codemonster\Auth\Providers\ArrayUserProvider;

$hasher = new NativePasswordHasher();
$provider = new ArrayUserProvider([
    new User(1, 'admin@example.com', $hasher->make('secret')),
], $hasher);

$guard = new SessionGuard($provider, session());

if ($guard->attempt(['email' => 'admin@example.com', 'password' => 'secret'])) {
    echo $guard->id(); // 1
}

$guard->logout(); // Invalidates the session by default.

ArrayUserProvider is intentionally small. Production applications can provide their own database-backed implementation of UserProviderInterface.

Authorization

use Codemonster\Auth\Authorization\Gate;

$gate = new Gate($guard);
$gate->define('posts.update', fn($user, $post) => $user?->getAuthIdentifier() === $post->owner_id);

if ($gate->allows('posts.update', $post)) {
    // ...
}

In Annabel routes, the can middleware alias can read route parameters exposed by the HTTP kernel:

router()
    ->get('/posts/{post}', [PostController::class, 'show'])
    ->middleware('can:posts.view,post');

Database users

DatabaseUserProvider retrieves users through codemonster-ru/database's ConnectionInterface:

use Codemonster\Auth\Database\DatabaseUserProvider;

$provider = new DatabaseUserProvider(
    db(),
    new NativePasswordHasher(),
    table: 'users',
    identifierColumn: 'id',
    passwordColumn: 'password',
    credentialKey: 'email',
);

Annabel integration

codemonster-ru/annabel registers the auth services through AuthServiceProvider. Applications can use auth() and user() helpers, and protect routes with Codemonster\Auth\Middleware\Authenticate and Codemonster\Auth\Middleware\Authorize.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固