
    f`                     Z    d dl mZ d dlmZ d dlmZ  G d de      Z G d de      ZegZy)	    )ProviderAccount)DataportenOAuth2Adapter)OAuth2Providerc                       e Zd Zd Zy)DataportenAccountc                 >    d}|| j                   j                  d   z   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_urls     n/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/allauth/socialaccount/providers/dataporten/provider.pyget_avatar_urlz DataportenAccount.get_avatar_url	   s$     G$,,11.AAA    N)__name__
__module____qualname__r    r   r   r   r      s    Br   r   c                   .    e Zd ZdZdZeZeZd Z	d Z
d Zy)DataportenProvider
dataporten
Dataportenc                     |d   S )zz
        Returns the primary user identifier, an UUID string
        See: https://docs.dataporten.no/docs/userid/
        useridr   r   datas     r   extract_uidzDataportenProvider.extract_uid   s    
 H~r   c                     |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   s     r   extract_extra_dataz%DataportenProvider.extract_extra_data    s	    & r   c                     t        |      }|j                  d      D ]5  }|j                  d      \  }}|dk(  s|j                  d      d   |d<    |S  |j                  d      j                  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%   s        r   extract_common_fieldsz(DataportenProvider.extract_common_fields5   s    $ Dz hh|, 	?F!'c!2Hh7"#+>>##6q#9Z 
 	?  $xx066s;A>Dr   N)r   r   r   idnamer   account_classr   oauth2_adapter_classr   r   r+   r   r   r   r   r      s&    	BD%M2*r   r   N)	$allauth.socialaccount.providers.baser   0allauth.socialaccount.providers.dataporten.viewsr   /allauth.socialaccount.providers.oauth2.providerr   r   r   provider_classesr   r   r   <module>r4      s;    @ KB BA AH '' r   