
    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KJr  S SKJr  \ R                  " \5      r " S	 S
\5      rg)    N)Response)request)import_stringgenerate_token)
url_encode)AuthorizationServer)OAuth1Requestc                      ^  \ rS rSrSrSS jrSS jrS rS rS r	S r
S	 rS
 rS rS rS rS rSU 4S jjrSU 4S jjrS rS rSrU =r$ )r	      aL  Flask implementation of :class:`authlib.rfc5849.AuthorizationServer`.
Initialize it with Flask app instance, client model class and cache::

    server = AuthorizationServer(app=app, query_client=query_client)
    # or initialize lazily
    server = AuthorizationServer()
    server.init_app(app, query_client=query_client)

:param app: A Flask app instance
:param query_client: A function to get client by client_id. The client
    model class MUST implement the methods described by
    :class:`~authlib.oauth1.rfc5849.ClientMixin`.
:param token_generator: A function to generate token
c                 n    Xl         X l        X0l        S S S S S S S.U l        Ub  U R	                  U5        g g )N)exists_noncecreate_temporary_credentialget_temporary_credentialdelete_temporary_credentialcreate_authorization_verifiercreate_token_credential)appquery_clienttoken_generator_hooksinit_app)selfr   r   r   s       p/home/james-whalen/.local/lib/python3.13/site-packages/authlib/integrations/flask_oauth1/authorization_server.py__init__AuthorizationServer.__init__   sH    (. !+/(,+/-1'+
 ?MM#     c                     Ub  X l         Ub  X0l        U R                  c  U R                  U5      U l        UR                  R	                  S5      nU(       a!  [        U[        [        45      (       a  X@l        Xl	        g )N"OAUTH1_SUPPORTED_SIGNATURE_METHODS)
r   r   create_token_generatorconfigget
isinstancelisttupleSUPPORTED_SIGNATURE_METHODSr   )r   r   r   r   methodss        r   r   AuthorizationServer.init_app/   sj    # ,&#2 '#'#>#>s#CD **..!EFz'D%=99/6,r   c                 T    XR                   ;  a  [        S5      eX R                   U'   g )NzInvalid "name" of hook)r   
ValueError)r   namefuncs      r   register_hook!AuthorizationServer.register_hook>   s$    {{"566 Dr   c                   ^^^ UR                   R                  S5      m[        T[        5      (       a  [	        T5      mO"UR                   R                  SS5      mU4S jmUR                   R                  S5      m[        T[        5      (       a  [	        T5      mO"UR                   R                  SS5      mU4S jmUU4S	 jnU$ )
NOAUTH1_TOKEN_GENERATOROAUTH1_TOKEN_LENGTH*   c                     > [        T 5      $ Nr   lengths   r   r   CAuthorizationServer.create_token_generator.<locals>.token_generatorK       %f--r   OAUTH1_TOKEN_SECRET_GENERATOROAUTH1_TOKEN_SECRET_LENGTH0   c                     > [        T 5      $ r4   r   r5   s   r   secret_generatorDAuthorizationServer.create_token_generator.<locals>.secret_generatorT   r8   r   c                  "   > T" 5       T " 5       S.$ )N)oauth_tokenoauth_token_secret )r=   r   s   r   create_token@AuthorizationServer.create_token_generator.<locals>.create_tokenW   s    .0&6&8 r   )r!   r"   r#   strr   )r   r   rC   r6   r=   r   s      @@@r   r    *AuthorizationServer.create_token_generatorC   s    **..)ABos+++O<OZZ^^$92>F. ::>>*IJ&,,,-=>ZZ^^$@"EF.	 r   c                 $    U R                  U5      $ r4   )r   )r   	client_ids     r   get_client_by_id$AuthorizationServer.get_client_by_id_   s      ++r   c                     U R                   S   n[        U5      (       a-  UR                  nUR                  nUR                  nU" XXV5      $ [        S5      e)Nr   z "exists_nonce" hook is required.)r   callable	timestamprH   tokenRuntimeError)r   noncer   r,   rM   rH   rN   s          r   r    AuthorizationServer.exists_nonceb   sQ    {{>*D>>))I))IMME);;=>>r   c                     U R                   S   n[        U5      (       a-  U R                  5       nU" X1R                  UR                  5      $ [        S5      e)Nr   z/"create_temporary_credential" hook is required.)r   rL   r   rH   redirect_urirO   )r   r   r,   rN   s       r   r   /AuthorizationServer.create_temporary_credentiall   sM    {{89D>>((*E00'2F2FGGLMMr   c                 z    U R                   S   n[        U5      (       a  U" UR                  5      $ [        S5      e)Nr   z,"get_temporary_credential" hook is required.r   rL   rN   rO   r   r   r,   s      r   r   ,AuthorizationServer.get_temporary_credentials   s5    {{56D>>&&IJJr   c                 z    U R                   S   n[        U5      (       a  U" UR                  5      $ [        S5      e)Nr   z/"delete_temporary_credential" hook is required.rV   rW   s      r   r   /AuthorizationServer.delete_temporary_credentialz   s5    {{89D>>&&LMMr   c                     U R                   S   n[        U5      (       a+  [        S5      nU" UR                  UR                  U5        U$ [        S5      e)Nr   $   z1"create_authorization_verifier" hook is required.)r   rL   r   
credentialuserrO   )r   r   r,   verifiers       r   r   1AuthorizationServer.create_authorization_verifier   sK    {{:;D>>%b)H##W\\8<ONOOr   c                     U R                   S   n[        U5      (       a$  UR                  nU R                  5       nU" XC5      $ [	        S5      e)Nr   z+"create_token_credential" hook is required.)r   rL   r]   r   rO   )r   r   r,   temporary_credentialrN   s        r   r   +AuthorizationServer.create_token_credential   sK    {{45D>>#*#5#5 ((*E44HIIr   c                 J    U R                  S 5      nU R                  U5        U$ r4   )create_oauth1_requestvalidate_authorization_request)r   reqs     r   check_authorization_request/AuthorizationServer.check_authorization_request   s%    ((.++C0
r   c                 "   > [         TU ]  X5      $ r4   )supercreate_authorization_response)r   r   
grant_user	__class__s      r   rl   1AuthorizationServer.create_authorization_response   s    w4WIIr   c                 "   > [         TU ]  U5      $ r4   )rk   create_token_response)r   r   rn   s     r   rq   )AuthorizationServer.create_token_response   s    w,W55r   c                     Uc  [         nUR                  S;   a  UR                  R                  SS9nOS n[	        UR                  UR
                  X!R                  5      $ )N)POSTPUTT)flat)	flask_reqmethodformto_dictr
   urlheaders)r   r   bodys      r   re   )AuthorizationServer.create_oauth1_request   sO    ?G>>_,<<''T'2DDW^^W[[$PPr   c                 (    [        [        U5      XS9$ )N)statusr|   )r   r   )r   status_codepayloadr|   s       r   handle_response#AuthorizationServer.handle_response   s    
7+KQQr   )r&   r   r   r   r   )NNN)NNr4   )__name__
__module____qualname____firstlineno____doc__r   r   r-   r    rI   r   r   r   r   r   r   rh   rl   rq   re   r   __static_attributes____classcell__)rn   s   @r   r	   r	      sf     !
8,?NKNPJ
J6QR Rr   r	   )loggingflaskr   r   rw   werkzeug.utilsr   authlib.common.securityr   authlib.common.urlsr   authlib.oauth1r	   _AuthorizationServerr
   	getLoggerr   logrB   r   r   <module>r      s>      & ( 2 * F (!YR. YRr   