Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
__init__.py52 linesDownload Raw Back to flask_client
1from werkzeug.local import LocalProxy2from .integration import FlaskIntegration, token_update3from .apps import FlaskOAuth1App, FlaskOAuth2App4from ..base_client import BaseOAuth, OAuthError5 6 7class OAuth(BaseOAuth):8    oauth1_client_cls = FlaskOAuth1App9    oauth2_client_cls = FlaskOAuth2App10    framework_integration_cls = FlaskIntegration11 12    def __init__(self, app=None, cache=None, fetch_token=None, update_token=None):13        super().__init__(14            cache=cache, fetch_token=fetch_token, update_token=update_token)15        self.app = app16        if app:17            self.init_app(app)18 19    def init_app(self, app, cache=None, fetch_token=None, update_token=None):20        """Initialize lazy for Flask app. This is usually used for Flask application21        factory pattern.22        """23        self.app = app24        if cache is not None:25            self.cache = cache26 27        if fetch_token:28            self.fetch_token = fetch_token29        if update_token:30            self.update_token = update_token31 32        app.extensions = getattr(app, 'extensions', {})33        app.extensions['authlib.integrations.flask_client'] = self34 35    def create_client(self, name):36        if not self.app:37            raise RuntimeError('OAuth is not init with Flask app.')38        return super().create_client(name)39 40    def register(self, name, overwrite=False, **kwargs):41        self._registry[name] = (overwrite, kwargs)42        if self.app:43            return self.create_client(name)44        return LocalProxy(lambda: self.create_client(name))45 46 47__all__ = [48    'OAuth', 'FlaskIntegration',49    'FlaskOAuth1App', 'FlaskOAuth2App',50    'token_update', 'OAuthError',51]52 
codekingpro/portable-devtools · Team Ai