Package: django-odesk-auth
Simple oDesk (now Upwork) login for your Django-based project.At current version it has inflexible and impossible to disable access control.
It suits my own needs so far but I plan to improve on this, given demand.Tested with Django 1.6.Note: oDesk rebranded as Upwork.Version 0.2.0 of this library depends onpython-upworkinstead ofpython-odesk,
and therefore works with new API endpoints.
Further support and development, if any, will only be continued for newdjango-upwork-auth, which is in the works. (See issue #4.)Creating oDesk OAuth API keyGo tohttps://www.odesk.com/services/api/apply.Authentication type should be set to “OAuth 1.0”.Callback URL should be left blank.Permission “View the structure of your companies/teams” is currently
required to be checked.Quick startProvided you have installeddjango-odesk-authandpython-upwork==1.0.Adddjango_odesk_authto INSTALLED_APPS.
Make sure you havedjango.contrib.sitesapp in INSTALLED_APPS as well.Adddjango_odesk_auth.backends.ODeskOAuthBackendto AUTHENTICATION_BACKENDS.SpecifyODESK_OAUTH_KEYandODESK_OAUTH_SECRETsettings
with your key information.Addyour_username@odesk.comtoODESK_AUTH_ALLOWED_USERS,
and setODESK_AUTH_CREATE_UNKNOWN_USERto True.Includedjango_odesk_auth.urlsin your URL patterns.In your login page template, put a link “Log in via oDesk” and point it
to{% url "odesk_oauth_login" %}.Open login page and click “Log in via oDesk” to verify everything works.Important: keepODESK_OAUTH_KEYandODESK_OAUTH_SECRETsettings in a file
that is not under version control.Example projectRequirements: Vagrant, Ansible, and free 8000 port.First, fill in some critical settings inexample_project/settings.py(see comments in the file).From example_project directory, bring up a VM using provided Vagrantfile
and run Django development server on it:$ vagrant up
$ vagrant ssh
vm$ cd /vagrant/example_project/
vm$ ./manage.py runserver 0.0.0.0:8000On your host machine, navigate to 127.0.0.1:8000 and you should be able
to test Upwork login functionality.Access controlApp has basic access control facilities.You can specify who is allowed to log in to your site and who upon login gets
staff and/or superuser statuses. This is configured through Django settings.Currently access control cannot be turned off.
Youhaveto explicitly specify at least who is allowed to log in to your site.
(Yes, this means you can’t grant access to everyone yet, unless you hack the app.)Users that aren’t allowed to log in getUser.is_activeflag set to False.
Seeutils.update_user_permissions()definition if you’re interested in other specifics,
and see available settings below.Making authenticated oDesk API callsAfter user is successfully authenticated, you can call oDesk API on their behalf.Here’s a quick example:from django_odesk_auth import utils, O_ACCESS_TOKEN

odesk_client = utils.get_client(request.session[O_ACCESS_TOKEN])
print odesk_client.hr.get_teams()
# Should output list of teams user has access toSome notes:How you make API calls is up to you. Internally django-odesk-auth
uses python-upwork library, and so does this example.utils.get_client()function returns an instance ofupwork.Client.
Handy if you’re using python-upwork library to make API calls.OAuth access token, obtained during authentication, is stored
underrequest.session[O_ACCESS_TOKEN].Checking OAuth access tokenSometimes there’s a need to make sure that current user’s authentication
is still valid—that they, for example, didn’t revoke access to their account.For that you can useutils.check_login()in Python, or make an AJAX request
to named URL'odesk_oauth_check_login'from client side
(seeviews.oauth_check_login).Available Django settingsODESK_OAUTH_KEY, ODESK_OAUTH_SECRETAPI key information.ODESK_AUTH_CREATE_UNKNOWN_USER = FalseWhether to create a new account in Django if given user logs in via oDesk
for the first time.ODESK_AUTH_ALLOWED_USERS = ()oDesk emails of users who are allowed to log in via oDesk.ODESK_AUTH_ADMINS = ()oDesk emails of users who are marked asis_staffupon login.ODESK_AUTH_SUPERUSERS = ()oDesk emails of users who are marked asis_superuserupon login.ODESK_AUTH_ALLOWED_TEAMS = ()IDs of oDesk teams, members of which are allowed to log in via oDesk.ODESK_AUTH_ADMIN_TEAMS = ()IDs of oDesk teams, members of which are marked asis_staffupon login.ODESK_AUTH_SUPERUSER_TEAMS = ()IDs of oDesk teams, members of which are marked asis_superuserupon login.