Beispiel #1
0
    def post(self, request, format=None):
        """
        Returns the URL to the login page of provider's authentication server.
        """
        # You should have CSRF protection enabled, see
        # https://security.stackexchange.com/a/104390 (point 3).
        # Therefore this is a POST endpoint.
        # This code is inspired by `OAuth2LoginView.dispatch`.
        adapter = self.adapter_class(request)
        provider = adapter.get_provider()
        app = provider.get_app(request)
        view = OAuth2LoginView()
        view.request = request
        view.adapter = adapter
        client = view.get_client(request, app)
        # You can modify `action` if you have more steps in your auth flow
        action = AuthAction.AUTHENTICATE
        auth_params = provider.get_auth_params(request, action)
        # You can omit this if you want to validate the state in the frontend
        #client.state = SocialLogin.stash_state(request)
        url = client.get_redirect_url(adapter.authorize_url, auth_params)
        custom_call_back_url = settings.SOCIAL_AUTH_CUSTOM_CALLBACK

        if custom_call_back_url:
            url = custom_call_back_url
        else:
            url = re.sub('api.', 'app.', url)
            url = re.sub('staging-api.', 'staging-app.', url)

        return Response({'url': url})
Beispiel #2
0
 def post(self, request):
     """Return the URL of provider's authentication server."""
     adapter = self.adapter_class(request)
     provider = adapter.get_provider()
     app = provider.get_app(request)
     view = OAuth2LoginView()
     view.request = request
     view.adapter = adapter
     client = view.get_client(request, app)
     action = AuthAction.AUTHENTICATE
     auth_params = provider.get_auth_params(request, action)
     client.state = SocialLogin.stash_state(request)
     url = client.get_redirect_url(adapter.authorize_url, auth_params)
     return Response({'url': url})
Beispiel #3
0
 def post(self, request, format=None):
     # You should have CSRF protection enabled, see
     # https://security.stackexchange.com/a/104390 (point 3).
     # Therefore this is a POST endpoint.
     # This code is inspired by `OAuth2LoginView.dispatch`.
     adapter = self.adapter_class(request)
     provider = adapter.get_provider()
     app = provider.get_app(request)
     view = OAuth2LoginView()
     view.request = request
     view.adapter = adapter
     client = view.get_client(request, app)
     action = AuthAction.AUTHENTICATE
     auth_params = provider.get_auth_params(request, action)
     client.state = SocialLogin.stash_state(request)
     url = client.get_redirect_url(adapter.authorize_url, auth_params)
     return Response({'url': url})
                                                          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)
Beispiel #5
0
class NetatmoOAuth2Adapter(OAuth2Adapter):
    provider_id = NetAtMoProvider.id
    access_token_url = NETATMO_OAUTH_URL
    authorize_url = NETATMO_AUTHORIZE_URL

    def complete_login(self, request, app, token, **kwargs):
        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        url = NETATMO_PROFILE_URL.format(token.token)
        resp = requests.get(url,
                            headers=headers)
        resp.raise_for_status()
        extra_data = resp.json()
        extra_data = extra_data['body']
        extra_data['id'] = extra_data['_id']
        extra_data['email'] = extra_data['username'] = extra_data['mail']
        extra_data['name'] = extra_data['mail'].split('@')[0]
        login = self.get_provider() \
            .sociallogin_from_response(request,
                                       extra_data)
        return login


class NetatmoCallbackView(OAuth2CallbackView):

    pass


oauth2_login = OAuth2LoginView.adapter_view(NetatmoOAuth2Adapter)
oauth2_callback = NetatmoCallbackView.adapter_view(NetatmoOAuth2Adapter)
Beispiel #6
0
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import WorldCubeAssociationProvider


class WorldCubeAssociationOAuth2Adapter(OAuth2Adapter):
    provider_id = WorldCubeAssociationProvider.id
    provider_default_url = "https://www.worldcubeassociation.org"
    provider_api_version = "v0"

    settings = app_settings.PROVIDERS.get(provider_id, {})
    provider_base_url = settings.get("BASE_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}/me".format(provider_base_url, provider_api_version)

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


oauth2_login = OAuth2LoginView.adapter_view(WorldCubeAssociationOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(WorldCubeAssociationOAuth2Adapter)
Beispiel #7
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)
Beispiel #8
0

class LoginTestingOAuth2Adapter(OAuth2Adapter):
    provider_id = LoginTestingProvider.id

    access_token_url = 'http://localhost:8000/oauth2/token/'
    authorize_url = 'http://localhost:8000/oauth2/authorize/'
    identity_url = 'http://localhost:8000/identity/'

    supports_state = True

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

    def get_data(self, token):
        resp = requests.get(
            self.identity_url,
            headers={'Authorization': 'Bearer {}'.format(token)})
        resp = resp.json()
        if not resp.get('ok'):
            raise OAuth2Error()
        info = {
            'user': resp.get('user'),
        }
        return info


oauth2_login = OAuth2LoginView.adapter_view(LoginTestingOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(LoginTestingOAuth2Adapter)
Beispiel #9
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)
Beispiel #10
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)

Beispiel #11
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)
Beispiel #12
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)
Beispiel #13
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)
Beispiel #14
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)
Beispiel #15
0
import requests

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

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)
Beispiel #16
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)
Beispiel #17
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)

Beispiel #18
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)
Beispiel #19
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)
Beispiel #20
0
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)

from .provider import CernProvider


class CernOAuth2Adapter(OAuth2Adapter):
    provider_id = CernProvider.id
    access_token_url = "https://oauth.web.cern.ch/OAuth/Token"
    authorize_url = "https://oauth.web.cern.ch/OAuth/Authorize"
    profile_url = "https://oauthresource.web.cern.ch/api/User"
    groups_url = "https://oauthresource.web.cern.ch/api/Groups"

    supports_state = False
    redirect_uri_protocol = "https"

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


oauth2_login = OAuth2LoginView.adapter_view(CernOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(CernOAuth2Adapter)
Beispiel #21
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)
Beispiel #22
0
import requests

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


class TampereOAuth2Adapter(OAuth2Adapter):
    provider_id = TampereProvider.id
    access_token_url = 'https://auth.tampere.fi/oauth2/token/'
    authorize_url = 'https://auth.tampere.fi/oauth2/authorize/'
    profile_url = 'https://auth.tampere.fi/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(TampereOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(TampereOAuth2Adapter)
Beispiel #23
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)
Beispiel #24
0
import requests

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


class FeedTheFoxGitHubOAuth2Adapter(GitHubOAuth2Adapter):
    """
    A custom GitHub OAuth adapter to be used for fetching the list
    of private email addresses stored for the given user at GitHub.

    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)


oauth2_login = OAuth2LoginView.adapter_view(FeedTheFoxGitHubOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(
    FeedTheFoxGitHubOAuth2Adapter)
Beispiel #25
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)
Beispiel #26
0
)

from .provider import MailRuProvider


class MailRuOAuth2Adapter(OAuth2Adapter):
    provider_id = MailRuProvider.id
    access_token_url = 'https://connect.mail.ru/oauth/token'
    authorize_url = 'https://connect.mail.ru/oauth/authorize'
    profile_url = 'http://www.appsmail.ru/platform/api'

    def complete_login(self, request, app, token, **kwargs):
        uid = kwargs['response']['x_mailru_vid']
        data = {
            'method': 'users.getInfo',
            'app_id': app.client_id,
            'secure': '1',
            'uids': uid
        }
        param_list = sorted(list(item + '=' + data[item] for item in data))
        data['sig'] = md5(
            (''.join(param_list) + app.secret).encode('utf-8')).hexdigest()
        response = requests.get(self.profile_url, params=data)
        extra_data = response.json()[0]
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(MailRuOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(MailRuOAuth2Adapter)
Beispiel #27
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)
Beispiel #28
0
                                                          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):
        #{u'first_name': u'James', u'last_name': u'Smith',
        # u'name': u'James Smith', u'locale': u'en_US', u'gender': None,
        # u'emails': {u'personal': None, u'account': u'*****@*****.**',
        # u'business': None, u'preferred': u'*****@*****.**'},
        # u'link': u'https://profile.live.com/',
        # u'updated_time': u'2014-02-07T00:35:27+0000',
        # u'id': u'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)
Beispiel #29
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)
Beispiel #30
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/v2/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)
Beispiel #31
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)
Beispiel #32
0
import requests

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


class LineOAuth2Adapter(OAuth2Adapter):
    provider_id = LineProvider.id
    access_token_url = 'https://api.line.me/v1/oauth/accessToken'
    authorize_url = 'https://access.line.me/dialog/oauth/weblogin'
    profile_url = 'https://api.line.me/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(LineOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(LineOAuth2Adapter)
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)
Beispiel #34
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)
Beispiel #35
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)
Beispiel #36
0
)

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
            },
        )
        resp.raise_for_status()
        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)
Beispiel #37
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)
Beispiel #38
0
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)
Beispiel #39
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)
Beispiel #40
0
import requests

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

from .provider import HBPOAuth2Provider


_URL_PREFIX = "https://services.humanbrainproject.eu/oidc/"


class HBPOAuth2Adapter(OAuth2Adapter):
    provider_id = HBPOAuth2Provider.id
    access_token_url = _URL_PREFIX + "token"
    authorize_url = _URL_PREFIX + "authorize"
    profile_url = _URL_PREFIX + "userinfo"

    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)


oauth_login = OAuth2LoginView.adapter_view(HBPOAuth2Adapter)
oauth_callback = OAuth2CallbackView.adapter_view(HBPOAuth2Adapter)
Beispiel #41
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)
Beispiel #42
0
from allauth.socialaccount.providers.oauth2.views import (
    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 = 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)
Beispiel #43
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)
Beispiel #44
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)
Beispiel #45
0
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)
import requests

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)
        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)
Beispiel #46
0
    # {"id": 12345, ...}
    if "id" not in data:
        # If the id is not present, the output is not usable (no UID)
        raise OAuth2Error("Invalid data from GitLab API: %r" % (data))

    return data


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

    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):
        response = requests.get(self.profile_url,
                                params={"access_token": token.token})
        data = _check_errors(response)
        return self.get_provider().sociallogin_from_response(request, data)


oauth2_login = OAuth2LoginView.adapter_view(GitLabOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(GitLabOAuth2Adapter)
Beispiel #47
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)
Beispiel #48
0
class KeycloakOAuth2Adapter(OAuth2Adapter):
    provider_id = KeycloakProvider.id
    supports_state = True

    settings = app_settings.PROVIDERS.get(provider_id, {})
    provider_base_url = "{0}/realms/{1}".format(settings.get("KEYCLOAK_URL"),
                                                settings.get("KEYCLOAK_REALM"))

    access_token_url = "{0}/protocol/openid-connect/token".format(
        provider_base_url)
    authorize_url = "{0}/protocol/openid-connect/auth".format(
        provider_base_url)
    profile_url = "{0}/protocol/openid-connect/userinfo".format(
        provider_base_url)

    def complete_login(self, request, app, token, response):
        response = requests.post(
            self.profile_url,
            headers={"Authorization": "Bearer " + str(token)})
        response.raise_for_status()
        extra_data = response.json()
        extra_data["id"] = extra_data["sub"]
        del extra_data["sub"]

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


oauth2_login = OAuth2LoginView.adapter_view(KeycloakOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(KeycloakOAuth2Adapter)
Beispiel #49
0
    '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]
        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)
Beispiel #50
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)
Beispiel #51
0
import requests

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

from .provider import StravaProvider


class StravaOauth2Adapter(OAuth2Adapter):
    provider_id = StravaProvider.id
    access_token_url = "https://www.strava.com/oauth/token"
    authorize_url = "https://www.strava.com/oauth/authorize"
    profile_url = "https://www.strava.com/api/v3/athlete"

    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(StravaOauth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(StravaOauth2Adapter)
Beispiel #52
0
import requests

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

from .provider import StripeExpressProvider


class StripeExpressOAuth2Adapter(OAuth2Adapter):
    provider_id = StripeExpressProvider.id
    access_token_url = 'https://connect.stripe.com/oauth/token'
    authorize_url = 'https://connect.stripe.com/express/oauth/authorize'
    profile_url = 'https://api.stripe.com/v1/accounts/%s'

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


oauth2_login = OAuth2LoginView.adapter_view(StripeExpressOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(StripeExpressOAuth2Adapter)
Beispiel #53
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)
Beispiel #54
0
        jira_user_scope = 'read:jira-user'
        print("sites******", sites)

        for site in sites:
            if jira_user_scope in site['scopes']:
                site_id = site['id']
                print("site_id", site_id)

        cloud_id = site_id
        base_url = "https://api.atlassian.com/ex/jira/" + cloud_id
        myself_url = base_url + "/rest/api/3/myself"

        myself_resp = requests.get(myself_url, headers=header)

        extra_data = myself_resp.json()
        print("extra_data", extra_data, type(extra_data))
        extra_data['sites'] = sites
        print("extra_data", extra_data)
        print("extra_data site id", extra_data['sites'])

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


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

# oauth_login = OAuthLoginView.adapter_view(AtlassianOAuthAdapter)
# oauth_callback = OAuthCallbackView.adapter_view(AtlassianOAuthAdapter)
Beispiel #55
0
import requests
from allauth.socialaccount import app_settings
from allauth.socialaccount.providers.oauth2.views import (OAuth2Adapter,
                                                          OAuth2LoginView,
                                                          OAuth2CallbackView)
from .provider import OwncloudProvider


class OwncloudOAuth2Adapter(OAuth2Adapter):
    provider_id = OwncloudProvider.id
    settings = app_settings.PROVIDERS.get(provider_id, {})
    server = settings.get('SERVER', 'https://owncloud.example.org')
    access_token_url = '{0}/index.php/apps/oauth2/api/v1/token'.format(server)
    authorize_url = '{0}/index.php/apps/oauth2/authorize'.format(server)
    basic_auth = True

    def complete_login(self, request, app, token, **kwargs):
        extra_data = {'user_id': kwargs['response']['user_id']}
        return self.get_provider().sociallogin_from_response(
            request, extra_data)


oauth2_login = OAuth2LoginView.adapter_view(OwncloudOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(OwncloudOAuth2Adapter)
Beispiel #56
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)
Beispiel #57
0
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)
import requests

from .provider import DaumProvider


class DaumOAuth2Adapter(OAuth2Adapter):
    provider_id = DaumProvider.id
    access_token_url = 'https://apis.daum.net/oauth2/token'
    authorize_url = 'https://apis.daum.net/oauth2/authorize'
    profile_url = 'https://apis.daum.net/user/v1/show.json'

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


oauth2_login = OAuth2LoginView.adapter_view(DaumOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(DaumOAuth2Adapter)
Beispiel #58
0
from allauth.socialaccount.providers.oauth2.views import (
    OAuth2Adapter,
    OAuth2CallbackView,
    OAuth2LoginView,
)
import requests

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


oauth2_login = OAuth2LoginView.adapter_view(SoundCloudOAuth2Adapter)
oauth2_callback = OAuth2CallbackView.adapter_view(SoundCloudOAuth2Adapter)
Beispiel #59
0
        .sociallogin_from_response(request, extra_data)
    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:
                provider = providers.registry.by_id(FacebookProvider.id)
                app = providers.registry.by_id(FacebookProvider.id) \
                    .get_app(request)
                access_token = form.cleaned_data['access_token']
                info = requests.get(
                    'https://graph.facebook.com/oauth/access_token_info',