<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , unicode_literals <EOL> import logging <EOL> from oauthlib . common import urlencode <EOL> from . base import BaseEndpoint <EOL> from . . import errors <EOL> log = logging . getLogger ( __name__ ) <EOL> class AccessTokenEndpoint ( BaseEndpoint ) : <EOL> """<STR_LIT>""" <EOL> def create_access_token ( self , request , credentials ) : <EOL> """<STR_LIT>""" <EOL> request . realms = self . request_validator . get_realms ( <EOL> request . resource_owner_key , request ) <EOL> token = { <EOL> '<STR_LIT>' : self . token_generator ( ) , <EOL> '<STR_LIT>' : self . token_generator ( ) , <EOL> '<STR_LIT>' : '<STR_LIT:U+0020>' . join ( request . realms ) <EOL> } <EOL> token . update ( credentials ) <EOL> self . request_validator . save_access_token ( token , request ) <EOL> return urlencode ( token . items ( ) ) <EOL> def create_access_token_response ( self , uri , http_method = '<STR_LIT:GET>' , body = None , <EOL> headers = None , credentials = None ) : <EOL> """<STR_LIT>""" <EOL> resp_headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } <EOL> try : <EOL> request = self . _create_request ( uri , http_method , body , headers ) <EOL> valid , processed_request = self . validate_access_token_request ( <EOL> request ) <EOL> if valid : <EOL> token = self . create_access_token ( request , credentials or { } ) <EOL> self . request_validator . invalidate_request_token ( <EOL> request . client_key , <EOL> request . resource_owner_key , <EOL> request ) <EOL> return resp_headers , token , <NUM_LIT:200> <EOL> else : <EOL> return { } , None , <NUM_LIT> <EOL> except errors . OAuth1Error as e : <EOL> return resp_headers , e . urlencoded , e . status_code <EOL> def validate_access_token_request ( self , request ) : <EOL> """<STR_LIT>""" <EOL> self . _check_transport_security ( request ) <EOL> self . _check_mandatory_parameters ( request ) <EOL> if not request . resource_owner_key : <EOL> raise errors . InvalidRequestError ( <EOL> description = '<STR_LIT>' ) <EOL> if not self . request_validator . check_request_token ( <EOL> request . resource_owner_key ) : <EOL> raise errors . InvalidRequestError ( <EOL> description = '<STR_LIT>' ) <EOL> if not request . verifier : <EOL> raise errors . InvalidRequestError ( <EOL> description = '<STR_LIT>' ) <EOL> if not self . request_validator . check_verifier ( request . verifier ) : <EOL> raise errors . InvalidRequestError ( <EOL> description = '<STR_LIT>' ) <EOL> if not self . request_validator . validate_timestamp_and_nonce ( <EOL> request . client_key , request . timestamp , request . nonce , request , <EOL> request_token = request . resource_owner_key ) : <EOL> return False , request <EOL> valid_client = self . request_validator . validate_client_key ( <EOL> request . client_key , request ) <EOL> if not valid_client : <EOL> request . client_key = self . request_validator . dummy_client <EOL> valid_resource_owner = self . request_validator . validate_request_token ( <EOL> request . client_key , request . resource_owner_key , request ) <EOL> if not valid_resource_owner : <EOL> request . resource_owner_key = self . request_validator . dummy_request_token <EOL> valid_verifier = self . request_validator . validate_verifier ( <EOL> request . client_key , <EOL> request . resource_owner_key , <EOL> request . verifier , <EOL> request ) <EOL> valid_signature = self . _check_signature ( request , is_token_request = True ) <EOL> request . validator_log [ '<STR_LIT>' ] = valid_client <EOL> request . validator_log [ '<STR_LIT>' ] = valid_resource_owner <EOL> request . validator_log [ '<STR_LIT>' ] = valid_verifier <EOL> request . validator_log [ '<STR_LIT>' ] = valid_signature <EOL> v = all ( ( valid_client , valid_resource_owner , valid_verifier , <EOL> valid_signature ) ) <EOL> if not v : <EOL> log . info ( "<STR_LIT>" ) <EOL> log . info ( "<STR_LIT>" , valid_client ) <EOL> log . info ( "<STR_LIT>" , valid_resource_owner ) <EOL> log . info ( "<STR_LIT>" , valid_verifier ) <EOL> log . info ( "<STR_LIT>" , valid_signature ) <EOL> return v , request </s>
