Adapters

The authomatic.login() function needs access to functionality like getting the URL of the handler where it is being called, getting the request params, headers and cookies and writing the body, headers and status to the response.

Since implementation of these features varies across Python web frameworks, the Authomatic library uses adapters to unify these differences into a single interface.

Available Adapters

If you are missing an adapter for the framework of your choice, which is very likely, since currently there are only the Webapp2Adapter and WerkzeugAdapter available, please consider a contribution to this module by implementing one. Its very easy and shouldn’t take you more than a few minutes.

class authomatic.adapters.Webapp2Adapter(handler)[source]

Adapter for the Webapp2 framework.

Parameters:handler – A Webapp2 RequestHandler instance.
class authomatic.adapters.WerkzeugAdapter(request, response)

Adapter for Flask and other Werkzeug based frameworks.

Thanks to Mark Steve Samson.

Parameters:

Implementing an Adapter

Implementing an adapter for a Python web framework is pretty easy.

Do it by subclassing the BaseAdapter abstract class. There are only seven members that you need to implement.

Moreover if your framework is based on the WebOb library you can subclass the WebObBaseAdapter and you only need to override the constructor.

class authomatic.adapters.BaseAdapter[source]

Base class for platform adapters

Defines common interface for WSGI framework specific functionality.

params[source]

Must return a dict of all request parameters of any HTTP method.

Returns:dict
url[source]

Must return the url of the actual request including path but without query and fragment

Returns:str
headers[source]

Must return the request headers as a dict.

Returns:dict
cookies[source]

Must return cookies as a dict.

Returns:dict
write(value)[source]

Must write specified value to response.

Parameters:value (str) – String to be written to response.
set_header(key, value)[source]

Must set response headers to Key: value.

Parameters:
  • key (str) – Header name.
  • value (str) – Header value.
set_status(status)[source]

Must set the response status e.g. '302 Found'.

Parameters:key (str) – The HTTP response status.
class authomatic.adapters.WebObBaseAdapter[source]

Abstract base class for adapters for WebOb based frameworks.

If you use this base class you only need to set the BaseAdapter.request to the WebOb Request and BaseAdapter.response to the WebOb Response in the constructor.

request[source]

Must be a WebOb Request.

response[source]

Must be a WebOb Response.

Fork me on GitHub