1
from .oauth import BaseOAuth2
4
class DigitalOceanOAuth(BaseOAuth2):
6
DigitalOcean OAuth authentication backend.
8
Docs: https://developers.digitalocean.com/documentation/oauth/
11
AUTHORIZATION_URL = 'https://cloud.digitalocean.com/v1/oauth/authorize'
12
ACCESS_TOKEN_URL = 'https://cloud.digitalocean.com/v1/oauth/token'
13
ACCESS_TOKEN_METHOD = 'POST'
16
('expires_in', 'expires_in')
19
def get_user_id(self, details, response):
20
"""Return user unique id provided by service"""
21
return response['account'].get('uuid')
23
def get_user_details(self, response):
24
"""Return user details from DigitalOcean account"""
25
fullname, first_name, last_name = self.get_user_names(
26
response.get('name') or '')
28
return {'username': response['account'].get('email'),
29
'email': response['account'].get('email'),
31
'first_name': first_name,
32
'last_name': last_name}
34
def user_data(self, token, *args, **kwargs):
35
"""Loads user data from service"""
36
url = 'https://api.digitalocean.com/v2/account'
37
auth_header = {"Authorization": "Bearer %s" % token}
39
return self.get_json(url, headers=auth_header)