diff --git a/docs/backends/docker.rst b/docs/backends/docker.rst new file mode 100644 index 000000000..8e4714354 --- /dev/null +++ b/docs/backends/docker.rst @@ -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 diff --git a/social/backends/docker.py b/social/backends/docker.py new file mode 100644 index 000000000..e1d28e88a --- /dev/null +++ b/social/backends/docker.py @@ -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}) \ No newline at end of file