File: webpy.rst

package info (click to toggle)
python-social-auth 0.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,828 kB
  • ctags: 3,245
  • sloc: python: 12,867; makefile: 119; sh: 3
file content (74 lines) | stat: -rw-r--r-- 1,946 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Webpy Framework
===============

Webpy_ framework is easy to setup, once that python-social-auth_ is installed
or accessible in the ``PYTHONPATH``, just add the needed configurations to make
it run.


Dependencies
------------

The `Webpy built-in app` depends on sqlalchemy_, there's no support for others
ORMs yet but pull-requests are welcome.


Configuration
-------------

Add the needed settings into ``web.config`` store. Settings are prefixed with
``SOCIAL_AUTH_`` but there's a helper for it::

    from social.utils import setting_name

    web.config[setting_name('USER_MODEL')] = 'models.User'
    web.config[setting_name('LOGIN_REDIRECT_URL')] = '/done/'
    web.config[setting_name('AUTHENTICATION_BACKENDS')] = (
        'social.backends.google.GoogleOAuth2',
        ...
    )

Add all the settings needed for the app (check Configuration_ section for
details).


URLs
----

Add the social application into URLs::

    from social.apps.webpy_app import app as social_app

    urls = (
        ...
        '', social_app.app_social
        ...
    )


Session
-------

python-social-auth_ depends on sessions storage to keep some essential values,
usually redirects and ``state`` parameters used to validate authentication
process on OAuth providers.

The `Webpy built-in app` expects the session reference to be available under
``web.web_session`` so ensure it's available there.


User model
----------

Like the other apps, the User model must be defined on settings since
a reference to it is kept on ``UserSocialAuth`` instance. Define like this::

    web.config[setting_name('USER_MODEL')] = 'models.User'

Where the value is the import path to the User model used on your project.


.. _python-social-auth: https://github.com/omab/python-social-auth
.. _Webpy: http://webpy.org/
.. _Webpy built-in app: https://github.com/omab/python-social-auth/tree/master/social/apps/webpy_app
.. _sqlalchemy: http://www.sqlalchemy.org/