#NEWLINE# def get_or_create_token( self , user , * args , **kwargs ) : #NEWLINE# #INDENT# def get_token( user ) : #NEWLINE# #INDENT# return self . token_backend . get_token_by_username ( 'admin' , username = user . username ) #NEWLINE# #UNINDENT# def create_token( user , * args , **kwargs ) : #NEWLINE# #INDENT# jwt_kwargs = { #NEWLINE# #INDENT# 'iss' : 'aiorest-ws' , #NEWLINE# 'exp' : 60 , #NEWLINE# 'name' : kwargs . get ( 'username' ) , #NEWLINE# 'authorized' : True , #NEWLINE# 'token_name' : 'admin' , #NEWLINE# #UNINDENT# } #NEWLINE# kwargs . update ( jwt_kwargs ) #NEWLINE# api_token = self . token_manager . generate ( { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } , ** kwargs ) #NEWLINE# self . token_backend . save ( 'admin' , api_token , user_id = user . id ) #NEWLINE# return api_token #NEWLINE# #UNINDENT# return ( get_token ( create_token ) or create_token ( user , * args , ** kwargs ) )