reshadman / laravel-mongo-auth
该包已被废弃,不再维护。未建议替代包。
最新版本(1.0.0)的包没有可用的许可证信息。
这是一个基于Laravel 5默认认证模块的原生MongoDB认证驱动。
1.0.0
2015-02-27 13:37 UTC
Requires
- illuminate/auth: 5.0.*
- illuminate/contracts: 5.0.*
- illuminate/support: 5.0.*
This package is auto-updated.
Last update: 2021-09-12 00:33:25 UTC
README
该包不需要任何外部MongoDB相关依赖(除了Php MongoDB Driver),只需简单地使用Auth::extend()
来扩展Laravel的原生认证模块。
安装
- 在你的项目的composer根目录中运行
composer require reshadman/laravel-mongo-auth
。 - 将
Reshadman\LmAuth\LmAuthServiceProvider
服务提供者添加到你的应用中。 - 运行
php artisan vendor:publish
命令以生成包配置文件。 - 在
auth.php
配置中设置driver
为lmauth
<?php return [ //... 'driver' => 'lmauth' ];
方法
将一个MongoCollection
实例传递给下面的\Reshadman\LmAuth\MongoDbUserProvider
来自\Reshadman\LmAuth\LmAuthServiceProvider
<?php $this->app['auth']->extend('lmauth', function(Application $app){ $config = $app['config']->get('lmauth'); return new MongoDbUserProvider( $app['lmauth.collection'], // Should be bound to an instance of \MongoCollection $app['hash'], $config ); });
上述代码需要在IoC容器中提供$app['lmauth.collection']
,它是一个MongoCollection
实例。如果你将use_default_collection_provider
配置选项设置为true,该包将为该创建一个新的绑定。
你也可以创建自己的驱动,使用其他驱动名称,并传递自己的配置和MongoCollection实例给它。
<?php Auth::extend('my-lmauth', function($app) { $config = $app['config']->get('lmauth'); // or your desired $mongoCollection = $app['global_mongo_connection']->myDb->myCollection; return new \Reshadman\LmAuth\MongoDbUserProvider($mongoCollection, $app['hash'], $config); });
default_connection_closure
配置
如果你向此配置键传递一个闭包,则该包将使用此闭包来获取连接到mongodb的MongoClient
连接。当使用Doctrine Mongo db包或替代品时非常有用。
<?php return [ //... 'default_connection_closure' => function($app) { return new \MongoClient('192.168.0.2:27013'); // or $app['mongo.singleton_connection'] } ];
如果你将上述选项设置为null
,则该包将使用一个单例共享实例(new \MongoClient()
),它在容器中具有lmauth.connection
键。