承接 acidjazz/humble 相关项目开发

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

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

acidjazz/humble

Composer 安装命令:

composer require acidjazz/humble

包简介

passwordless authentication and detailed sessioning for laravel

README 文档

README

Ideal Sessioning and authentication for Laravel

Packagist License Latest Stable Version Total Downloads

Features

  • Passwordless authentication
    • Ability to store and compare a cookie, securing the magic link sent out
    • Link expiration
    • Able to store "action" objects passed through for completing tasks the user was doing before prompted
  • Detailed sessions using whichbrowser
"device": {
  "string": "Chrome 68 on a Google Pixel 2 XL running Android 9",
  "platform": "Android 9",
  "browser": "Chrome 68",
  "name": "Google Pixel 2 XL",
  "desktop": false,
  "mobile": true
}
"location": {
  "ip": "86.222.88.167",
  "country": "France",
  "city": "Lons",
  "state": "NAQ",
  "postal_code": "64140",
  "lat": 43.3167,
  "lon": -0.4,
  "timezone": "Europe\/Paris",
  "currency": "EUR"
}

Installation

Install humble with composer:

composer require acidjazz/humble

Add Humble's trait to your user model:

use Fumeapp\Humble\Traits\Humble;
...
class User extends Authenticatable
{
  use Humble, Notifiable;
}

Publish Humble's migrations (sessions table)

php artisan vendor:publish --tag="humble.migrations"

Run the migration

php artisan migrate

Change your guard in your config, to the 'humble' guard in config/auth.php, in my case since I mainly use Laravel as an API

    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        'api' => [
            'driver' => 'humble',
            'provider' => 'users',
        ],
    ],

Check your defaults as well, if it's not api, you'll need to change that

If your user class is not App\Models\User, we need to tell humble what it is:

Publish Humble's configuration

 php artisan vendor:publish --tag="humble.config"

Modify config/humble.php and specify your user class

Usage

Humble is similar to Laravel Sanctum in the way you can also assign abilties to sessions.

Primarily humble sessions are stored for user sessions which by default would inherit all session abilities. You can also think of Humble Session as Personal Access Tokens, inside your application your users could create multiple session tokens for various services and integrations like: GitHub actions, CLI Applications, Slack Tokens, etc...

With these addtional session tokens your users can create, you still have access to the session source where you can attach certain Gates & Policy behaviors based on that. If your are fine with leaving these session tokens as-is with same access as the user you can stick with that. If you need more granularity you can also assign abilites.

With abilites you can addtionally set specific rules these session tokens can have. For example you might want to have a session tokens for a GitHub action that only has the abilty to peform READ events and not WRITE.

These abilites can be user defined in your app, meaing its up to you to declare these rules in your app and check/valdiate them. The default ability is set to ["*"] which means full access, but when creating a session you can pass a parameter to only set this to READ, and which your database record would show as ["READ"]

For valdiating these abilites we provide a few helpers and middlewares to make this easier.

To validate the middleware level you first need to add the following to your $routeMiddleware inside of app/Http/Kernel.php

// ...
'abilities' => \Fumeapp\Humble\Http\Middleware\CheckAbilities::class,
'ability' => \Fumeap\Humble\Http\Middleware\CheckForAnyAbility::class,
// ...

Once you add those, you can apply them in your routes middleware like so:

Route::get('admin', function () {
    return response()->json([
        'success' => true
    ]);
})->middleware(['auth:api', 'ability:admin']);

The example would pass if that session token had the abilites as: ["*"] or ["admin"]

You can also use abilities as middleware which is a strict check that the token must have all the given abilites.

Other ways of checking/valdiating abilites inside of your app in areas like Gates & Polciies

  1. auth()->user()->tokenCan('write')
  2. auth()->session()->can('write')
  3. $user()->tokenCan('write')
  4. $request->user()->tokenCan('write')

We also provide an easy way to create new session tokens with the following method

 $user->createToken('action', ['write'])

This would also work with either auth()->user()->createToken(...) or $request->user()->createToken(...)

acidjazz/humble 适用场景与选型建议

acidjazz/humble 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 138.74k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2018 年 08 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「Authentication」 「laravel」 「Passwordless」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 acidjazz/humble 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 acidjazz/humble 我们能提供哪些服务?
定制开发 / 二次开发

基于 acidjazz/humble 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 138.74k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 16
  • 点击次数: 37
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 15
  • Watchers: 1
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-31