o
    ëË·e  ã                   @   sB   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)ÚOAuth2Providerc                       s$   e Zd Zdd„ Z‡ fdd„Z‡  Z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/ideatree/venv/lib/python3.10/site-packages/allauth/socialaccount/providers/dataporten/provider.pyÚget_avatar_url   s   z DataportenAccount.get_avatar_urlc                    s&   t t| ƒ ¡ }d| jj dd¡|f S )zk
        Returns string representation of a social account. Includes the name
        of the user.
        z%s (%s)ÚnameÚ )Úsuperr   Úto_strr   r   Úget)r   Údflt©Ú	__class__r
   r   r      s
   þzDataportenAccount.to_str)Ú__name__Ú
__module__Ú__qualname__r   r   Ú__classcell__r
   r
   r   r   r      s    	r   c                   @   s0   e Zd ZdZd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)Údictr   Úsplit)r   r   r   Úusertyper%   r
   r
   r   Úextract_common_fields<   s   ùz(DataportenProvider.extract_common_fieldsN)
r   r   r   Úidr   r   Úaccount_classr   r    r*   r
   r
   r
   r   r      s    r   N)Ú$allauth.socialaccount.providers.baser   Ú/allauth.socialaccount.providers.oauth2.providerr   r   r   Úprovider_classesr
   r
   r
   r   Ú<module>   s
    
C