Example #1
0
        else:
            access_token = dict(parse_qsl(resp.text))
    if not access_token or 'access_token' not in access_token:
        raise OAuth2Error('Error retrieving access token: %s' % resp.content)
    return access_token


class KakaoOAuth2CallbackView(OAuth2CallbackView):
    def get_client(self, request, app):
        client = super(KakaoOAuth2CallbackView, self).get_client(request, app)
        setattr(client, 'get_access_token',
                lambda code: get_access_token(client, code))
        return client


oauth2_login = OAuth2LoginView.adapter_view(KakaoOAuth2Adapter)
oauth2_callback = KakaoOAuth2CallbackView.adapter_view(KakaoOAuth2Adapter)


def login_by_token(request):
    ret = None
    auth_exception = None

    if request.method == 'POST':
        form = KakaoConnectForm(request.POST)
        if form.is_valid():
            try:
                provider = providers.registry.by_id(KakaoProvider.id)
                app = providers.registry.by_id(
                    KakaoProvider.id).get_app(request)
                access_token = form.cleaned_data['access_token']
Example #2
0
import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import KakaoProvider


class KakaoOAuth2Adapter(OAuth2Adapter):
    provider_id = KakaoProvider.id
    access_token_url = 'https://kauth.kakao.com/oauth/token'
    authorize_url = 'https://kauth.kakao.com/oauth/authorize'
    profile_url = 'https://kapi.kakao.com/v1/user/me'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(KakaoOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(KakaoOAuth2Adapter)
Example #3
0

class VKOAuth2Adapter(OAuth2Adapter):
    provider_id = VKProvider.id
    access_token_url = 'https://oauth.vk.com/access_token'
    authorize_url = 'https://oauth.vk.com/authorize'
    profile_url = 'https://api.vk.com/method/users.get'

    def complete_login(self, request, app, token, **kwargs):
        uid = kwargs['response'].get('user_id')
        params = {
            'v': '3.0',
            'access_token': token.token,
            'fields': ','.join(USER_FIELDS),
        }
        if uid:
            params['user_ids'] = uid
        resp = requests.get(self.profile_url,
                            params=params)
        resp.raise_for_status()
        extra_data = resp.json()['response'][0]
        email = kwargs['response'].get('email')
        if email:
            extra_data['email'] = email
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(VKOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(VKOAuth2Adapter)
import requests

from allauth.socialaccount.providers.oauth2.views import OAuth2Adapter, OAuth2LoginView, OAuth2CallbackView
from allauth.socialaccount.models import SocialAccount, SocialLogin
from allauth.socialaccount.adapter import get_adapter

from .provider import TwitchProvider


class TwitchOAuth2Adapter(OAuth2Adapter):
    provider_id = TwitchProvider.id
    access_token_url = "https://api.twitch.tv/kraken/oauth2/token"
    authorize_url = "https://api.twitch.tv/kraken/oauth2/authorize"
    profile_url = "https://api.twitch.tv/kraken/user"

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url, params={"oauth_token": token.token})
        extra_data = resp.json()
        uid = str(extra_data["_id"])
        user = get_adapter().populate_new_user(
            username=extra_data.get("display_name"), name=extra_data.get("name"), email=extra_data.get("email")
        )
        account = SocialAccount(user=user, uid=uid, extra_data=extra_data, provider=self.provider_id)
        return SocialLogin(account)


oauth2_login = OAuth2LoginView.adapter_view(TwitchOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(TwitchOAuth2Adapter)
Example #5
0
class OdnoklassnikiOAuth2Adapter(OAuth2Adapter):
    provider_id = OdnoklassnikiProvider.id
    access_token_url = 'http://api.odnoklassniki.ru/oauth/token.do'
    authorize_url = 'http://www.odnoklassniki.ru/oauth/authorize'
    profile_url = 'http://api.odnoklassniki.ru/fb.do'
    access_token_method = 'POST'

    def complete_login(self, request, app, token, **kwargs):
        data = {'method': 'users.getCurrentUser',
                'access_token': token.token,
                'fields': ','.join(USER_FIELDS),
                'format': 'JSON',
                'application_key': app.key}
        suffix = md5(
            '{0:s}{1:s}'.format(
                data['access_token'], app.secret).encode('utf-8')).hexdigest()
        check_list = sorted(['{0:s}={1:s}'.format(k, v)
                             for k, v in data.items() if k != 'access_token'])
        data['sig'] = md5(
            (''.join(check_list) + suffix).encode('utf-8')).hexdigest()

        response = requests.get(self.profile_url, params=data)
        extra_data = response.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(OdnoklassnikiOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(OdnoklassnikiOAuth2Adapter)
Example #6
0
class BitlyOAuth2Adapter(OAuth2Adapter):
    provider_id = BitlyProvider.id
    access_token_url = 'https://api-ssl.bitly.com/oauth/access_token'
    authorize_url = 'https://bitly.com/oauth/authorize'
    profile_url = 'https://api-ssl.bitly.com/v3/user/info'
    supports_state = False

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(
            self.profile_url,
            params={ 'access_token': token.token }
        )
        extra_data = resp.json()['data']
        uid = str(extra_data['login'])
        user = get_adapter().populate_new_user(
            username=extra_data['login'],
            name=extra_data.get('full_name')
        )
        account = SocialAccount(
            user=user,
            uid=uid,
            extra_data=extra_data,
            provider=self.provider_id
        )
        return SocialLogin(account)


oauth2_login = OAuth2LoginView.adapter_view(BitlyOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(BitlyOAuth2Adapter)

Example #7
0
    OAuth2LoginView,
)

from .provider import DropboxOAuth2Provider


class DropboxOAuth2Adapter(OAuth2Adapter):
    provider_id = DropboxOAuth2Provider.id
    access_token_url = 'https://api.dropbox.com/oauth2/token'
    authorize_url = 'https://www.dropbox.com/oauth2/authorize'
    profile_url = 'https://api.dropbox.com/2/users/get_current_account'
    redirect_uri_protocol = 'https'

    def complete_login(self, request, app, token, **kwargs):
        extra_data = requests.post(self.profile_url, headers={
            'Authorization': 'Bearer %s' % (token.token, )
        })

        # This only here because of weird response from the test suite
        if isinstance(extra_data, list):
            extra_data = extra_data[0]

        return self.get_provider().sociallogin_from_response(
            request,
            extra_data.json()
        )


oauth_login = OAuth2LoginView.adapter_view(DropboxOAuth2Adapter)
oauth_callback = OAuth2CallbackView.adapter_view(DropboxOAuth2Adapter)
Example #8
0
import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import APDAOnlineProvider


class APDAOnlineOAuth2Adapter(OAuth2Adapter):
    provider_id = APDAOnlineProvider.id

    access_token_url = "https://apda.online/oauth/token"
    authorize_url = "https://apda.online/oauth/authorize"
    profile_url = "https://apda.online/oauth/me"

    def complete_login(self, request, app, token, **kwargs):
        headers = {"Authorization": "Bearer {0}".format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(APDAOnlineOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(APDAOnlineOAuth2Adapter)
Example #9
0
        resp.raise_for_status()
        data = ET.fromstring(resp.content.decode())[1]

        result_dict = {}
        for d in data:
            if d.text:
                value = d.text.strip()
                if d.tag == "displayname":
                    result_dict["name"] = value
                    if len(name_parts := d.text.strip().split(" ")) == 2:
                        result_dict["first_name"] = name_parts[0]
                        result_dict["second_name"] = name_parts[1]
                elif d.tag == "id":
                    result_dict["username"] = value
                result_dict[d.tag] = value

            # The 'groups' tag doesn't contain plain text, but a list of group strings
            if d.tag == 'groups':
                result_dict[d.tag] = ", ".join([e.text for e in d])

        # Our login fails if the nextcloud user doesn't have a valid email. This shouldn't be the case.
        if {"email", "username", "name"} - result_dict.keys():
            raise ValueError(
                f"Missing user details (email, username or name) in nextcloud account for user {user_id}."
            )
        return result_dict


oauth2_login = OAuth2LoginView.adapter_view(CustomNextCloudAdapter)
oauth2_callback = OAuth2CallbackView.adapter_view(CustomNextCloudAdapter)
Example #10
0
                error = AuthError.UNKNOWN
            return render_authentication_error(request,
                                               self.adapter.provider_id,
                                               error=error)
        app = self.adapter.get_provider().get_app(self.request)
        client = self.get_client(request, app)
        try:
            access_token = client.get_access_token(request.GET["code"])
            token = self.adapter.parse_token(access_token)
            token.app = app
            login = self.adapter.complete_login(request,
                                                app,
                                                token,
                                                response=access_token)
            login.token = token
            if self.adapter.supports_state:
                login.state = SocialLogin.verify_and_unstash_state(
                    request, get_request_param(request, "state"))
            else:
                login.state = SocialLogin.unstash_state(request)
            return complete_social_login(request, login)
        except (PermissionDenied, OAuth2Error, RequestException,
                ProviderException) as e:
            return render_authentication_error(request,
                                               self.adapter.provider_id,
                                               exception=e)


oauth2_login = OAuth2LoginView.adapter_view(PEAMUOAuth2Adapter)
oauth2_callback = PEAMUOAuth2CallbackView.adapter_view(PEAMUOAuth2Adapter)
Example #11
0
                                               self.adapter.provider_id,
                                               error=error)
        app = self.adapter.get_provider().get_app(self.request)
        client = self.get_client(request, app)
        try:
            access_token = client.get_access_token(request.GET['code'])
            token = self.adapter.parse_token(access_token)
            token.app = app
            login = self.adapter.complete_login(request,
                                                app,
                                                token,
                                                response=access_token)
            login.token = token
            if self.adapter.supports_state:
                login.state = SocialLogin \
                    .verify_and_unstash_state(
                        request,
                        get_request_param(request, 'state'))
            else:
                login.state = SocialLogin.unstash_state(request)
            return complete_social_login(request, login)
        except (PermissionDenied, OAuth2Error, RequestException,
                ProviderException) as e:
            return render_authentication_error(request,
                                               self.adapter.provider_id,
                                               exception=e)


oauth2_login = OAuth2LoginView.adapter_view(SlackOAuth2Adapter)
oauth2_callback = CustomOAuth2CallbackView.adapter_view(SlackOAuth2Adapter)
Example #12
0
    provider_id = DootixProvider.id

    client_class = OAuth2Client

    # Fetched programmatically, must be reachable from container
    access_token_url = "{}/oauth/token".format(
        settings.AUTH_PROVIDER_DOOTIX_URL)

    # URL to reach Dootix login form
    authorize_url = "{}/oauth/authorize".format(
        settings.AUTH_PROVIDER_DOOTIX_URL)
    profile_url = "{}/api/user".format(settings.AUTH_PROVIDER_DOOTIX_URL)

    def complete_login(self, request, app, token, **kwargs) -> SocialLogin:
        headers = {"Authorization": "Bearer {0}".format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)

    def get_callback_url(self, request, app):
        callback_url = reverse(self.provider_id + "_callback")
        protocol = self.redirect_uri_protocol
        callback_url = build_absolute_uri(request, callback_url, protocol)

        return build_absolute_uri(request, callback_url, protocol)


oauth2_login = OAuth2LoginView.adapter_view(DootixAdapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DootixAdapter)
Example #13
0
from custom_discord_auth.provider import CustomDiscordProvider
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from django.conf import settings


class DiscordOAuth2Adapter(OAuth2Adapter):
    provider_id = CustomDiscordProvider.id
    access_token_url = 'https://discordapp.com/api/oauth2/token'
    authorize_url = 'https://discordapp.com/api/oauth2/authorize'
    profile_url = 'https://discordapp.com/api/users/@me'

    def complete_login(self, request, app, token, **kwargs):
        headers = {
            'Authorization': 'Bearer {0}'.format(token.token),
            'Content-Type': 'application/json',
        }
        extra_data = requests.get(self.profile_url, headers=headers)

        return self.get_provider().sociallogin_from_response(
            request, extra_data.json())


oauth2_login = OAuth2LoginView.adapter_view(DiscordOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DiscordOAuth2Adapter)
Example #14
0
    extra_data = parsed['response']
    login = provider.sociallogin_from_response(request, extra_data)
    return login


class NaverOAuth2Adapter(OAuth2Adapter):
    provider_id = NaverProvider.id
    authorize_url = AUTH_HOST + '/oauth2.0/authorize'
    access_token_url = AUTH_HOST + '/oauth2.0/token'

    def complete_login(self, request, app, access_token, **kwargs):
        return naver_complete_login(request, app, access_token)


oauth2_login = OAuth2LoginView.adapter_view(NaverOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(NaverOAuth2Adapter)


def login_by_token(request):
    ret = None
    auth_exception = None

    if request.method == 'POST':
        form = NaverConnectForm(request.POST)
        if form.is_valid():
            try:
                provider = providers.registry.by_id(NaverProvider.id)
                app = providers.registry.by_id(
                    NaverProvider.id).get_app(request)
                access_token = form.cleaned_data['access_token']
Example #15
0
    # ORCID Public API (not Member API):
    # http://support.orcid.org/knowledgebase/articles/335483-the-public-
    # client-orcid-api

    #authorize_url = 'http://sandbox.orcid.org/oauth/authorize'
    #access_token_url = 'https://api.sandbox.orcid.org/oauth/token'
    #profile_url = 'http://pub.sandbox.orcid.org//v1.2/%s/orcid-profile'


    authorize_url = 'https://orcid.org/oauth/authorize'
    access_token_url = 'https://pub.orcid.org/oauth/token'
    profile_url = 'http://pub.orcid.org/v1.2/%s/orcid-profile'


    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url % kwargs['response']['orcid'],
                            #TODO - uncomment this for production registry - params={'access_token': token.token},
                            headers={'accept': 'application/orcid+json'})
        extra_data = resp.json()


        prov = self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


        return prov


oauth2_login = OAuth2LoginView.adapter_view(OrcidOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(OrcidOAuth2Adapter)
Example #16
0
import requests

from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
from .provider import InstagramProvider


class InstagramOAuth2Adapter(OAuth2Adapter):
    provider_id = InstagramProvider.id
    access_token_url = 'https://api.instagram.com/oauth/access_token'
    authorize_url = 'https://api.instagram.com/oauth/authorize'
    profile_url = 'https://api.instagram.com/v1/users/self'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(InstagramOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(InstagramOAuth2Adapter)
Example #17
0
                                                          OAuth2CallbackView)
from allauth.socialaccount.models import SocialAccount, SocialLogin
from allauth.socialaccount.adapter import get_adapter

from provider import SoundCloudProvider

class SoundCloudOAuth2Adapter(OAuth2Adapter):
    provider_id = SoundCloudProvider.id
    access_token_url = 'https://api.soundcloud.com/oauth2/token'
    authorize_url = 'https://soundcloud.com/connect'
    profile_url = 'https://api.soundcloud.com/me.json'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={ 'oauth_token': token.token })
        extra_data = resp.json()
        uid = str(extra_data['id'])
        user = get_adapter() \
            .populate_new_user(name=extra_data.get('full_name'),
                               username=extra_data.get('username'),
                               email=extra_data.get('email'))
        account = SocialAccount(user=user,
                                uid=uid,
                                extra_data=extra_data,
                                provider=self.provider_id)
        return SocialLogin(account)

oauth2_login = OAuth2LoginView.adapter_view(SoundCloudOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(SoundCloudOAuth2Adapter)

Example #18
0
import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import SpotifyOAuth2Provider


class SpotifyOAuth2Adapter(OAuth2Adapter):
    provider_id = SpotifyOAuth2Provider.id
    access_token_url = 'https://accounts.spotify.com/api/token'
    authorize_url = 'https://accounts.spotify.com/authorize'
    profile_url = 'https://api.spotify.com/v1/me'

    def complete_login(self, request, app, token, **kwargs):
        extra_data = requests.get(self.profile_url,
                                  params={'access_token': token.token})

        return self.get_provider().sociallogin_from_response(
            request, extra_data.json())


oauth_login = OAuth2LoginView.adapter_view(SpotifyOAuth2Adapter)
oauth_callback = OAuth2CallbackView.adapter_view(SpotifyOAuth2Adapter)
Example #19
0
class DwollaOAuth2Adapter(OAuth2Adapter):
    """Dwolla Views Adapter"""

    scope_delimiter = '|'

    provider_id = DwollaProvider.id
    access_token_url = TOKEN_URL
    authorize_url = AUTH_URL

    def complete_login(self, request, app, token, response, **kwargs):

        resp = requests.get(
            response['_links']['account']['href'],
            headers={
                'authorization': 'Bearer %s' % token.token,
                'accept': 'application/vnd.dwolla.v1.hal+json',
            },
        )

        extra_data = resp.json()

        return self.get_provider().sociallogin_from_response(
            request,
            extra_data
        )


oauth2_login = OAuth2LoginView.adapter_view(DwollaOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DwollaOAuth2Adapter)
Example #20
0
"""Views for Eventbrite API v3."""
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)
import requests

from .provider import EventbriteProvider


class EventbriteOAuth2Adapter(OAuth2Adapter):
    """OAuth2Adapter for Eventbrite API v3."""

    provider_id = EventbriteProvider.id

    authorize_url = 'https://www.eventbrite.com/oauth/authorize'
    access_token_url = 'https://www.eventbrite.com/oauth/token'
    profile_url = 'https://www.eventbriteapi.com/v3/users/me/'

    def complete_login(self, request, app, token, **kwargs):
        """Complete login."""
        resp = requests.get(self.profile_url, params={'token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(EventbriteOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(EventbriteOAuth2Adapter)
Example #21
0
import requests

from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)

from .provider import GoogleProvider


class GoogleOAuth2Adapter(OAuth2Adapter):
    provider_id = GoogleProvider.id
    access_token_url = 'https://accounts.google.com/o/oauth2/token'
    authorize_url = 'https://accounts.google.com/o/oauth2/auth'
    profile_url = 'https://www.googleapis.com/oauth2/v1/userinfo'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token,
                                    'alt': 'json'})
        resp.raise_for_status()
        extra_data = resp.json()
        login = self.get_provider() \
            .sociallogin_from_response(request,
                                       extra_data)
        return login


oauth2_login = OAuth2LoginView.adapter_view(GoogleOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GoogleOAuth2Adapter)
Example #22
0
class FacebookOAuth2Adapter(OAuth2Adapter):
    provider_id = FacebookProvider.id
    provider_default_auth_url = 'https://www.facebook.com/dialog/oauth'

    settings = app_settings.PROVIDERS.get(provider_id, {})

    authorize_url = settings.get('AUTHORIZE_URL', provider_default_auth_url)
    access_token_url = GRAPH_API_URL + '/oauth/access_token'
    expires_in_key = 'expires_in'

    def complete_login(self, request, app, access_token, **kwargs):
        return fb_complete_login(request, app, access_token)


oauth2_login = OAuth2LoginView.adapter_view(FacebookOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FacebookOAuth2Adapter)


def login_by_token(request):
    ret = None
    auth_exception = None
    if request.method == 'POST':
        form = FacebookConnectForm(request.POST)
        if form.is_valid():
            try:
                provider = providers.registry.by_id(FacebookProvider.id,
                                                    request)
                login_options = provider.get_fb_login_options(request)
                app = provider.get_app(request)
                access_token = form.cleaned_data['access_token']
Example #23
0
import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import SpotifyOAuth2Provider


class SpotifyOAuth2Adapter(OAuth2Adapter):
    provider_id = SpotifyOAuth2Provider.id
    access_token_url = 'https://accounts.spotify.com/api/token'
    authorize_url = 'https://accounts.spotify.com/authorize'
    profile_url = 'https://api.spotify.com/v1/me'

    def complete_login(self, request, app, token, **kwargs):
        extra_data = requests.get(self.profile_url, params={
            'access_token': token.token
        })

        return self.get_provider().sociallogin_from_response(
            request,
            extra_data.json()
        )


oauth_login = OAuth2LoginView.adapter_view(SpotifyOAuth2Adapter)
oauth_callback = OAuth2CallbackView.adapter_view(SpotifyOAuth2Adapter)
Example #24
0
    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'token {}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        resp.raise_for_status()
        extra_data = resp.json()
        if app_settings.QUERY_EMAIL and not extra_data.get('email'):
            extra_data['email'] = self.get_email(headers)
        return self.get_provider().sociallogin_from_response(
            request, extra_data)

    def get_email(self, headers):
        email = None
        resp = requests.get(self.emails_url, headers=headers)
        resp.raise_for_status()
        emails = resp.json()
        if resp.status_code == 200 and emails:
            email = emails[0]
            primary_emails = [
                e for e in emails
                if not isinstance(e, dict) or e.get('primary')
            ]
            if primary_emails:
                email = primary_emails[0]
            if isinstance(email, dict):
                email = email.get('email', '')
        return email


oauth2_login = OAuth2LoginView.adapter_view(GitHubOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GitHubOAuth2Adapter)
Example #25
0
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)

from .provider import CoinbaseProvider

class CoinbaseOAuth2Adapter(OAuth2Adapter):
    provider_id = CoinbaseProvider.id
    supports_state = False

    @property
    def authorize_url(self):
        return 'https://coinbase.com/oauth/authorize'

    @property
    def access_token_url(self):
        return 'https://coinbase.com/oauth/token'

    @property
    def profile_url(self):
        return 'https://coinbase.com/api/v1/users'

    def complete_login(self, request, app, token, **kwargs):
        response = requests.get(self.profile_url,
                                params={'access_token': token})
        extra_data = response.json()['users'][0]['user']
        return self.get_provider().sociallogin_from_response(request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(CoinbaseOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(CoinbaseOAuth2Adapter)
Example #26
0
            overridden in your url configuration if you have more than one
            callback endpoint.
    """

    add_apple_session(request)

    # Add regular OAuth2 params to the URL - reduces the overrides required
    keys_to_put_in_url = ["code", "state", "error"]
    url_params = {}
    for key in keys_to_put_in_url:
        value = get_request_param(request, key, "")
        if value:
            url_params[key] = value

    # Add other params to the apple_login_session
    keys_to_save_to_session = ["user", "access_token"]
    for key in keys_to_save_to_session:
        request.apple_login_session[key] = get_request_param(request, key, "")

    url = request.build_absolute_uri(reverse(finish_endpoint_name))
    response = HttpResponseRedirect("{url}?{query}".format(
        url=url, query=urlencode(url_params)
    ))
    persist_apple_session(request, response)
    return response


oauth2_login = OAuth2LoginView.adapter_view(AppleOAuth2Adapter)
oauth2_callback = apple_post_callback
oauth2_finish_login = OAuth2CallbackView.adapter_view(AppleOAuth2Adapter)
Example #27
0
import requests


class GitLabOAuth2Adapter(OAuth2Adapter):
    provider_id = GitLabProvider.id
    provider_default_url = 'https://gitlab.com'
    provider_api_version = 'v3'

    settings = app_settings.PROVIDERS.get(provider_id, {})
    provider_base_url = settings.get('GITLAB_URL', provider_default_url)

    access_token_url = '{0}/oauth/token'.format(provider_base_url)
    authorize_url = '{0}/oauth/authorize'.format(provider_base_url)
    profile_url = '{0}/api/{1}/user'.format(
        provider_base_url, provider_api_version
    )

    def complete_login(self, request, app, token, response):
        extra_data = requests.get(self.profile_url, params={
            'access_token': token.token
        })

        return self.get_provider().sociallogin_from_response(
            request,
            extra_data.json()
        )


oauth2_login = OAuth2LoginView.adapter_view(GitLabOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GitLabOAuth2Adapter)
Example #28
0
    OAuth2LoginView,
)

from .provider import FoursquareProvider


class FoursquareOAuth2Adapter(OAuth2Adapter):
    provider_id = FoursquareProvider.id
    access_token_url = 'https://foursquare.com/oauth2/access_token'
    # Issue ?? -- this one authenticates over and over again...
    # authorize_url = 'https://foursquare.com/oauth2/authorize'
    authorize_url = 'https://foursquare.com/oauth2/authenticate'
    profile_url = 'https://api.foursquare.com/v2/users/self'

    def complete_login(self, request, app, token, **kwargs):
        # Foursquare needs a version number for their API requests as
        # documented here
        # https://developer.foursquare.com/overview/versioning
        resp = requests.get(self.profile_url,
                            params={
                                'oauth_token': token.token,
                                'v': '20140116'
                            })
        extra_data = resp.json()['response']['user']
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(FoursquareOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FoursquareOAuth2Adapter)
                                                          OAuth2CallbackView)
from .provider import WindowsLiveProvider


class WindowsLiveOAuth2Adapter(OAuth2Adapter):
    provider_id = WindowsLiveProvider.id
    access_token_url = 'https://login.live.com/oauth20_token.srf'
    authorize_url = 'https://login.live.com/oauth20_authorize.srf'
    profile_url = 'https://apis.live.net/v5.0/me'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)

#example of whats returned (in python format):
#{'first_name': 'James', 'last_name': 'Smith',
# 'name': 'James Smith', 'locale': 'en_US', 'gender': None,
# 'emails': {'personal': None, 'account': '*****@*****.**',
# 'business': None, 'preferred': '*****@*****.**'},
# 'link': 'https://profile.live.com/',
# 'updated_time': '2014-02-07T00:35:27+0000',
# 'id': '83605e110af6ff98'}

        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(WindowsLiveOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(WindowsLiveOAuth2Adapter)
Example #30
0
from allauth.socialaccount.providers.gumroad.provider import GumroadProvider
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)


class GumroadOauth2Adapter(OAuth2Adapter):
    provider_id = GumroadProvider.id
    supports_state = True

    settings = app_settings.PROVIDERS.get(provider_id, {})
    provider_base_url = settings.get("GUMROAD_URL")
    access_token_url = "{0}/oauth/token".format(provider_base_url)
    authorize_url = "{0}/oauth/authorize".format(provider_base_url)
    profile_url = "https://api.gumroad.com/v2/user"

    def complete_login(self, request, app, token, response):
        resp = requests.get(self.profile_url,
                            params={"access_token": token.token})
        resp.raise_for_status()
        extra_data = resp.json()

        return self.get_provider().sociallogin_from_response(
            request, extra_data["user"])


oauth2_login = OAuth2LoginView.adapter_view(GumroadOauth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GumroadOauth2Adapter)
Example #31
0
import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import TwentyThreeAndMeProvider


class TwentyTreeAndMeOAuth2Adapter(OAuth2Adapter):
    provider_id = TwentyThreeAndMeProvider.id
    access_token_url = 'https://api.twentythreeandme.com/token'
    authorize_url = 'https://api.twentythreeandme.com/authorize'
    profile_url = 'https://api.twentythreeandme.com/1/user/'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(TwentyTreeAndMeOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(TwentyTreeAndMeOAuth2Adapter)
Example #32
0
    access_token_url = '{0}/oauth2/token'.format(provider_base_url)
    authorize_url = '{0}/oauth2/authorize'.format(provider_base_url)
    profile_url = '{0}/oauth2/userinfo?schema=openid'.format(provider_base_url)

    def complete_login(self, request, app, token, response):
        verify_ssl = import_from_settings('WSO2IS_VERIFY_SSL', True)
        extra_data = dict()
        try:
            extra_data = requests.get(self.profile_url,
                                      params={
                                          'access_token': token.token
                                      },
                                      verify=verify_ssl).json()
        except Exception as e:
            logger.error('> complete_login error(2) %s' % (e))

        extra_data = {
            'user_id': extra_data['sub'],
            'id': extra_data['sub'],
            'name': extra_data['sub'],
            'email': extra_data['email']
        }

        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(Wso2isOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(Wso2isOAuth2Adapter)
Example #33
0
import jwt
from allauth.socialaccount.providers.oauth2.views import OAuth2Adapter, OAuth2CallbackView, OAuth2LoginView
from django.conf import settings

from .provider import YleTunnusProvider


class YleTunnusOAuth2Adapter(OAuth2Adapter):
    provider_id = YleTunnusProvider.id
    access_token_url = 'https://auth.api.yle.fi/v1/token'
    authorize_url = 'https://auth.api.yle.fi/v1/authorize'

    def __init__(self, *args, **kwargs):
        self.auth_conf = settings.SOCIALACCOUNT_PROVIDERS['yletunnus']['AUTH_PARAMS']
        app_params = '?app_id={}&app_key={}'.format(self.auth_conf['app_id'],
                                                    self.auth_conf['app_key'])
        self.access_token_url += app_params
        return super(YleTunnusOAuth2Adapter, self).__init__(*args, **kwargs)

    def complete_login(self, request, app, token, **kwargs):
        data = jwt.decode(token.token, secret=app.secret, verify=False)
        return self.get_provider().sociallogin_from_response(request, data)


oauth2_login = OAuth2LoginView.adapter_view(YleTunnusOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(YleTunnusOAuth2Adapter)
Example #34
0
TOKEN_URL = ENVIRONMENTS[ENV]['token_url']


class DwollaOAuth2Adapter(OAuth2Adapter):
    """Dwolla Views Adapter"""

    scope_delimiter = '|'

    provider_id = DwollaProvider.id
    access_token_url = TOKEN_URL
    authorize_url = AUTH_URL

    def complete_login(self, request, app, token, response, **kwargs):

        resp = requests.get(
            response['_links']['account']['href'],
            headers={
                'authorization': 'Bearer %s' % token.token,
                'accept': 'application/vnd.dwolla.v1.hal+json',
            },
        )

        extra_data = resp.json()

        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(DwollaOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DwollaOAuth2Adapter)
Example #35
0
    provider_id = PinterestProvider.id

    provider_default_url = 'api.pinterest.com'
    provider_default_api_version = 'v1'

    settings = app_settings.PROVIDERS.get(provider_id, {})

    provider_base_url = settings.get('PINTEREST_URL', provider_default_url)
    provider_api_version = settings.get(
        'PINTEREST_VERSION',
        provider_default_api_version)

    access_token_url = 'https://{0}/{1}/oauth/token'.format(
        provider_base_url, provider_api_version
    )
    authorize_url = 'https://{0}/oauth/'.format(provider_base_url)
    profile_url = 'https://{0}/{1}/me'.format(
        provider_base_url, provider_api_version
    )

    def complete_login(self, request, app, token, **kwargs):
        response = requests.get(self.profile_url,
                                params={'access_token': token.token})
        extra_data = response.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(PinterestOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(PinterestOAuth2Adapter)
Example #36
0
from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter
from allauth.socialaccount.providers.oauth2.views import OAuth2LoginView, OAuth2CallbackView
from .provider import CustomGoogleProvider

class CustomGoogleOAuth2Adapter(GoogleOAuth2Adapter):
  provider_id = CustomGoogleProvider.id

oauth2_login = OAuth2LoginView.adapter_view(CustomGoogleOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(CustomGoogleOAuth2Adapter)
Example #37
0
import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import BaiduProvider


class BaiduOAuth2Adapter(OAuth2Adapter):
    provider_id = BaiduProvider.id
    access_token_url = 'https://openapi.baidu.com/oauth/2.0/token'
    authorize_url = 'https://openapi.baidu.com/oauth/2.0/authorize'
    profile_url = 'https://openapi.baidu.com/rest/2.0/passport/users/getLoggedInUser'  # noqa

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(BaiduOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(BaiduOAuth2Adapter)
Example #38
0
    access_token_method = 'POST'
    authorize_url = wiki_oauth_url + '/authorize'
    authorize_url_method = 'GET'
    profile_url = wiki_oauth_url + '/resource/profile'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        resp.raise_for_status()
        extra_data = resp.json()
        login = self.get_provider() \
            .sociallogin_from_response(request,
                                       extra_data)
        return login


class WikimediaCommonsOAuth2CallbackView(OAuth2CallbackView):
    """ Custom OAuth2CallbackView to return WikimediaCommonsOAuth2Client """

    def get_client(self, request, app):
        client = super(WikimediaCommonsOAuth2CallbackView, self).get_client(request, app)
        wikimedia_commons_client = WikimediaCommonsOAuth2Client(
            client.request, client.consumer_key, client.consumer_secret,
            client.access_token_method, client.access_token_url,
            client.callback_url, client.scope)
        return wikimedia_commons_client


oauth2_login = OAuth2LoginView.adapter_view(WikimediaCommonsOAuth2Adapter)
oauth2_callback = WikimediaCommonsOAuth2CallbackView.adapter_view(WikimediaCommonsOAuth2Adapter)
Example #39
0
                            extra_data=extra_data,
                            user=user)
    return SocialLogin(account)


class FacebookOAuth2Adapter(OAuth2Adapter):
    provider_id = FacebookProvider.id

    authorize_url = 'https://www.facebook.com/dialog/oauth'
    access_token_url = 'https://graph.facebook.com/oauth/access_token'

    def complete_login(self, request, app, access_token):
        return fb_complete_login(app, access_token)


oauth2_login = OAuth2LoginView.adapter_view(FacebookOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FacebookOAuth2Adapter)


def login_by_token(request):
    ret = None
    if request.method == 'POST':
        form = FacebookConnectForm(request.POST)
        if form.is_valid():
            try:
                app = providers.registry.by_id(FacebookProvider.id) \
                    .get_app(request)
                access_token = form.cleaned_data['access_token']
                token = SocialToken(app=app,
                                    token=access_token)
                login = fb_complete_login(app, token)
Example #40
0
    @property
    def authorize_url(self):
        return self.battlenet_base_url + "/oauth/authorize"

    @property
    def profile_url(self):
        return self.battlenet_api_url + "/account/user"

    def complete_login(self, request, app, token, **kwargs):
        params = {"access_token": token.token}
        response = requests.get(self.profile_url, params=params)
        data = response.json()
        _check_errors(data)

        # Add the region to the data so that we can have it in `extra_data`.
        data["region"] = self.battlenet_region

        return self.get_provider().sociallogin_from_response(request, data)

    def get_callback_url(self, request, app):
        r = super(BattleNetOAuth2Adapter, self).get_callback_url(request, app)
        region = request.GET.get("region", "").lower()
        # Pass the region down to the callback URL if we specified it
        if region and region in self.valid_regions:
            r += "?region=%s" % (region)
        return r


oauth2_login = OAuth2LoginView.adapter_view(BattleNetOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(BattleNetOAuth2Adapter)
Example #41
0
    def get_user_info(self, token):
        info = {}
        resp = requests.get(
            self.auth_test_url,
            params={'token': token.token}
        )
        resp = resp.json()

        if not resp.get('ok'):
            raise OAuth2Error()

        info['team_url'] = resp['url']
        info['user_id'] = resp['user_id']
        info['team_id'] = resp['team_id']

        user = requests.get(
            self.profile_url,
            params={'token': token.token, 'user': resp['user_id']}
        )

        user = user.json()
        if not user['ok']:
            raise OAuth2Error()

        info.update(user['user'])
        return info


oauth2_login = OAuth2LoginView.adapter_view(SlackOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(SlackOAuth2Adapter)
Example #42
0
from .provider import LinkedInOAuth2Provider


class LinkedInOAuth2Adapter(OAuth2Adapter):
    provider_id = LinkedInOAuth2Provider.id
    access_token_url = 'https://www.linkedin.com/oauth/v2/accessToken'
    authorize_url = 'https://www.linkedin.com/oauth/v2/authorization'
    profile_url = 'https://api.linkedin.com/v1/people/~'
    # See:
    # http://developer.linkedin.com/forum/unauthorized-invalid-or-expired-token-immediately-after-receiving-oauth2-token?page=1 # noqa
    access_token_method = 'GET'

    def complete_login(self, request, app, token, **kwargs):
        extra_data = self.get_user_info(token)
        return self.get_provider().sociallogin_from_response(
            request, extra_data)

    def get_user_info(self, token):
        fields = self.get_provider().get_profile_fields()
        url = self.profile_url + ':(%s)?format=json' % ','.join(fields)
        headers = {}
        headers.update(self.get_provider().get_settings().get('HEADERS', {}))
        headers['Authorization'] = ' '.join(['Bearer', token.token])
        resp = requests.get(url, headers=headers)
        resp.raise_for_status()
        return resp.json()


oauth2_login = OAuth2LoginView.adapter_view(LinkedInOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(LinkedInOAuth2Adapter)
Example #43
0
from .provider import LinkedInOAuth2Provider


class LinkedInOAuth2Adapter(OAuth2Adapter):
    provider_id = LinkedInOAuth2Provider.id
    access_token_url = 'https://api.linkedin.com/uas/oauth2/accessToken'
    authorize_url = 'https://www.linkedin.com/uas/oauth2/authorization'
    profile_url = 'https://api.linkedin.com/v1/people/~'
    # See:
    # http://developer.linkedin.com/forum/unauthorized-invalid-or-expired-token-immediately-after-receiving-oauth2-token?page=1 # noqa
    access_token_method = 'GET'

    def complete_login(self, request, app, token, **kwargs):
        extra_data = self.get_user_info(token)
        return self.get_provider().sociallogin_from_response(
            request, extra_data)

    def get_user_info(self, token):
        fields = self.get_provider().get_profile_fields()
        url = self.profile_url + ':(%s)?format=json' % ','.join(fields)
        resp = requests.get(url,
                            headers={'Authorization': ' '.join(('Bearer',
                                     token.token)), 'x-li-src': 'msdk'})
        resp.raise_for_status()
        return resp.json()


oauth2_login = OAuth2LoginView.adapter_view(LinkedInOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(LinkedInOAuth2Adapter)
Example #44
0
from .provider import WindowsLiveProvider


class WindowsLiveOAuth2Adapter(OAuth2Adapter):
    provider_id = WindowsLiveProvider.id
    access_token_url = 'https://login.live.com/oauth20_token.srf'
    authorize_url = 'https://login.live.com/oauth20_authorize.srf'
    profile_url = 'https://apis.live.net/v5.0/me'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)

        # example of whats returned (in python format):
        # {'first_name': 'James', 'last_name': 'Smith',
        #  'name': 'James Smith', 'locale': 'en_US', 'gender': None,
        #  'emails': {'personal': None, 'account': '*****@*****.**',
        #  'business': None, 'preferred': '*****@*****.**'},
        #  'link': 'https://profile.live.com/',
        #  'updated_time': '2014-02-07T00:35:27+0000',
        #  'id': '83605e110af6ff98'}

        resp.raise_for_status()
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(WindowsLiveOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(WindowsLiveOAuth2Adapter)
Example #45
0
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import EventbriteProvider


class EventbriteOAuth2Adapter(OAuth2Adapter):

    """OAuth2Adapter for Eventbrite API v3."""

    provider_id = EventbriteProvider.id

    authorize_url = 'https://www.eventbrite.com/oauth/authorize'
    access_token_url = 'https://www.eventbrite.com/oauth/token'
    profile_url = 'https://www.eventbriteapi.com/v3/users/me/'

    def complete_login(self, request, app, token, **kwargs):
        """Complete login."""
        resp = requests.get(self.profile_url, params={'token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(EventbriteOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(EventbriteOAuth2Adapter)
Example #46
0
import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import BaiduProvider


class BaiduOAuth2Adapter(OAuth2Adapter):
    provider_id = BaiduProvider.id
    access_token_url = "https://openapi.baidu.com/oauth/2.0/token"
    authorize_url = "https://openapi.baidu.com/oauth/2.0/authorize"
    profile_url = (
        "https://openapi.baidu.com/rest/2.0/passport/users/getLoggedInUser"  # noqa
    )

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={"access_token": token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(BaiduOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(BaiduOAuth2Adapter)
Example #47
0
    profile_test = 'https://sandbox-accounts.platform.intuit.com/v1/openid_connect/userinfo' # NOQA
    profile_url = \
        'https://accounts.platform.intuit.com/v1/openid_connect/userinfo'
    profile_url_method = 'GET'
    access_token_method = 'POST'

    def complete_login(self, request, app, token, **kwargs):
        resp = self.get_user_info(token)
        extra_data = resp
        return self.get_provider().sociallogin_from_response(
            request, extra_data)

    def get_user_info(self, token):
        auth_header = 'Bearer ' + token.token
        headers = {'Accept': 'application/json',
                   'Authorization': auth_header,
                   'accept': 'application/json'
                   }
        QBO_sandbox = self.get_provider().get_settings().get('SANDBOX', False)
        if QBO_sandbox:
            r = requests.get(self.profile_test, headers=headers)
        else:
            r = requests.get(self.profile_url, headers=headers)
#        status_code = r.status_code
        response = json.loads(r.text)
        return response


oauth2_login = OAuth2LoginView.adapter_view(QuickBooksOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(QuickBooksOAuth2Adapter)
Example #48
0
from .provider import RobinhoodProvider


class RobinhoodOAuth2Adapter(OAuth2Adapter):
    provider_id = RobinhoodProvider.id

    @property
    def authorize_url(self):
        return 'https://www.robinhood.com/oauth2/authorize/'

    @property
    def access_token_url(self):
        return 'https://api.robinhood.com/oauth2/token/'

    @property
    def profile_url(self):
        return 'https://api.robinhood.com/user/id/'

    def complete_login(self, request, app, token, **kwargs):
        response = requests.get(
            self.profile_url,
            headers={'Authorization': 'Bearer %s' % token.token})
        extra_data = response.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(RobinhoodOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(RobinhoodOAuth2Adapter)
Example #49
0
from provider import RedboothProvider

User = get_user_model()


class RedboothOAuth2Adapter(OAuth2Adapter):
    provider_id = RedboothProvider.id
    access_token_url = "https://redbooth.com/oauth/token"
    authorize_url = "https://redbooth.com/oauth/authorize"
    profile_url = "https://redbooth.com/api/1/account"

    def complete_login(self, request, app, token):
        resp = requests.get(
            self.profile_url, params={"access_token": token.token}, disable_ssl_certificate_validation=True
        )
        extra_data = resp.json
        uid = str(extra_data["id"])
        user = User(
            username=extra_data.get("username", ""),
            email=extra_data.get("email", ""),
            first_name=extra_data.get("first_name", ""),
            last_name=extra_data.get("last_name", ""),
        )
        account = SocialAccount(user=user, uid=uid, extra_data=extra_data, provider=self.provider_id)
        return SocialLogin(account)


oauth2_login = OAuth2LoginView.adapter_view(RedboothOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(RedboothOAuth2Adapter)
Example #50
0
from __future__ import unicode_literals

import requests

from allauth.socialaccount import app_settings
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import FeedlyProvider


class FeedlyOAuth2Adapter(OAuth2Adapter):
    provider_id = FeedlyProvider.id
    host = app_settings.PROVIDERS.get(provider_id, {}).get("HOST", "cloud.feedly.com")
    access_token_url = "https://%s/v3/auth/token" % host
    authorize_url = "https://%s/v3/auth/auth" % host
    profile_url = "https://%s/v3/profile" % host

    def complete_login(self, request, app, token, **kwargs):
        headers = {"Authorization": "OAuth {0}".format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(FeedlyOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FeedlyOAuth2Adapter)
Example #51
0
import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import EveOnlineProvider


class EveOnlineOAuth2Adapter(OAuth2Adapter):
    provider_id = EveOnlineProvider.id
    access_token_url = 'https://login.eveonline.com/oauth/token'
    authorize_url = 'https://login.eveonline.com/oauth/authorize'
    profile_url = 'https://login.eveonline.com/oauth/verify'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            headers={'Authorization': 'Bearer ' + token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(EveOnlineOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(EveOnlineOAuth2Adapter)
Example #52
0
USER_FIELDS = [
    'first_name', 'last_name', 'nickname', 'screen_name', 'sex', 'bdate',
    'city', 'country', 'timezone', 'photo', 'photo_medium', 'photo_big',
    'has_mobile', 'contacts', 'education', 'online', 'counters', 'relation',
    'last_seen', 'activity', 'universities'
]


class VKOAuth2Adapter(OAuth2Adapter):
    provider_id = VKProvider.id
    access_token_url = 'https://oauth.vk.com/access_token'
    authorize_url = 'http://oauth.vk.com/authorize'
    profile_url = 'https://api.vk.com/method/users.get'

    def complete_login(self, request, app, token, **kwargs):
        uid = kwargs['response']['user_id']
        resp = requests.get(self.profile_url,
                            params={
                                'access_token': token.token,
                                'fields': ','.join(USER_FIELDS),
                                'user_ids': uid
                            })
        resp.raise_for_status()
        extra_data = resp.json()['response'][0]
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(VKOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(VKOAuth2Adapter)
Example #53
0
import requests

from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
from .provider import InstagramProvider


class InstagramOAuth2Adapter(OAuth2Adapter):
    provider_id = InstagramProvider.id
    access_token_url = 'https://api.instagram.com/oauth/access_token'
    authorize_url = 'https://api.instagram.com/oauth/authorize'
    profile_url = 'https://api.instagram.com/v1/users/self'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(InstagramOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(InstagramOAuth2Adapter)
Example #54
0
import requests

from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
from .provider import FirefoxAccountsProvider


class FirefoxAccountsOAuth2Adapter(OAuth2Adapter):
    provider_id = FirefoxAccountsProvider.id
    access_token_url = 'https://oauth.accounts.firefox.com/v1/token'
    authorize_url = 'https://oauth.accounts.firefox.com/v1/authorization'
    profile_url = 'https://profile.accounts.firefox.com/v1/profile'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(FirefoxAccountsOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(FirefoxAccountsOAuth2Adapter)
Example #55
0
File: views.py Project: 400yk/Ejub
import requests

from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)

from .provider import WeiboProvider


class WeiboOAuth2Adapter(OAuth2Adapter):
    provider_id = WeiboProvider.id
    access_token_url = 'https://api.weibo.com/oauth2/access_token'
    authorize_url = 'https://api.weibo.com/oauth2/authorize'
    profile_url = 'https://api.weibo.com/2/users/show.json'

    def complete_login(self, request, app, token, **kwargs):
        uid = kwargs.get('response', {}).get('uid')
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token,
                                    'uid': uid})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(WeiboOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(WeiboOAuth2Adapter)
Example #56
0
#import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import EduAppsProvider


class EduAppsOAuth2Adapter(OAuth2Adapter):
    provider_id = EduAppsProvider.id
    access_token_url = 'https://login.eduapps.de/oauth/token'
    authorize_url = 'https://login.eduapps.de/oauth/authorize'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        #resp = requests.get(self.profile_url, headers=headers)
        #extra_data = resp.json()
        extra_data = {}
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(EduAppsOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(EduAppsOAuth2Adapter)
Example #57
0
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import StackExchangeProvider


class StackExchangeOAuth2Adapter(OAuth2Adapter):
    provider_id = StackExchangeProvider.id
    access_token_url = 'https://stackexchange.com/oauth/access_token'
    authorize_url = 'https://stackexchange.com/oauth'
    profile_url = 'https://api.stackexchange.com/2.1/me'

    def complete_login(self, request, app, token, **kwargs):
        provider = self.get_provider()
        site = provider.get_site()
        resp = requests.get(self.profile_url,
                            params={'access_token': token.token,
                                    'key': app.key,
                                    'site': site})
        extra_data = resp.json()['items'][0]
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(StackExchangeOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(StackExchangeOAuth2Adapter)
Example #58
0
class RedditAdapter(OAuth2Adapter):
    provider_id = RedditProvider.id
    access_token_url = 'https://www.reddit.com/api/v1/access_token'
    authorize_url = 'https://www.reddit.com/api/v1/authorize'
    profile_url = 'https://oauth.reddit.com/api/v1/me'
    basic_auth = True

    settings = app_settings.PROVIDERS.get(provider_id, {})
    # Allow custom User Agent to comply with reddit API limits
    headers = {
        'User-Agent': settings.get('USER_AGENT', 'django-allauth-header')}

    def complete_login(self, request, app, token, **kwargs):
        headers = {
            "Authorization": "bearer " + token.token}
        headers.update(self.headers)
        extra_data = requests.get(self.profile_url, headers=headers)

        # This only here because of weird response from the test suite
        if isinstance(extra_data, list):
            extra_data = extra_data[0]

        return self.get_provider().sociallogin_from_response(
            request,
            extra_data.json()
        )


oauth2_login = OAuth2LoginView.adapter_view(RedditAdapter)
oauth2_callback = OAuth2CallbackView.adapter_view(RedditAdapter)
Example #59
0
# -*- coding: utf-8 -*-
import requests
from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)

from .provider import YandexProvider


class YandexOAuth2Adapter(OAuth2Adapter):
    provider_id = YandexProvider.id
    access_token_url = 'https://oauth.yandex.ru/token'
    authorize_url = 'https://oauth.yandex.ru/authorize'
    profile_url = 'https://login.yandex.ru/info'

    def complete_login(self, request, app, token, **kwargs):
        resp = requests.get(self.profile_url,
                            params={'format': 'json',
                                    'oauth_token': token.token})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


oauth2_login = OAuth2LoginView.adapter_view(YandexOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(YandexOAuth2Adapter)
Example #60
0
import requests

from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import BasecampProvider


class BasecampOAuth2Adapter(OAuth2Adapter):
    provider_id = BasecampProvider.id
    access_token_url = 'https://launchpad.37signals.com/authorization/token?type=web_server'  # noqa
    authorize_url = 'https://launchpad.37signals.com/authorization/new'
    profile_url = 'https://launchpad.37signals.com/authorization.json'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(self.profile_url, headers=headers)
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(BasecampOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(BasecampOAuth2Adapter)