├── .gitignore ├── README.md ├── composer.json ├── composer.lock ├── src ├── .gitkeep ├── GenericUser.php ├── LmAuthServiceProvider.php ├── MongoConnection.php ├── MongoDbUserProvider.php └── lmauth.php └── tests └── .gitkeep /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | vendor/ 3 | .idea 4 | vendor 5 | .idea/* 6 | composer.lock 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Laravel Native MongoDB Authentication Driver 2 | 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. 3 | 4 | ### Installation 5 | 1. Run ```composer require reshadman/laravel-mongo-auth``` in your project's composer root. 6 | 2. Add the ```Reshadman\LmAuth\LmAuthServiceProvider``` service provider to your app. 7 | 4. Run ```php artisan vendor:publish``` command to generate package config files. 8 | 3. In ```auth.php``` config set the ```driver``` to ```lmauth``` : 9 | ```php 10 | 'lmauth' 13 | ]; 14 | ``` 15 | 16 | ### Approach 17 | An instance of ```MongoCollection``` is passed to ```\Reshadman\LmAuth\MongoDbUserProvider``` like below : 18 | 19 | From ```\Reshadman\LmAuth\LmAuthServiceProvider``` : 20 | ```php 21 | app['auth']->extend('lmauth', function(Application $app){ 23 | 24 | $config = $app['config']->get('lmauth'); 25 | 26 | return new MongoDbUserProvider( 27 | $app['lmauth.collection'], // Should be bound to an instance of \MongoCollection 28 | $app['hash'], 29 | $config 30 | ); 31 | 32 | }); 33 | ``` 34 | The above code needs ```$app['lmauth.collection']``` to be available in IoC container which is an instance of ```MongoCollection```. 35 | If you set the ```use_default_collection_provider``` config option to true, the package will create a new binding for that. 36 | 37 | You may also create your own driver with another driver name and pass your own config and mongo collection instance to it. 38 | 39 | ```php 40 | get('lmauth'); // or your desired 43 | $mongoCollection = $app['global_mongo_connection']->myDb->myCollection; 44 | 45 | return new \Reshadman\LmAuth\MongoDbUserProvider($mongoCollection, $app['hash'], $config); 46 | }); 47 | ``` 48 | 49 | #### The ```default_connection_closure``` config 50 | 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. 51 | ```php 52 | function($app) { 55 | return new \MongoClient('192.168.0.2:27013'); // or $app['mongo.singleton_connection'] 56 | } 57 | ]; 58 | ``` 59 | 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. 60 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reshadman/laravel-mongo-auth", 3 | "description": "A native mongo db auth driver on Laravel 5's default auth module.", 4 | "authors": [ 5 | { 6 | "name": "Reza Shadman", 7 | "email": "pcfeeler@gmail.com" 8 | } 9 | ], 10 | "require": { 11 | "ext-mongo": "*", 12 | "illuminate/contracts": "5.*", 13 | "illuminate/support": "5.*", 14 | "illuminate/auth" : "5.*" 15 | }, 16 | "required-dev": { 17 | "mockery/mockery" : "0.9.*", 18 | "phpunit/phpunit" : "~4.0" 19 | }, 20 | "autoload" : { 21 | "psr-4": { 22 | "Reshadman\\LmAuth\\": "src/" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "9ebca094ea745947ab8f228c85c32560", 8 | "packages": [ 9 | { 10 | "name": "danielstjules/stringy", 11 | "version": "1.9.0", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/danielstjules/Stringy.git", 15 | "reference": "3cf18e9e424a6dedc38b7eb7ef580edb0929461b" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/danielstjules/Stringy/zipball/3cf18e9e424a6dedc38b7eb7ef580edb0929461b", 20 | "reference": "3cf18e9e424a6dedc38b7eb7ef580edb0929461b", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "ext-mbstring": "*", 25 | "php": ">=5.3.0" 26 | }, 27 | "require-dev": { 28 | "phpunit/phpunit": "~4.0" 29 | }, 30 | "type": "library", 31 | "autoload": { 32 | "psr-4": { 33 | "Stringy\\": "src/" 34 | }, 35 | "files": [ 36 | "src/Create.php" 37 | ] 38 | }, 39 | "notification-url": "https://packagist.org/downloads/", 40 | "license": [ 41 | "MIT" 42 | ], 43 | "authors": [ 44 | { 45 | "name": "Daniel St. Jules", 46 | "email": "danielst.jules@gmail.com", 47 | "homepage": "http://www.danielstjules.com" 48 | } 49 | ], 50 | "description": "A string manipulation library with multibyte support", 51 | "homepage": "https://github.com/danielstjules/Stringy", 52 | "keywords": [ 53 | "UTF", 54 | "helpers", 55 | "manipulation", 56 | "methods", 57 | "multibyte", 58 | "string", 59 | "utf-8", 60 | "utility", 61 | "utils" 62 | ], 63 | "time": "2015-02-10 06:19:18" 64 | }, 65 | { 66 | "name": "doctrine/inflector", 67 | "version": "v1.0.1", 68 | "source": { 69 | "type": "git", 70 | "url": "https://github.com/doctrine/inflector.git", 71 | "reference": "0bcb2e79d8571787f18b7eb036ed3d004908e604" 72 | }, 73 | "dist": { 74 | "type": "zip", 75 | "url": "https://api.github.com/repos/doctrine/inflector/zipball/0bcb2e79d8571787f18b7eb036ed3d004908e604", 76 | "reference": "0bcb2e79d8571787f18b7eb036ed3d004908e604", 77 | "shasum": "" 78 | }, 79 | "require": { 80 | "php": ">=5.3.2" 81 | }, 82 | "require-dev": { 83 | "phpunit/phpunit": "4.*" 84 | }, 85 | "type": "library", 86 | "extra": { 87 | "branch-alias": { 88 | "dev-master": "1.0.x-dev" 89 | } 90 | }, 91 | "autoload": { 92 | "psr-0": { 93 | "Doctrine\\Common\\Inflector\\": "lib/" 94 | } 95 | }, 96 | "notification-url": "https://packagist.org/downloads/", 97 | "license": [ 98 | "MIT" 99 | ], 100 | "authors": [ 101 | { 102 | "name": "Roman Borschel", 103 | "email": "roman@code-factory.org" 104 | }, 105 | { 106 | "name": "Benjamin Eberlei", 107 | "email": "kontakt@beberlei.de" 108 | }, 109 | { 110 | "name": "Guilherme Blanco", 111 | "email": "guilhermeblanco@gmail.com" 112 | }, 113 | { 114 | "name": "Jonathan Wage", 115 | "email": "jonwage@gmail.com" 116 | }, 117 | { 118 | "name": "Johannes Schmitt", 119 | "email": "schmittjoh@gmail.com" 120 | } 121 | ], 122 | "description": "Common String Manipulations with regard to casing and singular/plural rules.", 123 | "homepage": "http://www.doctrine-project.org", 124 | "keywords": [ 125 | "inflection", 126 | "pluralize", 127 | "singularize", 128 | "string" 129 | ], 130 | "time": "2014-12-20 21:24:13" 131 | }, 132 | { 133 | "name": "illuminate/auth", 134 | "version": "v5.0.4", 135 | "source": { 136 | "type": "git", 137 | "url": "https://github.com/illuminate/auth.git", 138 | "reference": "1fe1f5ac453027fc28130812fd29ac8379e1cc99" 139 | }, 140 | "dist": { 141 | "type": "zip", 142 | "url": "https://api.github.com/repos/illuminate/auth/zipball/1fe1f5ac453027fc28130812fd29ac8379e1cc99", 143 | "reference": "1fe1f5ac453027fc28130812fd29ac8379e1cc99", 144 | "shasum": "" 145 | }, 146 | "require": { 147 | "illuminate/contracts": "5.0.*", 148 | "illuminate/http": "5.0.*", 149 | "illuminate/session": "5.0.*", 150 | "illuminate/support": "5.0.*", 151 | "nesbot/carbon": "~1.0", 152 | "php": ">=5.4.0" 153 | }, 154 | "suggest": { 155 | "illuminate/console": "Required to use the auth:clear-resets command (5.0.*)." 156 | }, 157 | "type": "library", 158 | "extra": { 159 | "branch-alias": { 160 | "dev-master": "5.0-dev" 161 | } 162 | }, 163 | "autoload": { 164 | "psr-4": { 165 | "Illuminate\\Auth\\": "" 166 | } 167 | }, 168 | "notification-url": "https://packagist.org/downloads/", 169 | "license": [ 170 | "MIT" 171 | ], 172 | "authors": [ 173 | { 174 | "name": "Taylor Otwell", 175 | "email": "taylorotwell@gmail.com" 176 | } 177 | ], 178 | "description": "The Illuminate Auth package.", 179 | "time": "2015-01-26 22:08:19" 180 | }, 181 | { 182 | "name": "illuminate/contracts", 183 | "version": "v5.0.0", 184 | "source": { 185 | "type": "git", 186 | "url": "https://github.com/illuminate/contracts.git", 187 | "reference": "78f1dba092d5fcb6d3a19537662abe31c4d128fd" 188 | }, 189 | "dist": { 190 | "type": "zip", 191 | "url": "https://api.github.com/repos/illuminate/contracts/zipball/78f1dba092d5fcb6d3a19537662abe31c4d128fd", 192 | "reference": "78f1dba092d5fcb6d3a19537662abe31c4d128fd", 193 | "shasum": "" 194 | }, 195 | "require": { 196 | "php": ">=5.4.0" 197 | }, 198 | "type": "library", 199 | "extra": { 200 | "branch-alias": { 201 | "dev-master": "5.0-dev" 202 | } 203 | }, 204 | "autoload": { 205 | "psr-4": { 206 | "Illuminate\\Contracts\\": "" 207 | } 208 | }, 209 | "notification-url": "https://packagist.org/downloads/", 210 | "license": [ 211 | "MIT" 212 | ], 213 | "authors": [ 214 | { 215 | "name": "Taylor Otwell", 216 | "email": "taylorotwell@gmail.com" 217 | } 218 | ], 219 | "description": "The Illuminate Contracts package.", 220 | "time": "2015-01-30 16:27:08" 221 | }, 222 | { 223 | "name": "illuminate/http", 224 | "version": "v5.0.4", 225 | "source": { 226 | "type": "git", 227 | "url": "https://github.com/illuminate/http.git", 228 | "reference": "d3a49dee742df45ab7207a29123ec858bbb3b1d2" 229 | }, 230 | "dist": { 231 | "type": "zip", 232 | "url": "https://api.github.com/repos/illuminate/http/zipball/d3a49dee742df45ab7207a29123ec858bbb3b1d2", 233 | "reference": "d3a49dee742df45ab7207a29123ec858bbb3b1d2", 234 | "shasum": "" 235 | }, 236 | "require": { 237 | "illuminate/session": "5.0.*", 238 | "illuminate/support": "5.0.*", 239 | "php": ">=5.4.0", 240 | "symfony/http-foundation": "2.6.*", 241 | "symfony/http-kernel": "2.6.*" 242 | }, 243 | "type": "library", 244 | "extra": { 245 | "branch-alias": { 246 | "dev-master": "5.0-dev" 247 | } 248 | }, 249 | "autoload": { 250 | "psr-4": { 251 | "Illuminate\\Http\\": "" 252 | } 253 | }, 254 | "notification-url": "https://packagist.org/downloads/", 255 | "license": [ 256 | "MIT" 257 | ], 258 | "authors": [ 259 | { 260 | "name": "Taylor Otwell", 261 | "email": "taylorotwell@gmail.com" 262 | } 263 | ], 264 | "description": "The Illuminate Http package.", 265 | "time": "2015-01-26 22:08:19" 266 | }, 267 | { 268 | "name": "illuminate/session", 269 | "version": "v5.0.4", 270 | "source": { 271 | "type": "git", 272 | "url": "https://github.com/illuminate/session.git", 273 | "reference": "ed488eae9db18fa24b2f183648ccce3378cfb060" 274 | }, 275 | "dist": { 276 | "type": "zip", 277 | "url": "https://api.github.com/repos/illuminate/session/zipball/ed488eae9db18fa24b2f183648ccce3378cfb060", 278 | "reference": "ed488eae9db18fa24b2f183648ccce3378cfb060", 279 | "shasum": "" 280 | }, 281 | "require": { 282 | "illuminate/contracts": "5.0.*", 283 | "illuminate/support": "5.0.*", 284 | "nesbot/carbon": "~1.0", 285 | "php": ">=5.4.0", 286 | "symfony/finder": "2.6.*", 287 | "symfony/http-foundation": "2.6.*" 288 | }, 289 | "suggest": { 290 | "illuminate/console": "Required to use the session:table command (5.0.*)." 291 | }, 292 | "type": "library", 293 | "extra": { 294 | "branch-alias": { 295 | "dev-master": "5.0-dev" 296 | } 297 | }, 298 | "autoload": { 299 | "psr-4": { 300 | "Illuminate\\Session\\": "" 301 | } 302 | }, 303 | "notification-url": "https://packagist.org/downloads/", 304 | "license": [ 305 | "MIT" 306 | ], 307 | "authors": [ 308 | { 309 | "name": "Taylor Otwell", 310 | "email": "taylorotwell@gmail.com" 311 | } 312 | ], 313 | "description": "The Illuminate Session package.", 314 | "time": "2015-02-06 23:14:12" 315 | }, 316 | { 317 | "name": "illuminate/support", 318 | "version": "v5.0.4", 319 | "source": { 320 | "type": "git", 321 | "url": "https://github.com/illuminate/support.git", 322 | "reference": "405a2241fefa49cfc39b7fba8cc54f69fce2f101" 323 | }, 324 | "dist": { 325 | "type": "zip", 326 | "url": "https://api.github.com/repos/illuminate/support/zipball/405a2241fefa49cfc39b7fba8cc54f69fce2f101", 327 | "reference": "405a2241fefa49cfc39b7fba8cc54f69fce2f101", 328 | "shasum": "" 329 | }, 330 | "require": { 331 | "danielstjules/stringy": "~1.8", 332 | "doctrine/inflector": "~1.0", 333 | "ext-mbstring": "*", 334 | "illuminate/contracts": "5.0.*", 335 | "php": ">=5.4.0" 336 | }, 337 | "suggest": { 338 | "jeremeamia/superclosure": "Required to be able to serialize closures (~2.0)." 339 | }, 340 | "type": "library", 341 | "extra": { 342 | "branch-alias": { 343 | "dev-master": "5.0-dev" 344 | } 345 | }, 346 | "autoload": { 347 | "psr-4": { 348 | "Illuminate\\Support\\": "" 349 | }, 350 | "files": [ 351 | "helpers.php" 352 | ] 353 | }, 354 | "notification-url": "https://packagist.org/downloads/", 355 | "license": [ 356 | "MIT" 357 | ], 358 | "authors": [ 359 | { 360 | "name": "Taylor Otwell", 361 | "email": "taylorotwell@gmail.com" 362 | } 363 | ], 364 | "description": "The Illuminate Support package.", 365 | "time": "2015-02-11 11:08:03" 366 | }, 367 | { 368 | "name": "nesbot/carbon", 369 | "version": "1.14.0", 370 | "source": { 371 | "type": "git", 372 | "url": "https://github.com/briannesbitt/Carbon.git", 373 | "reference": "bb87460c995d97fe55b39e65f6ffb7f64b0a941e" 374 | }, 375 | "dist": { 376 | "type": "zip", 377 | "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/bb87460c995d97fe55b39e65f6ffb7f64b0a941e", 378 | "reference": "bb87460c995d97fe55b39e65f6ffb7f64b0a941e", 379 | "shasum": "" 380 | }, 381 | "require": { 382 | "php": ">=5.3.0" 383 | }, 384 | "require-dev": { 385 | "phpunit/phpunit": "~4.0" 386 | }, 387 | "type": "library", 388 | "autoload": { 389 | "psr-0": { 390 | "Carbon": "src" 391 | } 392 | }, 393 | "notification-url": "https://packagist.org/downloads/", 394 | "license": [ 395 | "MIT" 396 | ], 397 | "authors": [ 398 | { 399 | "name": "Brian Nesbitt", 400 | "email": "brian@nesbot.com", 401 | "homepage": "http://nesbot.com" 402 | } 403 | ], 404 | "description": "A simple API extension for DateTime.", 405 | "homepage": "https://github.com/briannesbitt/Carbon", 406 | "keywords": [ 407 | "date", 408 | "datetime", 409 | "time" 410 | ], 411 | "time": "2015-02-06 05:07:29" 412 | }, 413 | { 414 | "name": "psr/log", 415 | "version": "1.0.0", 416 | "source": { 417 | "type": "git", 418 | "url": "https://github.com/php-fig/log.git", 419 | "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b" 420 | }, 421 | "dist": { 422 | "type": "zip", 423 | "url": "https://api.github.com/repos/php-fig/log/zipball/fe0936ee26643249e916849d48e3a51d5f5e278b", 424 | "reference": "fe0936ee26643249e916849d48e3a51d5f5e278b", 425 | "shasum": "" 426 | }, 427 | "type": "library", 428 | "autoload": { 429 | "psr-0": { 430 | "Psr\\Log\\": "" 431 | } 432 | }, 433 | "notification-url": "https://packagist.org/downloads/", 434 | "license": [ 435 | "MIT" 436 | ], 437 | "authors": [ 438 | { 439 | "name": "PHP-FIG", 440 | "homepage": "http://www.php-fig.org/" 441 | } 442 | ], 443 | "description": "Common interface for logging libraries", 444 | "keywords": [ 445 | "log", 446 | "psr", 447 | "psr-3" 448 | ], 449 | "time": "2012-12-21 11:40:51" 450 | }, 451 | { 452 | "name": "symfony/debug", 453 | "version": "v2.6.4", 454 | "target-dir": "Symfony/Component/Debug", 455 | "source": { 456 | "type": "git", 457 | "url": "https://github.com/symfony/Debug.git", 458 | "reference": "150c80059c3ccf68f96a4fceb513eb6b41f23300" 459 | }, 460 | "dist": { 461 | "type": "zip", 462 | "url": "https://api.github.com/repos/symfony/Debug/zipball/150c80059c3ccf68f96a4fceb513eb6b41f23300", 463 | "reference": "150c80059c3ccf68f96a4fceb513eb6b41f23300", 464 | "shasum": "" 465 | }, 466 | "require": { 467 | "php": ">=5.3.3", 468 | "psr/log": "~1.0" 469 | }, 470 | "conflict": { 471 | "symfony/http-kernel": ">=2.3,<2.3.24|~2.4.0|>=2.5,<2.5.9|>=2.6,<2.6.2" 472 | }, 473 | "require-dev": { 474 | "symfony/class-loader": "~2.2", 475 | "symfony/http-foundation": "~2.1", 476 | "symfony/http-kernel": "~2.3.24|~2.5.9|~2.6,>=2.6.2" 477 | }, 478 | "suggest": { 479 | "symfony/http-foundation": "", 480 | "symfony/http-kernel": "" 481 | }, 482 | "type": "library", 483 | "extra": { 484 | "branch-alias": { 485 | "dev-master": "2.6-dev" 486 | } 487 | }, 488 | "autoload": { 489 | "psr-0": { 490 | "Symfony\\Component\\Debug\\": "" 491 | } 492 | }, 493 | "notification-url": "https://packagist.org/downloads/", 494 | "license": [ 495 | "MIT" 496 | ], 497 | "authors": [ 498 | { 499 | "name": "Symfony Community", 500 | "homepage": "http://symfony.com/contributors" 501 | }, 502 | { 503 | "name": "Fabien Potencier", 504 | "email": "fabien@symfony.com" 505 | } 506 | ], 507 | "description": "Symfony Debug Component", 508 | "homepage": "http://symfony.com", 509 | "time": "2015-01-21 20:57:55" 510 | }, 511 | { 512 | "name": "symfony/event-dispatcher", 513 | "version": "v2.6.4", 514 | "target-dir": "Symfony/Component/EventDispatcher", 515 | "source": { 516 | "type": "git", 517 | "url": "https://github.com/symfony/EventDispatcher.git", 518 | "reference": "f75989f3ab2743a82fe0b03ded2598a2b1546813" 519 | }, 520 | "dist": { 521 | "type": "zip", 522 | "url": "https://api.github.com/repos/symfony/EventDispatcher/zipball/f75989f3ab2743a82fe0b03ded2598a2b1546813", 523 | "reference": "f75989f3ab2743a82fe0b03ded2598a2b1546813", 524 | "shasum": "" 525 | }, 526 | "require": { 527 | "php": ">=5.3.3" 528 | }, 529 | "require-dev": { 530 | "psr/log": "~1.0", 531 | "symfony/config": "~2.0,>=2.0.5", 532 | "symfony/dependency-injection": "~2.6", 533 | "symfony/expression-language": "~2.6", 534 | "symfony/stopwatch": "~2.3" 535 | }, 536 | "suggest": { 537 | "symfony/dependency-injection": "", 538 | "symfony/http-kernel": "" 539 | }, 540 | "type": "library", 541 | "extra": { 542 | "branch-alias": { 543 | "dev-master": "2.6-dev" 544 | } 545 | }, 546 | "autoload": { 547 | "psr-0": { 548 | "Symfony\\Component\\EventDispatcher\\": "" 549 | } 550 | }, 551 | "notification-url": "https://packagist.org/downloads/", 552 | "license": [ 553 | "MIT" 554 | ], 555 | "authors": [ 556 | { 557 | "name": "Symfony Community", 558 | "homepage": "http://symfony.com/contributors" 559 | }, 560 | { 561 | "name": "Fabien Potencier", 562 | "email": "fabien@symfony.com" 563 | } 564 | ], 565 | "description": "Symfony EventDispatcher Component", 566 | "homepage": "http://symfony.com", 567 | "time": "2015-02-01 16:10:57" 568 | }, 569 | { 570 | "name": "symfony/finder", 571 | "version": "v2.6.4", 572 | "target-dir": "Symfony/Component/Finder", 573 | "source": { 574 | "type": "git", 575 | "url": "https://github.com/symfony/Finder.git", 576 | "reference": "16513333bca64186c01609961a2bb1b95b5e1355" 577 | }, 578 | "dist": { 579 | "type": "zip", 580 | "url": "https://api.github.com/repos/symfony/Finder/zipball/16513333bca64186c01609961a2bb1b95b5e1355", 581 | "reference": "16513333bca64186c01609961a2bb1b95b5e1355", 582 | "shasum": "" 583 | }, 584 | "require": { 585 | "php": ">=5.3.3" 586 | }, 587 | "type": "library", 588 | "extra": { 589 | "branch-alias": { 590 | "dev-master": "2.6-dev" 591 | } 592 | }, 593 | "autoload": { 594 | "psr-0": { 595 | "Symfony\\Component\\Finder\\": "" 596 | } 597 | }, 598 | "notification-url": "https://packagist.org/downloads/", 599 | "license": [ 600 | "MIT" 601 | ], 602 | "authors": [ 603 | { 604 | "name": "Symfony Community", 605 | "homepage": "http://symfony.com/contributors" 606 | }, 607 | { 608 | "name": "Fabien Potencier", 609 | "email": "fabien@symfony.com" 610 | } 611 | ], 612 | "description": "Symfony Finder Component", 613 | "homepage": "http://symfony.com", 614 | "time": "2015-01-03 08:01:59" 615 | }, 616 | { 617 | "name": "symfony/http-foundation", 618 | "version": "v2.6.4", 619 | "target-dir": "Symfony/Component/HttpFoundation", 620 | "source": { 621 | "type": "git", 622 | "url": "https://github.com/symfony/HttpFoundation.git", 623 | "reference": "8fa63d614d56ccfe033e30411d90913cfc483ff6" 624 | }, 625 | "dist": { 626 | "type": "zip", 627 | "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/8fa63d614d56ccfe033e30411d90913cfc483ff6", 628 | "reference": "8fa63d614d56ccfe033e30411d90913cfc483ff6", 629 | "shasum": "" 630 | }, 631 | "require": { 632 | "php": ">=5.3.3" 633 | }, 634 | "require-dev": { 635 | "symfony/expression-language": "~2.4" 636 | }, 637 | "type": "library", 638 | "extra": { 639 | "branch-alias": { 640 | "dev-master": "2.6-dev" 641 | } 642 | }, 643 | "autoload": { 644 | "psr-0": { 645 | "Symfony\\Component\\HttpFoundation\\": "" 646 | }, 647 | "classmap": [ 648 | "Symfony/Component/HttpFoundation/Resources/stubs" 649 | ] 650 | }, 651 | "notification-url": "https://packagist.org/downloads/", 652 | "license": [ 653 | "MIT" 654 | ], 655 | "authors": [ 656 | { 657 | "name": "Symfony Community", 658 | "homepage": "http://symfony.com/contributors" 659 | }, 660 | { 661 | "name": "Fabien Potencier", 662 | "email": "fabien@symfony.com" 663 | } 664 | ], 665 | "description": "Symfony HttpFoundation Component", 666 | "homepage": "http://symfony.com", 667 | "time": "2015-02-01 16:10:57" 668 | }, 669 | { 670 | "name": "symfony/http-kernel", 671 | "version": "v2.6.4", 672 | "target-dir": "Symfony/Component/HttpKernel", 673 | "source": { 674 | "type": "git", 675 | "url": "https://github.com/symfony/HttpKernel.git", 676 | "reference": "27abf3106d8bd08562070dd4e2438c279792c434" 677 | }, 678 | "dist": { 679 | "type": "zip", 680 | "url": "https://api.github.com/repos/symfony/HttpKernel/zipball/27abf3106d8bd08562070dd4e2438c279792c434", 681 | "reference": "27abf3106d8bd08562070dd4e2438c279792c434", 682 | "shasum": "" 683 | }, 684 | "require": { 685 | "php": ">=5.3.3", 686 | "psr/log": "~1.0", 687 | "symfony/debug": "~2.6,>=2.6.2", 688 | "symfony/event-dispatcher": "~2.5.9|~2.6,>=2.6.2", 689 | "symfony/http-foundation": "~2.5,>=2.5.4" 690 | }, 691 | "require-dev": { 692 | "symfony/browser-kit": "~2.3", 693 | "symfony/class-loader": "~2.1", 694 | "symfony/config": "~2.0,>=2.0.5", 695 | "symfony/console": "~2.3", 696 | "symfony/css-selector": "~2.0,>=2.0.5", 697 | "symfony/dependency-injection": "~2.2", 698 | "symfony/dom-crawler": "~2.0,>=2.0.5", 699 | "symfony/expression-language": "~2.4", 700 | "symfony/finder": "~2.0,>=2.0.5", 701 | "symfony/process": "~2.0,>=2.0.5", 702 | "symfony/routing": "~2.2", 703 | "symfony/stopwatch": "~2.3", 704 | "symfony/templating": "~2.2", 705 | "symfony/translation": "~2.0,>=2.0.5", 706 | "symfony/var-dumper": "~2.6" 707 | }, 708 | "suggest": { 709 | "symfony/browser-kit": "", 710 | "symfony/class-loader": "", 711 | "symfony/config": "", 712 | "symfony/console": "", 713 | "symfony/dependency-injection": "", 714 | "symfony/finder": "", 715 | "symfony/var-dumper": "" 716 | }, 717 | "type": "library", 718 | "extra": { 719 | "branch-alias": { 720 | "dev-master": "2.6-dev" 721 | } 722 | }, 723 | "autoload": { 724 | "psr-0": { 725 | "Symfony\\Component\\HttpKernel\\": "" 726 | } 727 | }, 728 | "notification-url": "https://packagist.org/downloads/", 729 | "license": [ 730 | "MIT" 731 | ], 732 | "authors": [ 733 | { 734 | "name": "Symfony Community", 735 | "homepage": "http://symfony.com/contributors" 736 | }, 737 | { 738 | "name": "Fabien Potencier", 739 | "email": "fabien@symfony.com" 740 | } 741 | ], 742 | "description": "Symfony HttpKernel Component", 743 | "homepage": "http://symfony.com", 744 | "time": "2015-02-02 18:02:30" 745 | } 746 | ], 747 | "packages-dev": [], 748 | "aliases": [], 749 | "minimum-stability": "stable", 750 | "stability-flags": [], 751 | "prefer-stable": false, 752 | "prefer-lowest": false, 753 | "platform": [], 754 | "platform-dev": [] 755 | } 756 | -------------------------------------------------------------------------------- /src/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reshadman/laravel-mongo-auth/810dbca572444a72e9ca437f66f251827c2a1ff8/src/.gitkeep -------------------------------------------------------------------------------- /src/GenericUser.php: -------------------------------------------------------------------------------- 1 | attributes[$this->getConfig()['auth_id_field']]; 21 | } 22 | 23 | /** 24 | * Get config array 25 | * 26 | * @return array 27 | */ 28 | private function getConfig() 29 | { 30 | if(empty(self::$config)) 31 | { 32 | self::$config = config('lmauth', []); 33 | } 34 | 35 | return self::$config; 36 | } 37 | 38 | /** 39 | * Get auth password 40 | * 41 | * @return string 42 | */ 43 | public function getAuthPassword() 44 | { 45 | return $this->attributes[$this->getConfig()['auth_password_field']]; 46 | } 47 | 48 | /** 49 | * Get remember token value 50 | * 51 | * @return string 52 | */ 53 | public function getRememberToken() 54 | { 55 | return $this->attributes[$this->getConfig()['auth_remember_token_field']]; 56 | } 57 | } -------------------------------------------------------------------------------- /src/LmAuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([ 16 | __DIR__.'/lmauth.php' => config_path('lmauth.php'), 17 | ]); 18 | 19 | $this->app['auth']->extend('lmauth', function(Application $app){ 20 | 21 | $config = $app['config']->get('lmauth'); 22 | 23 | return new MongoDbUserProvider($app['lmauth.collection'], $app['hash'], $config); 24 | 25 | }); 26 | } 27 | 28 | /** 29 | * Register the application services. 30 | * 31 | * @return void 32 | */ 33 | public function register() 34 | { 35 | $config = $this->app['config']->get('lmauth'); 36 | 37 | if(is_null($config)) return; // In case there is no config 38 | 39 | if($config['use_default_collection_provider']) { 40 | 41 | if(! is_null($closure = $config['default_connection_closure'])){ 42 | 43 | $connection = $closure($this->app); 44 | 45 | $this->app->singleton('lmauth.connection', $connection); 46 | 47 | } else { 48 | 49 | $this->app->singleton('lmauth.connection', function(Application $app){ 50 | 51 | return new \MongoClient(); 52 | 53 | }); 54 | 55 | } 56 | 57 | $this->app->singleton('lmauth.collection', function(Application $app) use($config) { 58 | 59 | $mongoClient = $app['lmauth.connection']; 60 | 61 | return (new MongoConnection($mongoClient, $config)) 62 | ->getDefaultDatabase()->{$config['auth_collection_name']}; 63 | 64 | }); 65 | 66 | } 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/MongoConnection.php: -------------------------------------------------------------------------------- 1 | client = $client; 31 | $this->config = $config; 32 | } 33 | 34 | /** 35 | * Get default database 36 | * 37 | * @return \MongoDB 38 | */ 39 | public function getDefaultDatabase() 40 | { 41 | if(is_null($this->defaultDb)) 42 | { 43 | $this->defaultDb = $this->client->selectDB($this->config['database_name']); 44 | } 45 | 46 | return $this->defaultDb; 47 | } 48 | 49 | /** 50 | * Call all not available calls from default db 51 | * 52 | * @param $method 53 | * @param array $args 54 | * @return mixed 55 | */ 56 | public function __call($method, array $args = []) 57 | { 58 | return call_user_func_array([$this->getDefaultDatabase(), $method], $args); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/MongoDbUserProvider.php: -------------------------------------------------------------------------------- 1 | collection = $collection; 37 | $this->hasher = $hasher; 38 | $this->config = $config; 39 | 40 | $this->checkMongoObjectId(); 41 | } 42 | 43 | /** 44 | * Check that id should be decorated with object id or not 45 | */ 46 | protected function checkMongoObjectId() 47 | { 48 | if($this->getIdentificationField() == '_id') 49 | { 50 | $this->idShouldBeDecorated = true; 51 | } 52 | } 53 | 54 | /** 55 | * Should id be decorated with object id or not ? 56 | * 57 | * @return bool 58 | */ 59 | protected function idShouldBeDecorated() 60 | { 61 | return $this->idShouldBeDecorated; 62 | } 63 | 64 | /** 65 | * Get our hasher contract 66 | * 67 | * @return Hasher 68 | */ 69 | protected function getHasher() 70 | { 71 | return $this->hasher; 72 | } 73 | 74 | /** 75 | * Get collection name for users storage 76 | * 77 | * @return string 78 | */ 79 | protected function getCollectionName() 80 | { 81 | return $this->config['auth_collection_name']; 82 | } 83 | 84 | /** 85 | * Retrieve a user by their unique identifier. 86 | * 87 | * @param mixed $identifier 88 | * @return \Illuminate\Contracts\Auth\Authenticatable|null 89 | */ 90 | public function retrieveById($identifier) 91 | { 92 | if($this->idShouldBeDecorated()) $identifier = $this->makeObjectId($identifier); 93 | 94 | $user = $this->getCollection()->findOne([$this->getIdentificationField() => $identifier]); 95 | 96 | return $this->makeUserContract($user); 97 | } 98 | 99 | /** 100 | * Make mongo objectId 101 | * 102 | * @param $identifier 103 | * @return MongoId 104 | */ 105 | protected function makeObjectId($identifier) 106 | { 107 | return new MongoId($identifier); 108 | } 109 | 110 | /** 111 | * Make the authenticatable user 112 | * 113 | * @param $user 114 | * @return GenericUser|null 115 | */ 116 | protected function makeUserContract($user) 117 | { 118 | if(! is_null($user)) 119 | { 120 | return new $this->config['user_class']($user); 121 | } 122 | 123 | return null; 124 | } 125 | 126 | /** 127 | * Get id field in mongo db collection 128 | * 129 | * @return string 130 | */ 131 | protected function getIdentificationField() 132 | { 133 | return $this->config['auth_id_field']; 134 | } 135 | 136 | /** 137 | * Retrieve a user by by their unique identifier and "remember me" token. 138 | * 139 | * @param mixed $identifier 140 | * @param string $token 141 | * @return \Illuminate\Contracts\Auth\Authenticatable|null 142 | */ 143 | public function retrieveByToken($identifier, $token) 144 | { 145 | if($this->idShouldBeDecorated()) $identifier = $this->makeObjectId($identifier); 146 | 147 | $user = $this->getCollection()->findOne([ 148 | $this->getIdentificationField() => $identifier, 149 | $this->getRememberTokenField() => $token 150 | ]); 151 | 152 | return $this->makeUserContract($user); 153 | } 154 | 155 | /** 156 | * Get remember token field name 157 | * 158 | * @return string 159 | */ 160 | public function getRememberTokenField() 161 | { 162 | return $this->config['auth_remember_token_field']; 163 | } 164 | 165 | /** 166 | * Update the "remember me" token for the given user in storage. 167 | * 168 | * @param \Illuminate\Contracts\Auth\Authenticatable $user 169 | * @param string $token 170 | * @return void 171 | */ 172 | public function updateRememberToken(Authenticatable $user, $token) 173 | { 174 | $id = $user->getAuthIdentifier(); 175 | 176 | if($this->idShouldBeDecorated()) $id = $this->makeObjectId($user->getAuthIdentifier()); 177 | 178 | $this->getCollection()->findAndModify( 179 | [$this->getIdentificationField() => $id], 180 | ['$set' => [$this->getRememberTokenField() => $token]] 181 | ); 182 | } 183 | 184 | /** 185 | * Get password field 186 | * 187 | * @return string 188 | */ 189 | public function getPasswordField() 190 | { 191 | return $this->config['auth_password_field']; 192 | } 193 | 194 | /** 195 | * Retrieve a user by the given credentials. 196 | * 197 | * @param array $credentials 198 | * @return \Illuminate\Contracts\Auth\Authenticatable|null 199 | */ 200 | public function retrieveByCredentials(array $credentials) 201 | { 202 | $query = []; $password = $this->getPasswordField(); 203 | 204 | foreach($credentials as $key => $value) 205 | { 206 | if($key == '_id') $value = $this->makeObjectId($value); 207 | 208 | if(! str_contains($key, $password)) $query[$key] = $value; 209 | } 210 | 211 | return $this->makeUserContract($this->getCollection()->findOne($query)); 212 | } 213 | 214 | /** 215 | * Validate a user against the given credentials. 216 | * 217 | * @param \Illuminate\Contracts\Auth\Authenticatable $user 218 | * @param array $credentials 219 | * @return bool 220 | */ 221 | public function validateCredentials(Authenticatable $user, array $credentials) 222 | { 223 | $password = $credentials[$this->getPasswordField()]; 224 | 225 | return $this->hasher->check($password, $user->getAuthPassword()); 226 | } 227 | 228 | /** 229 | * Get mongodb collection instance 230 | * 231 | * @return \MongoCollection 232 | */ 233 | public function getCollection() 234 | { 235 | return $this->collection; 236 | } 237 | } -------------------------------------------------------------------------------- /src/lmauth.php: -------------------------------------------------------------------------------- 1 | '\Reshadman\LmAuth\GenericUser', 3 | 'auth_collection_name' => 'users', 4 | 'auth_id_field' => '_id', 5 | 'auth_remember_token_field' => 'remember_token', 6 | 'auth_password_field' => 'password', 7 | 'database_name' => 'mongo_test', 8 | 'use_default_collection_provider' => true, 9 | 'default_connection_closure' => null 10 | ]; -------------------------------------------------------------------------------- /tests/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reshadman/laravel-mongo-auth/810dbca572444a72e9ca437f66f251827c2a1ff8/tests/.gitkeep --------------------------------------------------------------------------------