Create an ``exists_nonce`` function that can be used in hooks and resource protector. :param cache: Cache instance :param key_prefix: key prefix for temporary credential :param expires: Expire time for nonce
(cache, key_prefix="nonce:", expires=86400)
| 55 | |
| 56 | |
| 57 | def create_exists_nonce_func(cache, key_prefix="nonce:", expires=86400): |
| 58 | """Create an ``exists_nonce`` function that can be used in hooks and |
| 59 | resource protector. |
| 60 | |
| 61 | :param cache: Cache instance |
| 62 | :param key_prefix: key prefix for temporary credential |
| 63 | :param expires: Expire time for nonce |
| 64 | """ |
| 65 | |
| 66 | def exists_nonce(nonce, timestamp, client_id, oauth_token): |
| 67 | key = f"{key_prefix}{nonce}-{timestamp}-{client_id}" |
| 68 | if oauth_token: |
| 69 | key = f"{key}-{oauth_token}" |
| 70 | rv = cache.has(key) |
| 71 | cache.set(key, 1, timeout=expires) |
| 72 | return rv |
| 73 | |
| 74 | return exists_nonce |
| 75 | |
| 76 | |
| 77 | def register_nonce_hooks( |
no outgoing calls
no test coverage detected