Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/backends/docker.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Docker
======

Docker.io OAuth2
----------------

Docker.io now supports OAuth2 for their API. In order to set it up:

- Register a new application by following the instructions in their website: `Register Your Application`_

- Fill **Consumer Key** and **Consumer Secret** values in settings::

SOCIAL_AUTH_DOCKER_KEY = ''
SOCIAL_AUTH_DOCKER_SECRET = ''

- Add ``'social.backends.docker.DockerOAuth2'`` into your
``SOCIAL_AUTH_AUTHENTICATION_BACKENDS``.

.. _Register Your Application: http://docs.docker.io/en/latest/reference/api/docker_io_oauth_api/#register-your-application
36 changes: 36 additions & 0 deletions social/backends/docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Docker.io OAuth2 backend, docs at:
http://psa.matiasaguirre.net/docs/backends/docker.html
"""
from social.backends.oauth import BaseOAuth2


class DockerOAuth2(BaseOAuth2):
name = 'docker'
ID_KEY = 'user_id'
AUTHORIZATION_URL = 'https://www.docker.io/api/v1.1/o/authorize/'
ACCESS_TOKEN_URL = 'https://www.docker.io/api/v1.1/o/token/'
REFRESH_TOKEN_URL = 'https://www.docker.io/api/v1.1/o/token/'
ACCESS_TOKEN_METHOD = 'POST'
REDIRECT_STATE = False
EXTRA_DATA = [
('refresh_token', 'refresh_token', True),
('user_id', 'user_id'),
('email', 'email'),
('full_name', 'fullname'),
('location', 'location'),
('url', 'url'),
('company', 'company'),
('gravatar_email', 'gravatar_email'),
]

def get_user_details(self, response):
"""Return user details from Docker.io account"""
return {'username': response.get('username'),
'first_name': response.get('full_name', response.get('username')),
'email': response.get('email', '')}

def user_data(self, access_token, *args, **kwargs):
"""Grab user profile information from Docker.io."""
return self.get_json('https://www.docker.io/api/v1.1/users/%s/' % kwargs['response']['username'],
headers={"Authorization": "Bearer %s" % access_token})