#NEWLINE# def token_endpoint( self , request = '' , authn = None , dtype = 'urlencoded' , **kwargs ) : #NEWLINE# #INDENT# '\n        This is where clients come to get their access tokens\n\n        :param request: The request\n        :param authn: Authentication info, comes from HTTP header\n        :returns:\n        ' #NEWLINE# logger . debug ( '- token -' ) #NEWLINE# logger . info ( ( 'token_request: %s' % request ) ) #NEWLINE# req = AccessTokenRequest ( ) . deserialize ( request , dtype ) #NEWLINE# if ( 'state' in req ) : #NEWLINE# #INDENT# if ( self . sdb [ req [ 'code' ] ] [ 'state' ] != req [ 'state' ] ) : #NEWLINE# #INDENT# err = TokenErrorResponse ( error = 'unauthorized_client' ) #NEWLINE# return Unauthorized ( err . to_json ( ) , content = 'application/json' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( 'refresh_token' in req ) : #NEWLINE# #INDENT# req = RefreshAccessTokenRequest ( ) . deserialize ( request , dtype ) #NEWLINE# #UNINDENT# logger . debug ( ( '%s: %s' % ( req . __class__ . __name__ , req ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# client_id = self . client_authn ( self , req , authn ) #NEWLINE# msg = '' #NEWLINE# #UNINDENT# except Exception as err : #NEWLINE# #INDENT# msg = 'Failed to verify client due to: {}' . format ( err ) #NEWLINE# logger . error ( msg ) #NEWLINE# client_id = '' #NEWLINE# #UNINDENT# if ( not client_id ) : #NEWLINE# #INDENT# err = TokenErrorResponse ( error = 'unauthorized_client' , error_description = msg ) #NEWLINE# return Unauthorized ( err . to_json ( ) , content = 'application/json' ) #NEWLINE# #UNINDENT# if ( 'client_id' not in req ) : #NEWLINE# #INDENT# req [ 'client_id' ] = client_id #NEWLINE# #UNINDENT# if isinstance ( req , AccessTokenRequest ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# return self . _access_token_endpoint ( req , ** kwargs ) #NEWLINE# #UNINDENT# except JWEException as err : #NEWLINE# #INDENT# return self . _error_response ( 'invalid_request' , descr = ( '%s' % err ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# return self . _refresh_access_token_endpoint ( req , ** kwargs )