PHP 8.2.30
Preview: jwt_identity.py Size: 1.18 KB
//opt/cloudlinux/venv/lib/python3.11/site-packages/aiohttp_security/jwt_identity.py

"""Identity policy for storing info in the jwt token.

"""

from .abc import AbstractIdentityPolicy

try:
    import jwt
except ImportError:  # pragma: no cover
    jwt = None


AUTH_HEADER_NAME = 'Authorization'
AUTH_SCHEME = 'Bearer '


class JWTIdentityPolicy(AbstractIdentityPolicy):
    def __init__(self, secret, algorithm='HS256'):
        if jwt is None:
            raise RuntimeError('Please install `PyJWT`')
        self.secret = secret
        self.algorithm = algorithm

    async def identify(self, request):
        header_identity = request.headers.get(AUTH_HEADER_NAME)

        if header_identity is None:
            return

        if not header_identity.startswith(AUTH_SCHEME):
            raise ValueError('Invalid authorization scheme. ' +
                             'Should be `Bearer <token>`')

        token = header_identity.split(' ')[1].strip()

        identity = jwt.decode(token,
                              self.secret,
                              algorithms=[self.algorithm])
        return identity

    async def remember(self, *args, **kwargs):  # pragma: no cover
        pass

    async def forget(self, request, response):  # pragma: no cover
        pass

Directory Contents

Dirs: 1 × Files: 6

Name Size Perms Modified Actions
- drwxr-xr-x 2026-02-06 08:01:08
Edit Download
1.45 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
5.75 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
887 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.18 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
1.09 KB lrw-r--r-- 2026-01-20 13:01:48
Edit Download
791 B lrw-r--r-- 2026-01-20 13:01:48
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).