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 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, please open an enhancement issue or consider a contribution to this module by implementing one by yourself. Its very easy and shouldn’t take you more than a few minutes.
-
class
authomatic.adapters.
DjangoAdapter
(request, response)[source]¶ Adapter for the Django framework.
Parameters: - request – An instance of the
django.http.HttpRequest
class. - response – An instance of the
django.http.HttpResponse
class.
-
url
¶ Must return the url of the actual request including path but without query and fragment.
Returns: str
-
write
(value)[source]¶ Must write specified value to response.
Parameters: value (str) – String to be written to response.
- request – An instance of the
-
class
authomatic.adapters.
Webapp2Adapter
(handler)[source]¶ Adapter for the Webapp2 framework.
Inherits from the
WebObAdapter
.Parameters: handler – A webapp2.RequestHandler
instance.
-
class
authomatic.adapters.
WebObAdapter
(request, response)[source]¶ Adapter for the WebOb package.
Parameters: -
url
¶ Must return the url of the actual request including path but without query and fragment.
Returns: str
-
write
(value)[source]¶ Must write specified value to response.
Parameters: value (str) – String to be written to response.
-
-
class
authomatic.adapters.
WerkzeugAdapter
(request, response)[source]¶ Adapter for Flask and other Werkzeug based frameworks.
Thanks to Mark Steve Samson.
Parameters: - request – Instance of the
werkzeug.wrappers.Request
class. - response – Instance of the
werkzeug.wrappers.Response
class.
-
url
¶ Must return the url of the actual request including path but without query and fragment.
Returns: str
-
write
(value)[source]¶ Must write specified value to response.
Parameters: value (str) – String to be written to response.
- request – Instance of the
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 six members that you need to implement.
Moreover if your framework is based on the WebOb or Werkzeug package
you can subclass the WebObAdapter
or WerkzeugAdapter
respectively.
-
class
authomatic.adapters.
BaseAdapter
[source]¶ Base class for platform adapters.
Defines common interface for WSGI framework specific functionality.
-
url
¶ Must return the url of the actual request including path but without query and fragment.
Returns: str
-
write
(value)[source]¶ Must write specified value to response.
Parameters: value (str) – String to be written to response.
-