o
    h                     @   sd   d dl mZ d dlmZ d dlmZ d dlmZ d dl	m
Z
mZmZ d dlmZ G dd de
Zd	S )
    )	urlencode)HttpResponseRedirect)gettext)get_adapter)OAuthClient
OAuthErrorget_token_prefix)build_absolute_uric                   @   s$   e Zd Zdd Zdd Zdd ZdS )PocketOAuthClientc                 C   s   | j du rEt| j| j}ddi}| j|d}t  j| j||d}|j	dkr2t
tdt| j | d | _ | j | jjd	t| j < | j S )
z
        Obtain a temporary request token to authorize an access token and to
        sign the request to obtain the access token
        NX-Acceptapplication/json)consumer_keyredirect_uri)urljsonheaders   z9Invalid response while obtaining request token from "%s".codezoauth_%s_request_token)request_tokenr	   requestcallback_urlr   r   get_requests_sessionpostrequest_token_urlstatus_coder   _r   r   session)selfredirect_urlr   dataresponse r!   d/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/socialaccount/providers/pocket/client.py_get_request_token   s6   

	z$PocketOAuthClient._get_request_tokenc                 C   s>   |   }|| j| jd}|| |d t| }t|S )zy
        Returns a ``HttpResponseRedirect`` object to redirect the user
        to the Pocket authorization URL.
        )r   r   ?)r#   r   r	   r   updater   r   )r   authorization_urlextra_paramsr   paramsr   r!   r!   r"   get_redirect2   s   
zPocketOAuthClient.get_redirectc                 C   s   | j du rL|  }| j}ddi}| j|d}t  j|||d}|jdkr1tt	dt
| j | }||d |d	 d
| _ | j | jjdt
| j < | j S )zb
        Obtain the access token to access private resources at the API
        endpoint.
        Nr   r   )r   r   )r   r   r   r   z8Invalid response while obtaining access token from "%s".access_tokenusername)oauth_tokenoauth_token_secretr+   zoauth_%s_access_token)r*   _get_rt_from_sessionaccess_token_urlr   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r    rr!   r!   r"   get_access_token@   s:   

z"PocketOAuthClient.get_access_tokenN)__name__
__module____qualname__r#   r)   r1   r!   r!   r!   r"   r
      s    "r
   N)urllib.parser   django.httpr   django.utils.translationr   r   allauth.socialaccount.adapterr   ,allauth.socialaccount.providers.oauth.clientr   r   r   allauth.utilsr	   r
   r!   r!   r!   r"   <module>   s    