# Path: sitegate/signin_flows/remotes/google.py
# class Google(Remote):
#     """Sign in using Google.
# 
#     Docs: https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow
# 
#     Register your OAuth application at
#         https://console.cloud.google.com/apis/credentials
# 
#         Set scopes:
#             https://developers.google.com/identity/protocols/oauth2/scopes?hl=ur#oauth2
# 
#             https://www.googleapis.com/auth/userinfo.email --- required
#             https://www.googleapis.com/auth/userinfo.profile --- optional
# 
#         Set callback URL:
#             <your-domain-uri>/rauth/google/
# 
#     """
#     alias: str = 'google'
#     title: str = _('Google')
# 
#     @classmethod
#     def _get_user_data(cls, request: HttpRequest, *, data: dict) -> UserData:
# 
#         user_data = cls._request_json(
#             'https://www.googleapis.com/oauth2/v1/userinfo?alt=json',
#             headers={'Authorization': f"Bearer {data.get('access_token')}"},
#         )
# 
#         email = user_data['email']
# 
#         if not user_data['verified_email']:
#             raise ValueError(f'Email: {email} is not verified')
# 
#         login, _, _ = email.partition('@')
#         
#         user_data = UserData(
#             remote_id=user_data['id'],
#             username=login,
#             emails=[email],
#             first_name=user_data.get('given_name', ''),
#             last_name=user_data.get('family_name', ''),
#         )
# 
#         return user_data
# 
#     def auth_start(self, request: HttpRequest, *, ticket: str) -> HttpResponseRedirect:
#         scope = 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
#         return self.redirect(
#             'https://accounts.google.com/o/oauth2/v2/auth?response_type=token&'
#             f'client_id={self.client_id}&state={ticket}&'
#             f'redirect_uri={quote(self.get_url_auth_continue_absolute(request))}&'
#             f"scope={quote(scope)}")
# 
# Path: sitegate/signin_flows/remotes/yandex.py
# class Yandex(Remote):
#     """Sign in using Yandex.
# 
#     Docs: https://yandex.ru/dev/oauth/
# 
#     Register your OAuth application at
#         https://oauth.yandex.ru/
# 
#         Set scopes:
#             API Яндекс ID - Доступ к адресу электронной почты --- required
#             API Яндекс ID - Доступ к логину, имени и фамилии, полу --- optional
# 
#         Set callback URL:
#             <your-domain-uri>/rauth/yandex/
# 
#     """
#     alias: str = 'yandex'
#     title: str = _('Yandex')
# 
#     @classmethod
#     def _get_user_data(cls, request: HttpRequest, *, data: dict) -> UserData:
# 
#         user_data = cls._request_json(
#             'https://login.yandex.ru/info?format=json',
#             headers={'Authorization': f"OAuth {data.get('access_token')}"},
#         )
# 
#         user_data = UserData(
#             remote_id=user_data['id'],
#             username=user_data['login'],
#             emails=user_data['emails'],
#             first_name=user_data.get('first_name', ''),
#             last_name=user_data.get('last_name', ''),
#         )
# 
#         return user_data
# 
#     def auth_start(self, request: HttpRequest, *, ticket: str) -> HttpResponseRedirect:
#         return self.redirect(
#             'https://oauth.yandex.ru/authorize?response_type=token&'
#             f'client_id={self.client_id}&state={ticket}&display=popup')
# 
# Path: sitegate/utils.py
# def register_remotes(*remotes: 'Remote'):
#     """Registers (configures) remotes.
# 
#     :param remotes: Remote heirs instances.
# 
#     """
#     global _REMOTES_REGISTRY
# 
#     for remote in remotes:
#         _REMOTES_REGISTRY[remote.alias] = remote


from sitegate.signin_flows.remotes.google import Google
from sitegate.signin_flows.remotes.yandex import Yandex
from sitegate.utils import register_remotes


register_remotes(
    Yandex(client_id='yandex-clid'),
    Google(client_id='google-clid'),

# Path: sitegate/signin_flows/remotes/google.py
# class Google(Remote):
#     """Sign in using Google.
# 
#     Docs: https://developers.google.com/identity/protocols/oauth2/javascript-implicit-flow
# 
#     Register your OAuth application at
#         https://console.cloud.google.com/apis/credentials
# 
#         Set scopes:
#             https://developers.google.com/identity/protocols/oauth2/scopes?hl=ur#oauth2
# 
#             https://www.googleapis.com/auth/userinfo.email --- required
#             https://www.googleapis.com/auth/userinfo.profile --- optional
# 
#         Set callback URL:
#             <your-domain-uri>/rauth/google/
# 
#     """
#     alias: str = 'google'
#     title: str = _('Google')
# 
#     @classmethod
#     def _get_user_data(cls, request: HttpRequest, *, data: dict) -> UserData:
# 
#         user_data = cls._request_json(
#             'https://www.googleapis.com/oauth2/v1/userinfo?alt=json',
#             headers={'Authorization': f"Bearer {data.get('access_token')}"},
#         )
# 
#         email = user_data['email']
# 
#         if not user_data['verified_email']:
#             raise ValueError(f'Email: {email} is not verified')
# 
#         login, _, _ = email.partition('@')
#         
#         user_data = UserData(
#             remote_id=user_data['id'],
#             username=login,
#             emails=[email],
#             first_name=user_data.get('given_name', ''),
#             last_name=user_data.get('family_name', ''),
#         )
# 
#         return user_data
# 
#     def auth_start(self, request: HttpRequest, *, ticket: str) -> HttpResponseRedirect:
#         scope = 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
#         return self.redirect(
#             'https://accounts.google.com/o/oauth2/v2/auth?response_type=token&'
#             f'client_id={self.client_id}&state={ticket}&'
#             f'redirect_uri={quote(self.get_url_auth_continue_absolute(request))}&'
#             f"scope={quote(scope)}")
# 
# Path: sitegate/signin_flows/remotes/yandex.py
# class Yandex(Remote):
#     """Sign in using Yandex.
# 
#     Docs: https://yandex.ru/dev/oauth/
# 
#     Register your OAuth application at
#         https://oauth.yandex.ru/
# 
#         Set scopes:
#             API Яндекс ID - Доступ к адресу электронной почты --- required
#             API Яндекс ID - Доступ к логину, имени и фамилии, полу --- optional
# 
#         Set callback URL:
#             <your-domain-uri>/rauth/yandex/
# 
#     """
#     alias: str = 'yandex'
#     title: str = _('Yandex')
# 
#     @classmethod
#     def _get_user_data(cls, request: HttpRequest, *, data: dict) -> UserData:
# 
#         user_data = cls._request_json(
#             'https://login.yandex.ru/info?format=json',
#             headers={'Authorization': f"OAuth {data.get('access_token')}"},
#         )
# 
#         user_data = UserData(
#             remote_id=user_data['id'],
#             username=user_data['login'],
#             emails=user_data['emails'],
#             first_name=user_data.get('first_name', ''),
#             last_name=user_data.get('last_name', ''),
#         )
# 
#         return user_data
# 
#     def auth_start(self, request: HttpRequest, *, ticket: str) -> HttpResponseRedirect:
#         return self.redirect(
#             'https://oauth.yandex.ru/authorize?response_type=token&'
#             f'client_id={self.client_id}&state={ticket}&display=popup')
# 
# Path: sitegate/utils.py
# def register_remotes(*remotes: 'Remote'):
#     """Registers (configures) remotes.
# 
#     :param remotes: Remote heirs instances.
# 
#     """
#     global _REMOTES_REGISTRY
# 
#     for remote in remotes:
#         _REMOTES_REGISTRY[remote.alias] = remote


# Path: sitegate/tests/testapp/sitegates.py
from sitegate.signin_flows.remotes.google import Google
from sitegate.signin_flows.remotes.yandex import Yandex
from sitegate.utils import register_remotes



register_remotes(
    Yandex(client_id='yandex-clid'),
    Google(client_id='google-clid'),

)