stauth / laravel-stauth
暂存服务器授权包,.htaccess替代品
0.0.7
2017-11-09 14:08 UTC
Requires
- guzzlehttp/guzzle: 6.*
- hedronium/spaceless-blade: ^2.0
- laravel/framework: 5.5.*
- symfony/psr-http-message-bridge: ~1.0
This package is not auto-updated.
Last update: 2024-09-28 00:44:42 UTC
README
暂存服务器授权包,.htaccess替代品,在stauth.io注册
安装
composer require stauth/laravel-stauth
本地和暂存
如果你不希望在生产环境中执行Stauth服务提供者,创建StauthProtectionServiceProvider
namespace App\Providers; use Illuminate\Support\ServiceProvider; use Stauth\StauthServiceProvider; class StauthProtectionServiceProvider extends ServiceProvider { /** * Register any application services. * * @return void */ public function register() { if ($this->app->environment('local', 'staging')) { $this->app->register(StauthServiceProvider::class); } } }
并将其添加到config/app.php中的AppServiceProvider下方
'providers' => [ /** * Stauth app access protection */ App\Providers\StauthProtectionServiceProvider::class, ],
生产
如果你不在意在生产环境中执行Stauth服务提供者,或者你想保护你的生产环境,可以直接在config/app.php中的providers数组中添加它。
'providers' => [ /** * Staging access control */ Stauth\StauthServiceProvider::class, ],
在app/Http/Kernel.php中添加Stauth中间件,非常重要的是StauthProtection必须放在任何响应缓存扩展中间件(如laravel-responsecache)之上
/** * The application's route middleware groups. * * @var array */ protected $middlewareGroups = [ 'web' => [ ... \Stauth\Middleware\StauthProtection::class, ],
在stauth.io生成访问令牌,并将其添加为.env文件中的STAUTH_ACCESS_TOKEN参数
STAUTH_ACCESS_TOKEN=verylongchainoflettersmixedwithsomerandomnumbers123
默认受保护环境为staging,为了改变这一点,在.env文件中添加STAUTH_PROTECTED_ENV参数
STAUTH_PROTECTED_ENV=local
其他
如果你想知道或做更多,请参阅下面。
发布配置
你可以发布配置并更新PHP文件中的所需参数
php artisan vendor:publish --provider="Stauth\StauthServiceProvider" --tag=config
缓存
请注意,此包利用了csrf_token,因此非常重要,请确保将路由/stauth/protected和/stauth/authorize从任何响应缓存引擎中排除。