2017 © Pedro Peláez
 

library laravel-mongo-auth

A native mongo db auth driver on Laravel 5's default auth module.

image

reshadman/laravel-mongo-auth

A native mongo db auth driver on Laravel 5's default auth module.

  • Monday, March 7, 2016
  • by bigsinoos
  • Repository
  • 1 Watchers
  • 25 Stars
  • 42 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 0 Open issues
  • 2 Versions
  • 5 % Grown

The README.md

Laravel Native MongoDB Authentication Driver

This package does not require any external MongoDB related dependencies except the Php MongoDB Driver and simply uses Auth::extend() to extend the native Laravel Auth module., (*1)

Installation

  1. Run composer require reshadman/laravel-mongo-auth in your project's composer root.
  2. Add the Reshadman\LmAuth\LmAuthServiceProvider service provider to your app.
  3. Run php artisan vendor:publish command to generate package config files.
  4. In auth.php config set the driver to lmauth :
<?php return [
    //...
    'driver' => 'lmauth'
];

Approach

An instance of MongoCollection is passed to \Reshadman\LmAuth\MongoDbUserProvider like below :, (*2)

From \Reshadman\LmAuth\LmAuthServiceProvider :, (*3)

<?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
    );

});

The above code needs $app['lmauth.collection'] to be available in IoC container which is an instance of MongoCollection. If you set the use_default_collection_provider config option to true, the package will create a new binding for that., (*4)

You may also create your own driver with another driver name and pass your own config and mongo collection instance to it., (*5)

<?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);
});

The default_connection_closure config

If you pass a closure to this config key then the package will use this closure to get the MongoClient connection to connect to mongodb. Usefull when using Doctrine Mongo db package or alternatives., (*6)

<?php return [
    //...
    'default_connection_closure' => function($app) {
        return new \MongoClient('192.168.0.2:27013'); // or $app['mongo.singleton_connection']
    }
];

If you set the above option to null the the package will use a singleton shared instance ( new \MongoClient()) which has lmauth.connection key in the container., (*7)

The Versions

07/03 2016

dev-master

9999999-dev

A native mongo db auth driver on Laravel 5's default auth module.

  Sources   Download

The Requires

 

by Reza Shadman

27/02 2015

1.0.0

1.0.0.0

A native mongo db auth driver on Laravel 5's default auth module.

  Sources   Download

The Requires

 

by Reza Shadman