Skip to content

yangzhaofeng/Flask-PAM

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask-PAM

Flask-PAM is a plugin for Flask microframework which enables authentication using Linux's PAM (Pluggable Authentication Module). You can check if user:

  • is authenticated
  • is in specified group

using views' decorators.

Installation

To install Flask-PAM you should use setup.py script:

python setup.py install

If you use Python's virtual environments don't forget to activate it using this command:

source bin/activate

in virtualenv's directory.

Usage

Firstly, you have initialize flask_pam.Auth object and choose storage type for tokens and type of token:

from flask import Flask
 
from flask_pam import Auth
from flask_pam.token import Simple
from flask_pam.token_storage import DictStorage

app = Flask(__name__)
auth = Auth(DictStorage, Simple, app)

When you write a view which requires authentication, you have to use auth_required decorator:

@app.route('/protected')
@auth.auth_requied
def protected_view():
    ....

When you want to require user to be a member of some group, you use group_required decorator.

@app.route('/group_protected')
@auth.group_protected('wheel')
def group_protected_view():
    ....

Please use Flask-Login instead.

Important! User who runs Flask application need to have access to /etc/shadow file. In some cases it's only needed to add that user to shadow group. Sometimes you have to create that group and change group of /etc/shadow file and then add user to that group. If your system has full libpam support, access to /etc/shadow is not required.

Example

You can check example which is located in example directory.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.0%
  • Shell 1.0%