def refresh_authorization_token(self, refresh_token): """ Exchange a refresh token for a new access token. Example response: { 'access_token': 'asdf', 'expires_in': 1209600, 'scope': 'profile', 'token_type': 'bearer'} } """ params = { 'grant_type': 'refresh_token', 'client_id': settings.FXA_CLIENT_ID, 'client_secret': settings.FXA_SECRET, 'scope': settings.FXA_SCOPE, 'refresh_token': refresh_token, } with stats_client.timer('fxa_refresh_auth_token_timing'): token_url = urlparse.urljoin(settings.FXA_OAUTH_URI, 'v1/token') response = requests.post(token_url, data=json.dumps(params)) stats_client.incr('fxa_refresh_auth_token_count') return self._parse_response(response)
def process_response(self, request, response): if hasattr(request, '_stats_start'): duration = (time.time() - request._stats_start) * 1000 view_name = getattr(request, '_stats_view_name', None) if view_name is not None: stats_client.timing( 'request_timing|{}'.format( request._stats_view_name), duration) stats_client.incr( 'request_count|{}'.format(request._stats_view_name)) return response
def process_response(self, request, response): if hasattr(request, '_stats_start'): duration = (time.time() - request._stats_start) * 1000 view_name = getattr(request, '_stats_view_name', None) if view_name is not None: stats_client.timing( 'request_timing|{}'.format(request._stats_view_name), duration) stats_client.incr('request_count|{}'.format( request._stats_view_name)) return response
def get_profile_data(self, access_token): """ Retrieve the profile details for a user given a valid access_token. Example response: { 'email': '*****@*****.**', 'uid': '92e70a0155544210a787f98a4a22f6e2' } """ headers = { 'Authorization': 'Bearer {}'.format(access_token), } with stats_client.timer('fxa_get_profile_timing'): profile_url = urlparse.urljoin( settings.FXA_PROFILE_URI, 'v1/profile') response = requests.get(profile_url, headers=headers) stats_client.incr('fxa_get_profile_count') return self._parse_response(response)
def verify_token(self, access_token): """ Verify an access token with FXA. Example response: { "user": "******", "client_id": "45defeda038a1c92", "scope": ["profile:email", "profile:avatar"], "email": "*****@*****.**" } """ with stats_client.timer('fxa_verify_auth_token_timing'): profile_url = urlparse.urljoin(settings.FXA_OAUTH_URI, 'v1/verify') response = requests.post( profile_url, {'token': access_token}, ) stats_client.incr('fxa_verify_auth_token_count') return self._parse_response(response)