File: nonce.py

package info (click to toggle)
python-authlib 1.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,016 kB
  • sloc: python: 26,998; makefile: 53; sh: 14
file content (15 lines) | stat: -rw-r--r-- 396 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from django.core.cache import cache


def exists_nonce_in_cache(nonce, request, timeout):
    key_prefix = "nonce:"
    timestamp = request.timestamp
    client_id = request.client_id
    token = request.token
    key = f"{key_prefix}{nonce}-{timestamp}-{client_id}"
    if token:
        key = f"{key}-{token}"

    rv = bool(cache.get(key))
    cache.set(key, 1, timeout=timeout)
    return rv