o
    õÁhW  ã                   @   sN   d dl mZ d dlmZ d dlmZ G dd„ deƒZG dd„ deƒZegZdS )	é    )ÚProviderAccount)ÚDataportenOAuth2Adapter)ÚOAuth2Providerc                   @   s   e Zd Zdd„ ZdS )ÚDataportenAccountc                 C   s   d}|| j jd  S )zJ
        Returns a valid URL to an 128x128 .png photo of the user
        z1https://api.dataporten.no/userinfo/v1/user/media/Úprofilephoto)ÚaccountÚ
extra_data)ÚselfÚbase_url© r   új/var/www/html/pos/venv/lib/python3.10/site-packages/allauth/socialaccount/providers/dataporten/provider.pyÚget_avatar_url   s   z DataportenAccount.get_avatar_urlN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s    r   c                   @   s4   e Zd ZdZdZeZeZdd„ Z	dd„ Z
dd„ Zd	S )
ÚDataportenProviderÚ
dataportenÚ
Dataportenc                 C   s   |d S )zz
        Returns the primary user identifier, an UUID string
        See: https://docs.dataporten.no/docs/userid/
        Úuseridr   ©r	   Údatar   r   r   Úextract_uid   s   zDataportenProvider.extract_uidc                 C   s   |S )uà  
        Extracts fields from `data` that will be stored in
        `SocialAccount`'s `extra_data` JSONField.

        All the necessary data extraction has already been done in the
        complete_login()-view, so we can just return the data.
        PS: This is default behaviour, so we did not really need to define
            this function, but it is included for documentation purposes.

        Typical return dict:
        {
            "userid": "76a7a061-3c55-430d-8ee0-6f82ec42501f",
            "userid_sec": ["feide:andreas@uninett.no"],
            "name": "Andreas Ã…kre Solberg",
            "email": "andreas.solberg@uninett.no",
            "profilephoto": "p:a3019954-902f-45a3-b4ee-bca7b48ab507",
        }
        r   r   r   r   r   Úextract_extra_data   s   z%DataportenProvider.extract_extra_datac                 C   sb   t |ƒ}| d¡D ]}| d¡\}}|dkr"| d¡d |d<  |S q	| d¡ d¡d |d< |S )uv  
        This function extracts information from the /userinfo endpoint which
        will be consumed by allauth.socialaccount.adapter.populate_user().
        Look there to find which key-value pairs that should be saved in the
        returned dict.

        Typical return dict:
        {
            "userid": "76a7a061-3c55-430d-8ee0-6f82ec42501f",
            "userid_sec": ["feide:andreas@uninett.no"],
            "name": "Andreas Ã…kre Solberg",
            "email": "andreas.solberg@uninett.no",
            "profilephoto": "p:a3019954-902f-45a3-b4ee-bca7b48ab507",
            "username": "andreas",
        }
        Ú
userid_secú:Úfeideú@r   ÚusernameÚemail)ÚdictÚgetÚsplit)r	   r   r   Úusertyper   r   r   r   Úextract_common_fields3   s   ùz(DataportenProvider.extract_common_fieldsN)r   r   r   ÚidÚnamer   Úaccount_classr   Úoauth2_adapter_classr   r   r#   r   r   r   r   r      s    r   N)	Ú$allauth.socialaccount.providers.baser   Ú0allauth.socialaccount.providers.dataporten.viewsr   Ú/allauth.socialaccount.providers.oauth2.providerr   r   r   Úprovider_classesr   r   r   r   Ú<module>   s    
D