{ "info": { "author": "John McGrath", "author_email": "john.mcgrath207@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP :: Dynamic Content", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# Flask LDAP View\nA library to restrict your flask pages by LDAP groups\n\nA more full example that includes Flask-Login can be found [here](https://github.com/sonance207/Flask_LDAP_View/blob/master/examples/example_Flask_LDAP_View.py).\n\n\n## Installation\n\nInstall the extension with the following command:\n\n```sh\n$ pip install Flask_LDAP_View\n```\n\n\n## Usage\n\nWe start the Flask LDAP View by instantiating it and telling it about our Flask app:\n\n```python\nfrom flask import Flask, g, redirect, session\nfrom Flask_LDAP_View import LDAP_VIEW\n\n\napp = Flask(__name__)\n\nldap = LDAP_VIEW(app)\n```\n\nNext we have to import our LDAP configuration \n\n```python\n#Service account to search ldap tree\napp.config['LDAP_HOST'] = 'ldap://127.0.0.1:389/'\napp.config['LDAP_BASE_DN'] = 'OU=Admins,OU=Users,DC=exampleDC,DC=local'\napp.config['LDAP_USERNAME'] = 'CN=User,OU=Admins,OU=Users,DC=exampleDC,DC=local'\napp.config['LDAP_PASSWORD'] = 'password'\n\n#Splash page to appear when user access a unauthorized resource\napp.config['LDAP_UNAUTHORIZED_REDIRECT'] = '/unauthorized'\n```\n\nAfter that we will add our before request,views, and login\n```python\n\n@app.before_request\ndef before_request():\n try:\n g.user_memberof = session['user_memberof']\n except:\n session['user_memberof'] = None\n g.user_memberof = session['user_memberof']\n \n\n@app.route('/')\ndef index():\n return 'Successfully logged in!'\n \n@app.route('/unauthorized')\ndef unauthorized():\n return 'You are unauthorized to access this page'\n \n\ndef login():\n if current_user.is_authenticated:\n return redirect(url_for('index'))\n if request.method == 'POST':\n username = request.form['user']\n passwd = request.form['passwd']\n g.user_memberof = ldap.bind_user(username, passwd)\n if type(g.user_memberof) == ValueError:\n flash(g.user_memberof.message)\n return redirect('/login')\n session['user_memberof'] = g.user_memberof\n flash('You have successfully logged in')\n return redirect('/')\n else:\n redirect('/login')\n return \"\"\"
\n user:
\n password:
\n
\"\"\"\n\n```\n\nNow we're ready to define our views. In this example we are restricting access to the \nQA group\n \n```python\n@app.route('/group')\n@ldap.group_required(['QA'])\ndef group():\n return 'You have been granted access to the Group restricted page '\n```\n\nYou keep even use Flask-Login alongside with it.\n\n```python\n@app.route('/group')\n@login_required\n@ldap.group_required(['QA'])\ndef group():\n return 'You have been granted access to the Group restricted page '\n```\n\nA more full example that includes Flask-Login can be found [here](https://github.com/sonance207/Flask_LDAP_View/blob/master/examples/example_Flask_LDAP_View.py).\n", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/sonance207/Flask_LDAP_View/tarball/0.3", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/sonance207/Flask_LDAP_View", "keywords": "Flask,LDAP,Security", "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "Flask_LDAP_View", "package_url": "https://pypi.org/project/Flask_LDAP_View/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/Flask_LDAP_View/", "project_urls": { "Download": "https://github.com/sonance207/Flask_LDAP_View/tarball/0.3", "Homepage": "https://github.com/sonance207/Flask_LDAP_View" }, "release_url": "https://pypi.org/project/Flask_LDAP_View/0.3/", "requires_dist": null, "requires_python": null, "summary": "A library to restrict your flask pages by LDAP groups", "version": "0.3" }, "last_serial": 2198322, "releases": { "0.2": [], "0.3": [ { "comment_text": "", "digests": { "md5": "34e19c7a4dc5717b950c9e434243e3b7", "sha256": "8a3aa09316a12a9d3af1a06014a93df7ffc4ab6f744b0f57853f557ec15a6f32" }, "downloads": -1, "filename": "Flask_LDAP_View-0.3.tar.gz", "has_sig": false, "md5_digest": "34e19c7a4dc5717b950c9e434243e3b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3083, "upload_time": "2016-07-01T16:17:53", "url": "https://files.pythonhosted.org/packages/84/4b/04fa34948bee69ebf14a3be760cbd8e493c779be2f68e78b755fa4a3dcd3/Flask_LDAP_View-0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "34e19c7a4dc5717b950c9e434243e3b7", "sha256": "8a3aa09316a12a9d3af1a06014a93df7ffc4ab6f744b0f57853f557ec15a6f32" }, "downloads": -1, "filename": "Flask_LDAP_View-0.3.tar.gz", "has_sig": false, "md5_digest": "34e19c7a4dc5717b950c9e434243e3b7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3083, "upload_time": "2016-07-01T16:17:53", "url": "https://files.pythonhosted.org/packages/84/4b/04fa34948bee69ebf14a3be760cbd8e493c779be2f68e78b755fa4a3dcd3/Flask_LDAP_View-0.3.tar.gz" } ] }