#NEWLINE# def add_access_token( self , client_id , user_id , access_lifetime , refresh_token = None , refresh_lifetime = None , expires_refresh = None , the_scope = None ) : #NEWLINE# #INDENT# 'Generates an access token and adds it to the database. If the refresh\n        token does not exist, it will create one. The method takes 6 arguments:\n        * The client application ID\n        * The user ID\n        * The access token lifetime\n        * [OPTIONAL] The refresh token\n        * [OPTIONAL] The refresh token lifetime\n        * [OPTIONAL] The the_scope of the access\n        ' #NEWLINE# now = datetime . datetime . now ( ) #NEWLINE# access_token = self . generate_hash_512 ( ) #NEWLINE# while self . get_access_token ( access_token ) : #NEWLINE# #INDENT# access_token = self . generate_hash_512 ( ) #NEWLINE# #UNINDENT# expires_access = add_seconds_to_date ( access_token , access_lifetime ) #NEWLINE# if ( not refresh_token ) : #NEWLINE# #INDENT# refresh_token = self . generate_hash_512 ( ) #NEWLINE# while self . get_refresh_token ( refresh_token ) : #NEWLINE# #INDENT# refresh_token = self . generate_hash_512 ( ) #NEWLINE# #UNINDENT# expires_refresh = add_seconds_to_date ( now , refresh_lifetime ) #NEWLINE# #UNINDENT# self . db . tokens . update_or_insert ( ** { #NEWLINE# #INDENT# 'refresh_token' : referesh_token , #NEWLINE# 'client_id' : client_id , #NEWLINE# 'user_id' : user_id , #NEWLINE# 'expires_access' : expires_access , #NEWLINE# 'expires_refresh' : expires_refresh , #NEWLINE# 'the_scope' : the_scope , #NEWLINE# 'access_token' : access_token , #NEWLINE# #UNINDENT# } ) #NEWLINE# return ( access_token , refresh_token , expires_access )