Getting Started - PlaidWeb/Authl GitHub Wiki
Getting started
using Flask
def setup(app,
config,
login_name='authl.login',
login_path='/login',
callback_name='authl.callback',
callback_path='/cb',
tester_name='authl.test',
tester_path=None,
login_render_func=None,
notify_render_func=None,
session_auth_name='me',
force_ssl=False,
stylesheet=None
):
""" Setup Authl to work with a Flask application.
The Flask application should be configured with a secret_key before this
function is called.
Arguments:
app -- the application to attach to
config -- Configuration directives for Authl's handlers. See from_config
for more information.
login_name -- The endpoint name for the login handler, for flask.url_for()
login_path -- The mount point of the login route
callback_name -- The endpoint name for the callback handler, for
flask.url_for()
callback_path -- The mount point of the callback handler
tester_name -- The endpoint name for the URL tester, for flask.url_for()
tester_path -- The mount point of the URL tester
login_render_func -- The function to call to render the login page; if not
specified a default will be provided.
notify_render_func -- The function to call to render the user notification
page; if not specified a default will be provided.
session_auth_name -- The session parameter to use for the authenticated user
force_ssl -- Whether to force authentication to switch to an SSL connection
stylesheet -- the URL to use for the default page stylesheet
The login_render_func takes the following arguments:
login_url -- the URL to use for the login form
auth -- the Authl object
The render_notify_func takes the following arguments:
cdata -- the client data for the handler
The login endpoint takes a query parameter of 'me' which is the URL to
authenticate against.
The URL tester endpoint takes a query parameter of 'url' which is the URL
to check. It returns a JSON object that describes the detected handler, with
the following attributes:
name -- the service name
url -- a canonicized version of the URL
The URL tester endpoint will only be mounted if tester_path is specified.
Return value: the configured Authl instance
"""
Simple example
This configures your Flask app (named app
) to enable email sent via localhost, IndieLogin that will work from http://localhost
, Mastodon with a very generic configuration, and the loopback test handler.
import authl.flask
app.secret_key = str(uuid.uuid4())
authl.flask.setup(
app,
{
'SMTP_HOST': 'localhost',
'SMTP_PORT': 25,
'EMAIL_FROM': '[email protected]',
'EMAIL_SUBJECT': 'Login attempt for Authl test',
'INDIELOGIN_CLIENT_ID': 'http://localhost',
'TEST_ENABLED': True,
'MASTODON_NAME': 'authl testing',
'MASTODON_HOMEPAGE': 'https://github.com/PlaidWeb/Authl'
}
)