定制 stratedge/visa 二次开发

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

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

stratedge/visa

Composer 安装命令:

composer require stratedge/visa

包简介

A complimentary extension of the official Laravel Passport package.

README 文档

README

Build Status Latest Stable Version Total Downloads License

Visa

A complimentary extension of the official Laravel Passport package.

Visa provides the following functionality:

  • Use a random string for Client ID;
  • Add configuration to use a UUID for Client ID instead of a random string;
  • Provide the CheckFirstPartyClient middleware class to authenticate a client as a first party client;
  • Add configuration to use the global Laravel error handler to handle errors thrown by Passport instead of Passport's built-in handler; and
  • Provide overwrite-able enableCustomGrants() method in the service provider to make registering custom grants easier.

Passport Compatability

While this library mostly adheres to semantic versioning, major version numbers are set to align to major versions for the Passport library. This simplifies determining which version of Visa includes which version of Passport.

Visa Version Configured Passport Version
7.* ^7.0

Installation

Visa is registered with Packagist and can be installed with Composer. Run the following on the command line:

composer require stratedge/visa

Since Visa extends Passport, installing Visa will install Passport for you.

For versions of Laravel that support auto-registration of packages, Visa will automatically register itself. For older versions, be sure to add Stratedge\Visa\VisaServiceProvider::class to your list of service providers in config/app.php.

No need to include Passport's service provider, the Visa provider extends it.

From here, complete all the typical Passport installation steps.

PLEASE NOTE: See configuration below to ensure you complete any optional Visa configurations before running migrations to ensure columns are created with the correct types.

Configuration

To configure core Passport features, refer to the Passport documentation. Since Visa uses Passport, you're free to configure whatever you want from Passport.

Using Random Strings for Client ID

By default Visa will use random 40-character strings for client IDs, the same as the client secrets. No configuration required.

Using UUIDs for Client ID

Visa also supports UUIDs for client IDs, but must be configured to do so before migrations are run so that the migrations specify the correct column type for client_id.

To use UUIDs, call \Stratedge\Visa\Visa::enableClientUUIDs() in the boot() method of your AppServiceProvider:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Stratedge\Visa\Visa;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // Configure UUIDs for OAuth client IDs
        Visa::enableClientUUIDs();
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

Using the CheckFirstPartyClient Middleware

To use the CheckFirstPartyClient middleware, add the following middleware to the $routeMiddleware property of your App\Http\Kernel class:

protected $routeMiddleware = [
    'auth.first-party' => \Stratedge\Visa\Http\Middleware\CheckFirstPartyClient::class,
];

The middleware can then be registered for any route or route group with the key auth.first-party. Any clients that are not considered first-party that attempt to authenticate with endpoints assigned the CheckFirstPartyClient middleware will fail with an authentication error.

Error Handling

By default, Visa will use the built-in Passport error handler that will catch and respond to errors automatically. If you wish to disable the built-in handler and use the global Laravel error handler to control the logging and output of errors, call \Stratedge\Visa\Visa::disablePassportErrorHandling() in the boot() method of your AppServiceProvider:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Stratedge\Visa\Visa;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // Do not use the standard Passport error handling
        Visa::disablePassportErrorHandling();
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

Enabling Custom Grants

In order to use your own custom grants, you must extend the Stratedge\Visa\VisaServiceProvider class and overload the enableCustomGrants() method.

The method accepts a single parameter of type League\OAuth2\Server\AuthorizationServer that will be injected automatically as the argument $server. Use the enableGrantType() method of the AuthorizationServer class to enable new grant types.

<?php

namespace App\Providers;

use Stratedge\Visa\VisaServiceProvider as BaseProvider;

class VisaServiceProvider extends BaseProvider
{
    /**
     * Enables any additional custom grants when overloaded.
     *
     * @param  AuthorizationServer $server
     * @return void
     */
    public function enableCustomGrants(AuthorizationServer $server)
    {
        $server->enableGrantType(/* Register custom grant here */);
    }
}

PLEASE NOTE: When extending the service provider, be sure to register your custom VisaServiceProvider in the app.php configuration file and turn off the auto-discovery of the default provider provided by this library through your composer.json file.

Extension Philosophy

Because Passport is an authorization library, integrating security patches quickly is immensely important. Unlike a fork, which creates a separately maintained version of the entire Passport library, Visa is a complimentary package that sits alongside the core Passport in your project. In that sense Visa extends Passport and makes only the smallest required changes.

In fact, when Visa is installed it will automatically require Passport. But since Passport remains a separate library, the developer is free to specify the version of Passport they wish to use. This allows the developer to take advantage of incremental security updates in Passport without requiring corresponding changes to Visa. So long as the newest version of Passport makes no breaking API changes, changing the Passport version should work just fine.

stratedge/visa 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-20