| 9 | |
| 10 | |
| 11 | class OAuth(BaseOAuth): |
| 12 | oauth1_client_cls = FlaskOAuth1App |
| 13 | oauth2_client_cls = FlaskOAuth2App |
| 14 | framework_integration_cls = FlaskIntegration |
| 15 | |
| 16 | def __init__(self, app=None, cache=None, fetch_token=None, update_token=None): |
| 17 | super().__init__( |
| 18 | cache=cache, fetch_token=fetch_token, update_token=update_token |
| 19 | ) |
| 20 | self.app = app |
| 21 | if app: |
| 22 | self.init_app(app) |
| 23 | |
| 24 | def init_app(self, app, cache=None, fetch_token=None, update_token=None): |
| 25 | """Initialize lazy for Flask app. This is usually used for Flask application |
| 26 | factory pattern. |
| 27 | """ |
| 28 | self.app = app |
| 29 | if cache is not None: |
| 30 | self.cache = cache |
| 31 | |
| 32 | if fetch_token: |
| 33 | self.fetch_token = fetch_token |
| 34 | if update_token: |
| 35 | self.update_token = update_token |
| 36 | |
| 37 | app.extensions = getattr(app, "extensions", {}) |
| 38 | app.extensions["authlib.integrations.flask_client"] = self |
| 39 | |
| 40 | def create_client(self, name): |
| 41 | if not self.app: |
| 42 | raise RuntimeError("OAuth is not init with Flask app.") |
| 43 | return super().create_client(name) |
| 44 | |
| 45 | def register(self, name, overwrite=False, **kwargs): |
| 46 | self._registry[name] = (overwrite, kwargs) |
| 47 | if self.app: |
| 48 | return self.create_client(name) |
| 49 | return LocalProxy(lambda: self.create_client(name)) |
| 50 | |
| 51 | |
| 52 | __all__ = [ |
no outgoing calls
searching dependent graphs…