Skip to main content

Registration and authorization (including social) for aiohttp apps

Project description

This fork of imbolc/aiohttp-login is developed for the based on

JWT tokens registration and login procedures.

Moreover, the following options are added into the cfg.py for the contained in JWT roles: - "ROLES_API_BLACK_LIST": {} - for the configuration of forbiden endpoints for certain roles; - "ROLES_API_LIMITS": {} - for the configuration of API calls limits for certain roles; - "CACHE" - Redis or KeyDB object for calls counting (cache storage) (default None that means no restrictions); - "API_CALL_LIMIT_EXPIRATION_TIME" - time interval in minutes within which number calls should be restricted (default 60).

aiohttp-login

Registration and authorization (including social) for aiohttp apps

With just a few settings you’ll give for your aiohttp site:

  • registration with email confirmation

  • authorization by email or social account (facebook, google and vkontakte for now)

  • reset password by email

  • change email with confirmation

  • edit current password

You can see all of this staff alive here

Databases

You can use this lib with different database backends:

  • postgres with asyncpg

  • mongodb with motor

  • the db you need - it’s very easy to add a new backend

UI themes

The library designed to easily change UI themes. Currently bootstrap-3 and bootstrap-4 themes are available. But it’s very easy to add new themes, actually theme - is just a folder with jinja2 templates.

Installation and configuration

Just install the library from pypi:

pip install aiohttp-login

Choice and configure one of database storages.

For postgres with asyncpg:

import asyncpg
from aiohttp_login.asyncpg_storage import AsyncpgStorage

pool = await asyncpg.create_pool(dsn='postgres:///your_db')
storage = AsyncpgStorage(pool)

For mongodb with motor:

from motor.motor_asyncio import AsyncIOMotorClient
from aiohttp_login.motor_storage import MotorStorage

db = AsyncIOMotorClient(io_loop=loop)['your_db']
storage = MotorStorage(db)

Now configure the library with a few settings:

app = web.Application(loop=loop)
app.middlewares.append(aiohttp_login.flash.middleware)
aiohttp_jinja2.setup(
    app,
    loader=jinja_app_loader.Loader(),
    context_processors=[aiohttp_login.flash.context_processor],
)
aiohttp_login.setup(app, storage, {
    'CSRF_SECRET': 'secret',

    'VKONTAKTE_ID': 'your-id',
    'VKONTAKTE_SECRET': 'your-secret',
    'GOOGLE_ID': 'your-id',
    'GOOGLE_SECRET': 'your-secret',
    'FACEBOOK_ID': 'your-id',
    'FACEBOOK_SECRET': 'your-secret',

    'SMTP_SENDER': 'Your Name <your@gmail.com>',
    'SMTP_HOST': 'smtp.gmail.com',
    'SMTP_PORT': 465,
    'SMTP_USERNAME': 'your@gmail.com',
    'SMTP_PASSWORD': 'password'
})

That’s all. Look at the code in the example folder. Full list of available settings you can find in aiohttp_login/cfg.py file.

Run the example

Create a virtual environment and install the dependencies:

cd example
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Create postgres database and tables:

createdb aiohttp_login
psql -d aiohttp_login -f ../aiohttp_login/pg_tables.sql

Rename settings.py.template to settings.py and populate it with real data.

Run the server:

python app.py

Run tests

pip install -r requirements-dev.txt
py.test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp-login-jwt-1.4.1.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_login_jwt-1.4.1-py3-none-any.whl (38.9 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp-login-jwt-1.4.1.tar.gz.

File metadata

  • Download URL: aiohttp-login-jwt-1.4.1.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.3

File hashes

Hashes for aiohttp-login-jwt-1.4.1.tar.gz
Algorithm Hash digest
SHA256 f0708910c7f9244a65ecf2a770463134c9ec1d918e33272f742a288e9ff15c41
MD5 e497d9b59664d861504092c126b2fef4
BLAKE2b-256 1095fab334871023fc45f89326401f31ac0f906db68eb507aeba63d2caaa70de

See more details on using hashes here.

File details

Details for the file aiohttp_login_jwt-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_login_jwt-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 38.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.3

File hashes

Hashes for aiohttp_login_jwt-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6c262d4da386a0415906bdf3069506beed70b77dca9767ebc0affc3e5a8902f4
MD5 fa000591f094414cd6976ed865c1815c
BLAKE2b-256 5f119b5ccc7029e98be44eda740a872dc5feb2ee7ca80d057871a67674ecb65f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page