{"id":18367858,"url":"https://github.com/photon/auth-mongodb","last_synced_at":"2025-10-15T07:12:39.247Z","repository":{"id":57039264,"uuid":"75280969","full_name":"photon/auth-mongodb","owner":"photon","description":"Store users in a mongodb collection","archived":false,"fork":false,"pushed_at":"2020-11-04T10:15:41.000Z","size":71,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-15T20:49:35.084Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-2.1","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/photon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-01T10:17:57.000Z","updated_at":"2020-11-04T10:15:44.000Z","dependencies_parsed_at":"2022-08-23T23:31:04.784Z","dependency_job_id":null,"html_url":"https://github.com/photon/auth-mongodb","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/photon%2Fauth-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/photon%2Fauth-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/photon%2Fauth-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/photon%2Fauth-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/photon","download_url":"https://codeload.github.com/photon/auth-mongodb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248259504,"owners_count":21074139,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T23:23:44.368Z","updated_at":"2025-10-15T07:12:39.160Z","avatar_url":"https://github.com/photon.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# auth-mongodb\n\n\n[![Build Status](https://travis-ci.org/photon/auth-mongodb.svg?branch=master)](https://travis-ci.org/photon/auth-mongodb)\n\nMongoDB Backend for user, group, acl storage in photon\n\n## Quick start\n\n\n1) Add the module in your project\n\n    composer require \"photon/auth-mongodb:dev-master\"\n\nor for a specific version\n\n    composer require \"photon/auth-mongodb:^2.0\"\n\n2) Define a MongoDB connection in your project configuration\n\n  Declare your MongoBD database\n\n    'databases' =\u003e array(\n        'default' =\u003e array(\n            'engine' =\u003e '\\photon\\db\\MongoDB',\n            'server' =\u003e 'mongodb://localhost:27017/',\n            'database' =\u003e 'orm',\n            'options' =\u003e array(\n                'connect' =\u003e true,\n            ),\n        ),\n    ),\n\n3) Enable session backend\n\n  The authentification module use a session to store user information\n\n    'session_storage' =\u003e '\\photon\\session\\storage\\MongoDB',\n    'session_cookie_path' =\u003e '/',\n    'session_timeout' =\u003e 4 * 60 * 60,\n    'session_mongodb' =\u003e array(\n        'database' =\u003e 'default',\n        'collection' =\u003e 'session',\n    ),\n\n4) Configure the authentification backend\n\n  Configure the authentification backend to use this module\n\n    'auth_backend' =\u003e '\\photon\\Auth\\MongoDBBackend',\n\n5) Create a user\n\n  Create your first user to be able to login\n\n    $user = new \\photon\\auth\\MongoDBUser;\n    $user-\u003esetLogin('jd@exemple.com');\n    $user-\u003esetPassword('strong');\n    $user-\u003esave();\n\n6) Create a login view\n\n  Add a login view in your app, the following code is the minimal one\n\n    class MyViews {\n\t    public function login($request, $match)\n\t    {\n            if ($request-\u003emethod === 'POST') {\n                $user = \\photon\\auth\\Auth::authenticate($request-\u003ePOST);\n                if ($user !== false) {\n                    \\photon\\auth\\Auth::login($request, $user);\n                    return new Redirect('/');\n                }\n            }\n\n\t\t    return shortcuts\\Template::RenderToResponse('login.html', array(), $request);\n        }\n    }\n\n  Declare the login view in your urls.\n\n    array('regex' =\u003e '#^/login$#',\n          'view' =\u003e array('\\Dummy', 'dummy'),\n          'name' =\u003e 'login_view')\n\n7) Enjoy !\n\n## Advanced usage\n\n### Custom user class\n\nIf you want to add application specific content to the user class, you just have to extends it.\nIt's allow you to change the collection name where object are stored.\n\n    class MyUser extends \\photon\\auth\\MongoDBUser\n    {\n        const collectionName = 'foobarcollection';\n\n        public function isAdmin()\n        {\n            return $this-\u003eadmin;\n        }\n    }\n\nThen, you must configure the MongoDB auth backend to use your class. Edit your photon configuration file to add :\n\n    'auth_mongodb' =\u003e array(\n        'user_class' =\u003e '\\My\\App\\MyUser',\n    )\n\n### Protect your view with ACLs\n\nThe following view `dummy` is protected by precondition.\nThe class `MongoDBPrecondition` will load the ACL with name `adminPanel` and ensure the user can access to this view, otherwize a 403 will be generated.\n\n    class Dummy\n    {\n      public $dummy_precond = array(\n      '\\photon\\auth\\MongoDBPrecondition::adminPanel'\n      );\n      public function dummy($request, $match)\n      {\n        return new \\photon\\http\\response\\NoContent;\n      }\n    }\n\n  The ACL can be created with the following code\n\n    $acl = new \\photon\\auth\\MongoDBAcl;\n    $acl-\u003esetName('adminPanel');\n    $acl-\u003eaddUser($user);\n    $acl-\u003esave();\n\n  You can ensure all ACL are created with the following code, users can be added later.\n\n    \\photon\\auth\\MongoDBAcl::ensureExists(['admin', 'api', 'ntp']);\n\n\n### Conditional rendering in templates\n\n  You can use `MongoDBTemplateTag` in your template to test user ACL.\n\n    {acl 'adminPanel'}\n    Will be display only if the user have the adminPanel acl\n    {/acl}\n\n  The template must be declared in your configuration file\n\n    'template_tags' =\u003e array(\n        'acl' =\u003e '\\photon\\auth\\MongoDBTemplateTag',\n    )\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphoton%2Fauth-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphoton%2Fauth-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphoton%2Fauth-mongodb/lists"}