A protecting method for resource servers. Initialize a resource protector with the these method: 1. query_client 2. query_token, 3. exists_nonce Usually, a ``query_client`` method would look like (if using SQLAlchemy):: def query_client(client_id): return C
| 12 | |
| 13 | |
| 14 | class ResourceProtector(_ResourceProtector): |
| 15 | """A protecting method for resource servers. Initialize a resource |
| 16 | protector with the these method: |
| 17 | |
| 18 | 1. query_client |
| 19 | 2. query_token, |
| 20 | 3. exists_nonce |
| 21 | |
| 22 | Usually, a ``query_client`` method would look like (if using SQLAlchemy):: |
| 23 | |
| 24 | def query_client(client_id): |
| 25 | return Client.query.filter_by(client_id=client_id).first() |
| 26 | |
| 27 | A ``query_token`` method accept two parameters, ``client_id`` and ``oauth_token``:: |
| 28 | |
| 29 | def query_token(client_id, oauth_token): |
| 30 | return Token.query.filter_by( |
| 31 | client_id=client_id, oauth_token=oauth_token |
| 32 | ).first() |
| 33 | |
| 34 | And for ``exists_nonce``, if using cache, we have a built-in hook to create this method:: |
| 35 | |
| 36 | from authlib.integrations.flask_oauth1 import create_exists_nonce_func |
| 37 | |
| 38 | exists_nonce = create_exists_nonce_func(cache) |
| 39 | |
| 40 | Then initialize the resource protector with those methods:: |
| 41 | |
| 42 | require_oauth = ResourceProtector( |
| 43 | app, |
| 44 | query_client=query_client, |
| 45 | query_token=query_token, |
| 46 | exists_nonce=exists_nonce, |
| 47 | ) |
| 48 | """ |
| 49 | |
| 50 | def __init__( |
| 51 | self, app=None, query_client=None, query_token=None, exists_nonce=None |
| 52 | ): |
| 53 | self.query_client = query_client |
| 54 | self.query_token = query_token |
| 55 | self._exists_nonce = exists_nonce |
| 56 | |
| 57 | self.app = app |
| 58 | if app: |
| 59 | self.init_app(app) |
| 60 | |
| 61 | def init_app(self, app, query_client=None, query_token=None, exists_nonce=None): |
| 62 | if query_client is not None: |
| 63 | self.query_client = query_client |
| 64 | if query_token is not None: |
| 65 | self.query_token = query_token |
| 66 | if exists_nonce is not None: |
| 67 | self._exists_nonce = exists_nonce |
| 68 | |
| 69 | methods = app.config.get("OAUTH1_SUPPORTED_SIGNATURE_METHODS") |
| 70 | if methods and isinstance(methods, (list, tuple)): |
| 71 | self.SUPPORTED_SIGNATURE_METHODS = methods |
no outgoing calls
no test coverage detected
searching dependent graphs…