Example #1
0
import requests

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

from .provider import ZohoProvider


class ZohoOAuth2Adapter(OAuth2Adapter):
    provider_id = ZohoProvider.id
    access_token_url = "https://accounts.zoho.com/oauth/v2/token"
    authorize_url = "https://accounts.zoho.com/oauth/v2/auth"
    profile_url = "https://accounts.zoho.com/oauth/user/info"

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


oauth2_login = OAuth2LoginView.adapter_view(ZohoOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(ZohoOAuth2Adapter)
Example #2
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 #3
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 #4
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 #5
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 #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
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)
import requests

from .provider import EdmodoProvider


class EdmodoOAuth2Adapter(OAuth2Adapter):
    provider_id = EdmodoProvider.id
    access_token_url = 'https://api.edmodo.com/oauth/token'
    authorize_url = 'https://api.edmodo.com/oauth/authorize'
    profile_url = 'https://api.edmodo.com/users/me'

    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(EdmodoOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(EdmodoOAuth2Adapter)
Example #9
0
import requests

from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
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 #10
0
from .provider import iHelaProvider
from django.conf import settings


class iHelaAdapter(OAuth2Adapter):
    provider_id = iHelaProvider.id

    # Fetched programmatically, must be reachable from container
    access_token_url = "{}/oAuth2/token/".format(
        settings.IHELA_OAUTH_SERVER_BASEURL)
    profile_url = "{}/api/v1/connected-user/".format(
        settings.IHELA_OAUTH_SERVER_BASEURL)

    # Accessed by the user browser, must be reachable by the host
    authorize_url = "{}/oAuth2/authorize/".format(
        settings.IHELA_OAUTH_SERVER_BASEURL)

    # NOTE: trailing slashes in URLs are important, don't miss it

    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(iHelaAdapter)
oauth2_callback = OAuth2CallbackView.adapter_view(iHelaAdapter)
Example #11
0
import requests

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

from .provider import NaverProvider


class NaverOAuth2Adapter(OAuth2Adapter):
    provider_id = NaverProvider.id
    access_token_url = 'https://nid.naver.com/oauth2.0/token'
    authorize_url = 'https://nid.naver.com/oauth2.0/authorize'
    profile_url = 'https://openapi.naver.com/v1/nid/me'

    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().get('response')
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(NaverOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(NaverOAuth2Adapter)
Example #12
0
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import WebmonitorProvider


class WebmonitorOAuth2Adapter(OAuth2Adapter):
    provider_id = WebmonitorProvider.id
    access_token_url = 'https://oauthtst.webmonitor.global/token'
    authorize_url = 'https://oauthtst.webmonitor.global/authorize'
    profile_url = 'https://oauthtst.webmonitor.global/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(WebmonitorOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(WebmonitorOAuth2Adapter)
Example #13
0
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import EventbriteProvider


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

    provider_id = EventbriteProvider.id
    settings = app_settings.PROVIDERS.get(provider_id, {})
    authorize_url = 'https://%s/oauth/authorize' % (settings.get(
        'EVENTBRITE_HOSTNAME', 'www.eventbrite.com'))
    access_token_url = 'https://%s/oauth/token' % (settings.get(
        'EVENTBRITE_HOSTNAME', 'www.eventbrite.com'))
    profile_url = 'https://%s/v3/users/me/' % (settings.get(
        'EVENTBRITEAPI_HOSTNAME', 'www.eventbriteapi.com'))

    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 #14
0
from allauth.socialaccount.adapter import get_adapter
from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)

from .provider import BitlyProvider


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'

    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 #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
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

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 = ast.literal_eval(kwargs.get('response', {})).get('uid')
        access_token = ast.literal_eval(kwargs.get('response',
                                                   {})).get('access_token')
        resp = requests.get(self.profile_url,
                            params={
                                'access_token': access_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 #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,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
from .provider import (FirefoxAccountsProvider, FXA_OAUTH_ENDPOINT,
                       FXA_PROFILE_ENDPOINT)


class FirefoxAccountsOAuth2Adapter(OAuth2Adapter):
    provider_id = FirefoxAccountsProvider.id
    access_token_url = FXA_OAUTH_ENDPOINT + '/token'
    authorize_url = FXA_OAUTH_ENDPOINT + '/authorization'
    profile_url = FXA_PROFILE_ENDPOINT + '/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 #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
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 #21
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 #22
0
from .provider import MapillaryProvider


class MapillaryOAuth2Adapter(OAuth2Adapter):
    supports_state = False
    provider_id = MapillaryProvider.id
    access_token_url = 'https://a.mapillary.com/v2/oauth/token'
    # Issue ?? -- this one authenticates over and over again...
    # authorize_url = 'https://foursquare.com/oauth2/authorize'
    authorize_url = 'https://www.mapillary.com/connect'

    def complete_login(self, request, app, token, **kwargs):
        profile_url = 'https://a.mapillary.com/v3/me'
        # Foursquare needs a version number for their API requests as
        # documented here
        # https://developer.foursquare.com/overview/versioning
        headers = {'Authorization': 'Bearer {0}'.format(token.token)}
        resp = requests.get(profile_url + '?token=' + token.token +
                            '&client_id=' + app.client_id,
                            headers=headers)
        #    profile_url,
        #  params={'token': token.token, 'client_id': app.client_id})
        extra_data = resp.json()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(MapillaryOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(MapillaryOAuth2Adapter)
Example #23
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 #24
0
import requests

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

from .provider import DoximityProvider


class DoximityOAuth2Adapter(OAuth2Adapter):
    provider_id = DoximityProvider.id
    access_token_url = 'https://auth.doximity.com/oauth/token'
    authorize_url = 'https://auth.doximity.com/oauth/authorize'
    profile_url = 'https://www.doximity.com/api/v1/users/current'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer %s' % 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(DoximityOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DoximityOAuth2Adapter)
Example #25
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 #26
0
class Auth0OAuth2Adapter(OAuth2Adapter):
    provider_id = Auth0Provider.id
    supports_state = True

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

    access_token_url = "{0}/oauth/token".format(provider_base_url)
    authorize_url = "{0}/authorize".format(provider_base_url)
    profile_url = "{0}/userinfo".format(provider_base_url)

    def complete_login(self, request, app, token, response):
        extra_data = requests.get(self.profile_url,
                                  params={
                                      "access_token": token.token
                                  }).json()
        extra_data = {
            "user_id": extra_data["sub"],
            "id": extra_data["sub"],
            "name": extra_data["name"],
            "email": extra_data["email"],
        }

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


oauth2_login = OAuth2LoginView.adapter_view(Auth0OAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(Auth0OAuth2Adapter)
Example #27
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)
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://instagram.com/oauth/access_token'
    authorize_url = 'https://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)
                                                          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
import requests

from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
from linkedevents.providers.turku_oidc.provider import TurkuOIDCProvider
from django.conf import settings


class OIDCOAuth2Adapter(OAuth2Adapter):
    provider_id = TurkuOIDCProvider.id
    access_token_url = '%s/openid/token/' % getattr(
        settings, 'OIDC_API_TOKEN_AUTH')['ISSUER']
    authorize_url = '%s/openid/authorize/' % getattr(
        settings, 'OIDC_API_TOKEN_AUTH')['ISSUER']
    profile_url = '%s/openid/userinfo/' % getattr(
        settings, 'OIDC_API_TOKEN_AUTH')['ISSUER']

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


oauth2_login = OAuth2LoginView.adapter_view(OIDCOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(OIDCOAuth2Adapter)
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
import requests
from django.conf import settings
from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
from .provider import XLMMProvider
from allauth.socialaccount import app_settings


class XLMMOAuth2Adapter(OAuth2Adapter):
    provider_id = XLMMProvider.id
    access_token_url = settings.AUTH_TOKEN_URL
    authorize_url = settings.AUTH_AUTHORIZE_URL
    profile_url = settings.AUTH_PROFILE_URL

    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(XLMMOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(XLMMOAuth2Adapter)
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
from allauth.socialaccount.models import SocialAccount, SocialLogin
from allauth.socialaccount.adapter import get_adapter

from .provider import GitHubProvider


class GitHubOAuth2Adapter(OAuth2Adapter):
    provider_id = GitHubProvider.id
    access_token_url = 'https://github.com/login/oauth/access_token'
    authorize_url = 'https://github.com/login/oauth/authorize'
    profile_url = 'https://api.github.com/user'

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


oauth2_login = OAuth2LoginView.adapter_view(GitHubOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GitHubOAuth2Adapter)
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 .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/~'
    supports_state = False
    # 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 = providers.registry \
            .by_id(LinkedInOAuth2Provider.id) \
            .get_profile_fields()
        url = self.profile_url + ':(%s)?format=json' % ','.join(fields)
        resp = requests.get(url, params={'oauth2_access_token': token.token})
        return resp.json()


oauth2_login = OAuth2LoginView.adapter_view(LinkedInOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(LinkedInOAuth2Adapter)
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
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)
import requests

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)
Example #39
0
                            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)
                login.token = token
Example #40
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'}

        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 #41
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 #42
0
    return login


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'
    expires_in_key = 'expires'

    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
    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(request, app, token)
                login.token = token
                login.state = SocialLogin.state_from_request(request)
Example #43
0
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 #44
0
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)


class GlobusAdapter(OAuth2Adapter):
    provider_id = GlobusProvider.id
    provider_default_url = 'https://auth.globus.org/v2/oauth2'

    provider_base_url = 'https://auth.globus.org/v2/oauth2'

    access_token_url = '{0}/token'.format(provider_base_url)
    authorize_url = '{0}/authorize'.format(provider_base_url)
    profile_url = '{0}/userinfo'.format(provider_base_url)

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

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


oauth2_login = OAuth2LoginView.adapter_view(GlobusAdapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GlobusAdapter)
Example #45
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 #46
0
import requests

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

from .provider import HubicProvider


class HubicOAuth2Adapter(OAuth2Adapter):
    provider_id = HubicProvider.id
    access_token_url = 'https://api.hubic.com/oauth/token'
    authorize_url = 'https://api.hubic.com/oauth/auth'
    profile_url = 'https://api.hubic.com/1.0/account'
    redirect_uri_protocol = 'https'

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


oauth2_login = OAuth2LoginView.adapter_view(HubicOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(HubicOAuth2Adapter)
Example #47
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 #48
0
    @property
    def authorize_url(self):
        return self.battlenet_base_url + "/oauth/authorize"

    @property
    def profile_url(self):
        return self.battlenet_base_url + "/oauth/userinfo"

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

        # 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 #49
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 #50
0
import requests

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


class AngelListOAuth2Adapter(OAuth2Adapter):
    provider_id = AngelListProvider.id
    access_token_url = 'https://angel.co/api/oauth/token/'
    authorize_url = 'https://angel.co/api/oauth/authorize/'
    profile_url = 'https://api.angel.co/1/me/'
    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()
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(AngelListOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(AngelListOAuth2Adapter)
Example #51
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 #52
0
import requests

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

from .provider import VimeoOAuth2Provider


class VimeoOAuth2Adapter(OAuth2Adapter):
    provider_id = VimeoOAuth2Provider.id
    access_token_url = "https://api.vimeo.com/oauth/access_token"
    authorize_url = "https://api.vimeo.com/oauth/authorize"
    profile_url = "https://api.vimeo.com/me/"

    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(VimeoOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(VimeoOAuth2Adapter)
Example #53
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 #54
0
import requests

from allauth.socialaccount.providers.discord.views import DiscordOAuth2Adapter as DiscordAdapter
from allauth.socialaccount.providers.oauth2.views import OAuth2CallbackView, OAuth2LoginView

from discord.provider import DiscordProvider


class CustomDiscordOAuth2Adapter(DiscordAdapter):
    provider_id = DiscordProvider.id
    guilds_url = 'https://discordapp.com/api/users/@me/guilds'

    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).json()
        guild_data = requests.get(self.guilds_url, headers=headers).json()

        extra_data['guilds'] = guild_data if isinstance(guild_data,
                                                        list) else []

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


oauth2_login = OAuth2LoginView.adapter_view(CustomDiscordOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(CustomDiscordOAuth2Adapter)
Example #55
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 .provider import DoubanProvider


class DoubanOAuth2Adapter(OAuth2Adapter):
    provider_id = DoubanProvider.id
    access_token_url = 'https://www.douban.com/service/auth2/token'
    authorize_url = 'https://www.douban.com/service/auth2/auth'
    profile_url = 'https://api.douban.com/v2/user/~me'

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Authorization': 'Bearer %s' % 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(DoubanOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DoubanOAuth2Adapter)
Example #57
0
File: views.py Project: Elchi3/kuma
    We store those email addresses in the extra data of each account.
    """
    email_url = 'https://api.github.com/user/emails'

    def complete_login(self, request, app, token, **kwargs):
        params = {'access_token': token.token}
        profile_data = requests.get(self.profile_url, params=params)
        extra_data = profile_data.json()
        email_data = requests.get(self.email_url, params=params)
        extra_data['email_addresses'] = email_data.json()
        return self.get_provider().sociallogin_from_response(request,
                                                             extra_data)


class KumaOAuth2LoginView(OAuth2LoginView):

    def dispatch(self, request):
        next_url = (get_next_redirect_url(request) or
                    reverse('users.my_edit_page'))
        request.session['sociallogin_next_url'] = next_url
        request.session.modified = True
        return super(KumaOAuth2LoginView, self).dispatch(request)


oauth2_login = redirect_in_maintenance_mode(
    KumaOAuth2LoginView.adapter_view(KumaGitHubOAuth2Adapter)
)
oauth2_callback = redirect_in_maintenance_mode(
    OAuth2CallbackView.adapter_view(KumaGitHubOAuth2Adapter)
)
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
    @property
    def access_token_url(self):
        path = "v1/identity/openidconnect/tokenservice"
        return 'https://api.{0}/{1}'.format(self._get_endpoint(), path)

    @property
    def profile_url(self):
        path = 'v1/identity/openidconnect/userinfo'
        return 'https://api.{0}/{1}'.format(self._get_endpoint(), path)

    def _get_endpoint(self):
        settings = self.get_provider().get_settings()
        if settings.get('MODE') == 'live':
            return 'paypal.com'
        else:
            return 'sandbox.paypal.com'

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


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