
    k7i!                     ^    S SK r S SKJr  S SKJr  S SKJr  S SKJr  S SKJ	r	   " S S\	5      r
g)	    N)Optional)Uniongenerate_token)jwt)BearerTokenGeneratorc                      ^  \ rS rSrSr   SU 4S jjrS rS rS\\	\
\	   4   4S jrS\\	   4S jrS\\   4S	 jrS\\
\	      4S
 jrS\	4S jrS rSrU =r$ )JWTBearerTokenGenerator
   a  A JWT formatted access token generator.

:param issuer: The issuer identifier. Will appear in the JWT ``iss`` claim.

:param \\*\\*kwargs: Other parameters are inherited from
    :class:`~authlib.oauth2.rfc6750.token.BearerTokenGenerator`.

This token generator can be registered into the authorization server::

    class MyJWTBearerTokenGenerator(JWTBearerTokenGenerator):
        def get_jwks(self): ...

        def get_extra_claims(self, client, grant_type, user, scope): ...


    authorization_server.register_token_generator(
        "default",
        MyJWTBearerTokenGenerator(
            issuer="https://authorization-server.example.org"
        ),
    )
c                 R   > [         TU ]  U R                  X45        Xl        X l        g )N)super__init__access_token_generatorissueralg)selfr   r   refresh_token_generatorexpires_generator	__class__s        V/home/james-whalen/.local/lib/python3.13/site-packages/authlib/oauth2/rfc9068/token.pyr    JWTBearerTokenGenerator.__init__"   s*     	'')@	
     c                     [        5       e)zReturn the JWKs that will be used to sign the JWT access token.
Developers MUST re-implement this method::

    def get_jwks(self):
        return load_jwks("jwks.json")
)NotImplementedError)r   s    r   get_jwks JWTBearerTokenGenerator.get_jwks/   s     "##r   c                     0 $ )a1  Return extra claims to add in the JWT access token. Developers MAY
re-implement this method to add identity claims like the ones in
:ref:`specs/oidc` ID Token, or any other arbitrary claims::

    def get_extra_claims(self, client, grant_type, user, scope):
        return generate_user_info(user, scope)
 r   client
grant_typeuserscopes        r   get_extra_claims(JWTBearerTokenGenerator.get_extra_claims8   s	     	r   returnc                 "    UR                  5       $ )a*  Return the audience for the token. By default this simply returns
the client ID. Developers MAY re-implement this method to add extra
audiences::

    def get_audiences(self, client, user, scope):
        return [
            client.get_client_id(),
            resource_server.get_id(),
        ]
)get_client_id)r   r    r"   r#   s       r   get_audiences%JWTBearerTokenGenerator.get_audiencesB   s     ##%%r   c                     g)ay  Authentication Context Class Reference.
Returns a user-defined case sensitive string indicating the class of
authentication the used performed. Token audience may refuse to give access to
some resources if some ACR criteria are not met.
:ref:`specs/oidc` defines one special value: ``0`` means that the user
authentication did not respect `ISO29115`_ level 1, and will be refused monetary
operations. Developers MAY re-implement this method::

    def get_acr(self, user):
        if user.insecure_session():
            return "0"
        return "urn:mace:incommon:iap:silver"

.. _ISO29115: https://www.iso.org/standard/45138.html
Nr   r   r"   s     r   get_acrJWTBearerTokenGenerator.get_acrO   s      r   c                     g)aM  User authentication time.
Time when the End-User authentication occurred. Its value is a JSON number
representing the number of seconds from 1970-01-01T0:0:0Z as measured in UTC
until the date/time. Developers MAY re-implement this method::

    def get_auth_time(self, user):
        return datetime.timestamp(user.get_auth_time())
Nr   r,   s     r   get_auth_time%JWTBearerTokenGenerator.get_auth_timea        r   c                     g)aK  Authentication Methods References.
Defined by :ref:`specs/oidc` as an option list of user-defined case-sensitive
strings indication which authentication methods have been used to authenticate
the user. Developers MAY re-implement this method::

    def get_amr(self, user):
        return ["2FA"] if user.has_2fa_enabled() else []
Nr   r,   s     r   get_amrJWTBearerTokenGenerator.get_amrl   r2   r   c                     [        S5      $ )zJWT ID.
Create an unique identifier for the token. Developers MAY re-implement
this method::

    def get_jti(self, client, grant_type, user scope):
        return generate_random_string(16)
   r   r   s        r   get_jtiJWTBearerTokenGenerator.get_jtiw   s     b!!r   c           
         [        [        R                  " 5       5      nXPR                  X5      -   nU R                  UUR	                  5       UU R                  XX45      US.nU(       a  UR                  5       US'   OUR	                  5       US'    U R                  XU5      US'   U R                  U5      =n(       a  XS'   U R                  U5      =n	(       a  XS'   U R                  U5      =n
(       a  XS'   UR                  U R                  XX45      5        U R                  SS	.n[        R                  " UUU R!                  5       SS
9nUR#                  5       $ )N)issexp	client_idiatjtir#   subFaud	auth_timeacramrzat+jwt)r   typ)keycheck)inttime_get_expires_inr   r(   r8   get_user_idr)   r0   r-   r4   updater$   r   r   encoder   decode)r   r    r!   r"   r#   now
expires_in
token_datarB   rC   rD   headeraccess_tokens                r   r   .JWTBearerTokenGenerator.access_token_generator   s]   $))+//CC
 ;;--/<<D@

  $ 0 0 2Ju !' 4 4 6Ju  !% 2 26 GJu **40090&/{#
 ,,t$$3$ #u
 ,,t$$3$ #u 	$//DPQ (3zz	
 ""$$r   )r   r   )RS256NN)__name__
__module____qualname____firstlineno____doc__r   r   r$   r   strlistr)   r   r-   rH   r0   r4   r8   r   __static_attributes____classcell__)r   s   @r   r
   r
   
   s    4  $$&E#tCy.4I &x} $	Xc] 		xS	2 	"# "Y% Y%r   r
   )rI   typingr   r   authlib.common.securityr   authlib.joser   authlib.oauth2.rfc6750.tokenr   r
   r   r   r   <module>rc      s&       2  =P%2 P%r   