Skip to content
Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
publicauth
README
setup.py

README

=== Description ===
Django application that allows authenticate users through OpenID/OAuth/Facebook/Vkontakte.

Successfully used for a year in [[http://pyplanet.org/forum/django/|django]] community website.

== Requirements ==
* python >= 2.5 
* django >= 1.2 (r11807)
* [[http://bitbucket.org/offline/django-annoying/wiki/Home|django-annoying]]


== Installation ==
* Download and run python setup.py install or put publicauth directory on PYTHONPATH
* Add 'publicauth' to your INSTALLED_APPS tuple
* Add 'annoying.middlewares.RedirectMiddleware' to your MIDDLEWARE_CLASSES
* Add url(r'^auth/', include('publicauth.urls')) to your base urls.py
* Set [[PROFILE_MAPPING|FOO_PROFILE_MAPPING ]]

=== Facebook/OpenID/OAuth/Vkontakte ===
* Add 'publicauth.PublicBackend' to your AUTHENTICATION_BACKENDS
* run python manage.py syncdb

=== Facebook ===
* Install PyFacebook
* Add 'facebook.djangofb.FacebookMiddleware' to your MIDDLEWARE_CLASSES
* Go to http://www.facebook.com/developers/ and create application
* Set FACEBOOK_API_KEY and FACEBOOK_SECRET_KEY in your settings.py file.
* Add next code to your login page template (can be "templates/publicauth/login.html" if you want to use built in login view.

{{{
#!html

<a href="#" onclick="return fb_login();" id="facebook">Login with facebook</a>

<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>
<script type="text/javascript">
    FB.init("{{ request.facebook.api_key }}", "{% url publicauth-facebook-xdreceiver %}");

    function fb_login() {
        FB.Connect.requireSession(function(test) {
            window.location = "{% url publicauth-complete 'facebook' %}?next={{ request.GET.next }}";
        });
        return false;
    }
</script>


}}}

=== OpenID ===
* Install python-openid

=== OAuth (Twitter) ===
* Install python-oauth
* Go to [[http://twitter.com/oauth_clients|http://twitter.com/oauth_clients]] if you use twitter and get Consumer Key and Consumer Secret. Also you will need 3 urls, Request Token URL, Access Token Url and Authorize Url. In case of another OAuth Service Provider, find out how to generate this keys and set them in settings.py with name PROVIDER_CONSUMER_KEY, PROVIDER_CONSUMER_SECRET, PROVIDER_REQUEST_TOKEN_URL, PROVIDER_ACCESS_TOKEN_URL, PROVIDER_AUTHORIZE_URL
for example:
* TWITTER_CONSUMER_KEY = "g7ajf7OPlUzhMM9JBPk3ZQ"
* TWITTER_CONSUMER_SECRET = "MCKHvJquCldbTjLG3rCwyVwWhsQkaX1X8JQy83dDHQ"
* TWITTER_REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token"
* TWITTER_ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token"
* TWITTER_AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize"
* TWITTER_API_URL = "http://api.twitter.com/1/users/show.json?user_id=%s"


=== Vkontakte ===

* Create application in vkontakte.ru webiste and set in your settings.py file next variables (replace values with yours)

{{{
#!python

VKONTAKTE_APP_ID = XXXX
VKONTAKTE_API_KEY = "XXXX"
VKONTAKTE_SECRET_KEY = "XXXXXXXXX"

}}}
* Note that VKONTAKTE_APP_ID is integer, not a string, also this is the case in template below
* Then add folowing html to your login page

{{{
#!html

<a onclick="return vk_login();" href="#">Вконтакте.ru</a><


<script src="http://vkontakte.ru/js/api/openapi.js" type="text/javascript" charset="windows-1251"></script>
<script type="text/javascript">
VK.init({
    apiId: xxxxx,
    nameTransportPath: '{% url publicauth-vkontakte-xdreceiver %}'
});

function vk_login() {
    VK.Auth.login(testMe);
    return false;
}

function testMe(response) {
    if (response.status == "connected") {
        window.location = "{% url publicauth-complete 'vkontakte' %}"
    }
};
</script>


}}}

=== Defaults ===
By default every authentication method is allowed. To configure specific backends, please set 
PUBLICAUTH_BACKEND_MAPPING in your settings.py file. To see example, go to [[http://bitbucket.org/offline/django-publicauth/src/tip/publicauth/settings.py#cl-163|publicauth.settings.py]] file

=== Note ===
You need to setup [[http://docs.djangoproject.com/en/dev/ref/contrib/messages/#ref-contrib-messages|messages framework]] as described in django documentation 
Something went wrong with that request. Please try again.