定制 girift/apitwist-sso-laravel-client 二次开发

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

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

girift/apitwist-sso-laravel-client

最新稳定版本:0.2.2

Composer 安装命令:

composer require girift/apitwist-sso-laravel-client

包简介

This is the client Integration with ApiTwist SSO.

README 文档

README

Latest Version on Packagist GitHub Code Style Action Status Total Downloads

Client integration for ApiTwist SSO.

Installation

Install the package via composer:

composer require girift/apitwist-sso-laravel-client

Add SSO config to your .env file:

SSO_CLIENT_ID=client_id
SSO_CLIENT_SECRET=client_secret
SSO_DOMAIN='https://sso.apitwist.com'

Add HasSsoTokens trait to your User model

// ...
use Girift\SSO\Traits\HasSsoTokens;

class User extends Authenticatable
{
    use HasSsoTokens;
    // ...
}

Add middlewares to your app/Http/Kernel.php file $routeMiddleware array:

protected $routeMiddleware = [
    // ...
    'sso.auth' => \Girift\SSO\Http\Middleware\SsoAuthenticate::class,
    'sso.api' => \Girift\SSO\Http\Middleware\SsoApiAuthenticate::class,
];

You can publish and run the migrations with:

php artisan vendor:publish --tag="sso-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="sso-config"

This is the contents of the published config file:

return [
    'client_id' => env('SSO_CLIENT_ID'),
    'client_secret' => env('SSO_CLIENT_SECRET'),
    'redirect_url' => config('app.url') . '/sso/callback',
    'sso_domain' => env('SSO_DOMAIN', 'https://sso.apitwist.com'),
    'authorize_url' => config('sso.sso_domain').'/oauth/authorize',
    'api_url' => config('sso.sso_domain').'/oauth/token',
    'logout_url' => config('sso.sso_domain'). '/logout',
    'get_user_url' => config('sso.sso_domain').  '/api/user',
];

Usage

Use sso.auth along with web middleware in your routes/web.php file:

Route::middleware([ 'web', 'sso.auth' ])->get('/route', function () {
    // Your routes
});

If you see Session store not set on request. error, add theese middlewares in your app/Http/Kernel.php file $middleware array:

protected $middleware = [
    // ...
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
];

Use named routes as authentication routes:

sso.login
sso.logout

Add sso.loggedIn named route to your home page:

Route::middleware([ 'web', 'sso.auth' ])->get('/home', function () {
    // Your home page
})->name('sso.loggedIn')->name('home');

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固