o
    RDi	                     @   s   d dl Z d dlZ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 ddlmZ dd	lmZ ee	d
deed
dG dd deZdS )    N)ObjectDoesNotExist)JsonResponse)method_decorator)csrf_exempt   )login_not_required)get_access_token_model)!ClientProtectedScopedResourceViewdispatch)namec                   @   s4   e Zd ZdZdgZed
ddZdd Zdd	 ZdS )IntrospectTokenViewz
    Implements an endpoint for token introspection based
    on RFC 7662 https://rfc-editor.org/rfc/rfc7662.html

    To access this view the request must pass a OAuth2 Bearer Token
    which is allowed to access the scope `introspection`.
    introspectionNc                 C   s   zt | d }t jddj|d}W n ty)   t	ddidd Y S w |
 rTd	|jtt|j d
}|jrF|jj|d< |jrP|j |d< t	|S t	ddiddS )Nzutf-8userapplication)token_checksumactiveF   )statusT)r   scopeexp	client_idusername)hashlibsha256encode	hexdigestr   objectsselect_relatedgetr   r   is_validr   intcalendartimegmexpires	timetupler   r   r   get_username)token_valuer   tokendata r)   Y/var/www/Datamplify/venv/lib/python3.10/site-packages/oauth2_provider/views/introspect.pyget_token_response   s*   
z&IntrospectTokenView.get_token_responsec                 O      |  |jddS )z
        Get the token from the URL parameters.
        URL: https://example.com/introspect?token=mF_9.B5f-4.1JqM

        :param request:
        :param args:
        :param kwargs:
        :return:
        r'   N)r+   GETr   selfrequestargskwargsr)   r)   r*   r   5      
zIntrospectTokenView.getc                 O   r,   )z
        Get the token from the body form parameters.
        Body: token=mF_9.B5f-4.1JqM

        :param request:
        :param args:
        :param kwargs:
        :return:
        r'   N)r+   POSTr   r.   r)   r)   r*   postA   r3   zIntrospectTokenView.post)N)	__name__
__module____qualname____doc__required_scopesstaticmethodr+   r   r5   r)   r)   r)   r*   r      s    r   )r!   r   django.core.exceptionsr   django.httpr   django.utils.decoratorsr   django.views.decorators.csrfr   compatr   modelsr   views.genericr	   r   r)   r)   r)   r*   <module>   s    

