<s> """<STR_LIT>""" <EOL> from app . extensions import db <EOL> class OAuth2Client ( db . Model ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> client_id = db . Column ( db . String ( length = <NUM_LIT> ) , primary_key = True ) <EOL> client_secret = db . Column ( db . String ( length = <NUM_LIT> ) , nullable = False ) <EOL> user_id = db . Column ( db . ForeignKey ( '<STR_LIT>' , ondelete = '<STR_LIT>' ) , index = True , nullable = False ) <EOL> user = db . relationship ( '<STR_LIT>' ) <EOL> _redirect_uris = db . Column ( db . Text , default = '<STR_LIT>' , nullable = False ) <EOL> _default_scopes = db . Column ( db . Text , default = '<STR_LIT>' , nullable = False ) <EOL> @ property <EOL> def client_type ( self ) : <EOL> return '<STR_LIT>' <EOL> @ property <EOL> def redirect_uris ( self ) : <EOL> if self . _redirect_uris : <EOL> return self . _redirect_uris . split ( ) <EOL> return [ ] <EOL> @ property <EOL> def default_redirect_uri ( self ) : <EOL> redirect_uris = self . redirect_uris <EOL> if redirect_uris : <EOL> return redirect_uris [ <NUM_LIT:0> ] <EOL> return None <EOL> @ property <EOL> def default_scopes ( self ) : <EOL> if self . _default_scopes : <EOL> return self . _default_scopes . split ( ) <EOL> return [ ] <EOL> @ classmethod <EOL> def find ( cls , client_id ) : <EOL> return cls . query . get ( client_id ) <EOL> class OAuth2Grant ( db . Model ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> user_id = db . Column ( db . ForeignKey ( '<STR_LIT>' , ondelete = '<STR_LIT>' ) , index = True , nullable = False ) <EOL> user = db . relationship ( '<STR_LIT>' ) <EOL> client_id = db . Column ( <EOL> db . String ( length = <NUM_LIT> ) , <EOL> db . ForeignKey ( '<STR_LIT>' ) , <EOL> index = True , <EOL> nullable = False , <EOL> ) <EOL> client = db . relationship ( '<STR_LIT>' ) <EOL> code = db . Column ( db . String ( length = <NUM_LIT:255> ) , index = True , nullable = False ) <EOL> redirect_uri = db . Column ( db . String ( length = <NUM_LIT:255> ) , nullable = False ) <EOL> expires = db . Column ( db . DateTime , nullable = False ) <EOL> _scopes = db . Column ( db . Text , nullable = False ) <EOL> def delete ( self ) : <EOL> db . session . delete ( self ) <EOL> db . session . commit ( ) <EOL> return self <EOL> @ property <EOL> def scopes ( self ) : <EOL> if self . _scopes : <EOL> return self . _scopes . split ( ) <EOL> return [ ] <EOL> @ classmethod <EOL> def find ( cls , client_id , code ) : <EOL> return cls . query . filter_by ( client_id = client_id , code = code ) . first ( ) <EOL> class OAuth2Token ( db . Model ) : <EOL> """<STR_LIT>""" <EOL> __tablename__ = '<STR_LIT>' <EOL> id = db . Column ( db . Integer , primary_key = True ) <EOL> client_id = db . Column ( <EOL> db . String ( length = <NUM_LIT> ) , <EOL> db . ForeignKey ( '<STR_LIT>' ) , <EOL> index = True , <EOL> nullable = False , <EOL> ) <EOL> client = db . relationship ( '<STR_LIT>' ) <EOL> user_id = db . Column ( db . ForeignKey ( '<STR_LIT>' , ondelete = '<STR_LIT>' ) , index = True , nullable = False ) <EOL> user = db . relationship ( '<STR_LIT>' ) <EOL> token_type = db . Column ( db . String ( length = <NUM_LIT> ) , nullable = False ) <EOL> access_token = db . Column ( db . String ( length = <NUM_LIT:255> ) , unique = True , nullable = False ) <EOL> refresh_token = db . Column ( db . String ( length = <NUM_LIT:255> ) , unique = True , nullable = True ) <EOL> expires = db . Column ( db . DateTime , nullable = False ) <EOL> _scopes = db . Column ( db . Text , nullable = False ) <EOL> @ property <EOL> def scopes ( self ) : <EOL> if self . _scopes : <EOL> return self . _scopes . split ( ) <EOL> return [ ] <EOL> @ classmethod <EOL> def find ( cls , access_token = None , refresh_token = None ) : <EOL> if access_token : <EOL> return cls . query . filter_by ( access_token = access_token ) . first ( ) <EOL> elif refresh_token : <EOL> return cls . query . filter_by ( refresh_token = refresh_token ) . first ( ) </s>
