Skip to main content

Genericized multi-protocol authentication wrapper

Project description

Authl

A library for managing federated identity

About

Authl is intended to make it easy to add federated identity to Python-based web apps without requiring the creation of site-specific user accounts, but also without requiring the user to choose from a myriad of buttons or links to select any specific login provider.

All it should take is a single login form that asks for how the user wants to be identified.

Current state

Currently supported authentication mechanisms:

  • Directly authenticating against email using a magic link
  • Federated authentication against IndieLogin
  • Federated authentcation against Mastodon
  • Test/loopback authentication for development purposes

It also provides an easy setup mechanism for use with Flask.

Rationale

Identity is hard, and there are so many competing standards which try to be the be-all end-all Single Solution. OAuth and OpenID Connect want lock-in to silos, IndieAuth wants every user to self-host their own identity site, and OpenID 1.x has fallen by the wayside. Meanwhile, users just want to be able to log in with the social media they're already using (siloed or not).

Any solution which requires all users to have a certain minimum level of technical ability is not a workable solution.

All of these solutions are prone to the so-called "NASCAR problem" where every supported login provider needs its own UI. But being able to experiment with a more unified UX might help to fix some of that.

Usage

Basic usage is as follows:

  1. Create an Authl object with your configured handlers

    This can be done by instancing individual handlers yourself, or you can use authl.from_config

  2. Make endpoints for initiation and progress callbacks

    The initiation callback receives an identity string (email address/URL/etc.) from the user, queries Authl for the handler and its ID, and builds a callback URL for that handler to use. Typically you'll have a single callback endpoint that includes the handler's ID as part of the URL scheme.

    The callback endpoint needs to be able to receive a GET or POST request and use that to validate the returned data from the authorization handler.

    Your callback endpoint (and generated URL thereof) should also include whatever intended forwarding destination.

  3. Handle the authl.disposition object types accordingly

    A disposition is what should be done with the agent that initiated the endpoint call. Currently there are the following:

    • Redirect: return an HTTP redirection to forward it along to another URL
    • Notify: return a notification to the user that they must take another action (e.g. check their email)
    • Verified: indicates that the user has been verified; set a session cookie (or whatever) and forward them along to their intended destination
    • Error: An error occurred; return it to the user as appropriate

Flask usage

To make life easier with Flask, Authl provides an authl.setup_flask convenience function. You can use it from a Flask app with something like the below:

import uuid
import logging

import flask
import authl.flask

logging.basicConfig(level=logging.INFO)
LOGGER = logging.getLogger(__name__)

# Create a Flask application and give it a randomly-generated signing key
app = flask.Flask('authl-test')
app.secret_key = str(uuid.uuid4())

# Configure the default Flask endpoints
authl.flask.setup(
    app,
    {
        'SMTP_HOST': 'localhost',
        'SMTP_PORT': 25,
        'EMAIL_FROM': 'nobody@example.com',
        'EMAIL_SUBJECT': 'Login attempt for Authl test',
        'INDIELOGIN_CLIENT_ID': 'http://localhost',
        'MASTODON_NAME': 'Authl test site'
    },
)

# Here's a simple page handler which just shows a login link if you're logged out
# and vice versa
@app.route('/')
@app.route('/some-page')
def index():
    if 'me' in flask.session:
        return 'Hello {me}. Want to <a href="{logout}">log out</a>?'.format(
            me=flask.session['me'],
            logout=flask.url_for('logout', redir=flask.request.path[1:])
        )

    return 'You are not logged in. Want to <a href="{login}">log in</a>?'.format(
        login=flask.url_for('login', redir=flask.request.path[1:]))

# And here's a means of logging out
@app.route('/logout/')
@app.route('/logout/<path:redir>')
def logout(redir=''):
    flask.session.clear()
    return flask.redirect('/' + redir)

This will configure the Flask app to allow IndieLogin and email-based authentication (using the server's local sendmail), and use the default login endpoint of /login/. The index() endpoint handler always redirects logins and logouts back to the same page when you log in or log out (the [1:] is to trim off the initial / from the path). The logout handler simply clears the session and redirects back to the redirection path.

The above configuration uses Flask's default session lifetime of one month (this can be configured by setting app.permanent_session_lifetime to a timedelta object, e.g. app.permanent_session_lifetime = datetime.timedelta(hours=20)). Sessions will also implicitly expire whenever the application server is restarted, as app.secret_key is generated randomly at every startup.

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

Authl-0.1.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

Authl-0.1.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file Authl-0.1.1.tar.gz.

File metadata

  • Download URL: Authl-0.1.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for Authl-0.1.1.tar.gz
Algorithm Hash digest
SHA256 95f37df69881f7e43a6e7267ab80ce8ecd8fbea1e44b29746a25e159f000e830
MD5 43b2e173ac6aa9266259396bc76446dc
BLAKE2b-256 f88abb425b6b9d86ad485ed6e6381c0f1b53c7b27573b359ac53e5f9498c0245

See more details on using hashes here.

File details

Details for the file Authl-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: Authl-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for Authl-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce14877e14072278fb051eb452c6adf25e9f182ff71e9ddd15e6995e5c44e702
MD5 93172201307e23b62f8cfc5c0e98f096
BLAKE2b-256 cf29c4e3879adf9601c9d33edecd0ce058f1c26b03dc43d67372f81dd3035d61

See more details on using hashes here.

Supported by

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