def get_nationbuilder_connection():
    access_token_url = "http://%s.nationbuilder.com/oauth/token" % sls.NATIONBUILDER_SLUG
    authorize_url = "%s.nationbuilder.com/oauth/authorize" % sls.NATIONBUILDER_SLUG
    service = OAuth2Service(client_id=sls.NATIONBUILDER_CLIENT_ID,
                            client_secret=sls.NATIONBUILDER_CLIENT_SECRET,
                            name="NationBuilder",
                            authorize_url=authorize_url,
                            access_token_url=access_token_url,
                            base_url=base_url)
    token = sls.NATIONBUILDER_TOKEN
    session = service.get_session(token)
    return session
Esempio n. 2
0
 def __init__(self):
     super(GoogleSignIn, self).__init__('google')
     googleinfo = urllib2.urlopen('https://accounts.google.com/.well-known/openid-configuration')
     google_params = json.load(googleinfo)
     self.service = OAuth2Service(
             name='google',
             client_id=self.consumer_id,
             client_secret=self.consumer_secret,
             authorize_url=google_params.get('authorization_endpoint'),
             base_url=google_params.get('userinfo_endpoint'),
             access_token_url=google_params.get('token_endpoint')
     )
Esempio n. 3
0
def handle_musicbrainz_oauth2_login():
    musicbrainz = OAuth2Service(
        name='musicbrainz',
        client_id=current_app.config['MB_OAUTH_CLIENT_ID'],
        client_secret=current_app.config['MB_OAUTH_CLIENT_SECRET'],
        base_url='https://musicbrainz.org',
        authorize_url='https://musicbrainz.org/oauth2/authorize',
        access_token_url='https://musicbrainz.org/oauth2/token',
    )

    serializer = URLSafeSerializer(current_app.config['SECRET_KEY'])

    code = request.args.get('code')
    if not code:
        token = str(random.getrandbits(64))
        session['mb_login_token'] = token
        url = musicbrainz.get_authorize_url(**{
            'response_type': 'code',
            'scope': 'profile',
            'redirect_uri': url_for('.musicbrainz_login', _external=True),
            'state': serializer.dumps({
                'return_url': request.values.get('return_url'),
                'token': token,
            }),
        })
        return redirect(url)

    serialized_state = request.args.get('state')
    if serialized_state:
        state = serializer.loads(serialized_state)
    else:
        state = {}

    token = session.get('mb_login_token')
    if not token:
        raise Exception('token not found in session')

    if token != state.get('token'):
        raise Exception('token from session does not match token from oauth2 state')

    auth_session = musicbrainz.get_auth_session(data={
        'grant_type': 'authorization_code',
        'code': code,
        'redirect_uri': url_for('.musicbrainz_login', _external=True),
    }, decoder=json.loads)

    response = auth_session.get('oauth2/userinfo').json()

    user = find_or_create_musicbrainz_user(response['sub'])
    logger.info('MusicBrainz user %s "%s" logged in', user.id, user.name)

    return login_user_and_redirect(user.id, return_url=state.get('return_url'))
Esempio n. 4
0
def get_oauth2_flow(provider):
    from rauth import OAuth2Service

    # get client_id and client_secret
    params = get_oauth_keys(provider)

    oauth2_providers = get_oauth2_providers()

    # additional params for getting the flow
    params.update(oauth2_providers[provider]["flow_params"])

    # and we have setup the communication lines
    return OAuth2Service(**params)
Esempio n. 5
0
    def __init__(self, email, password):
        self.access_token = None

        self.service = OAuth2Service(
            client_id='81527cff06843c8634fdc09e8ac0abefb46ac849f38fe1e431c2ef2106796384',
            client_secret='c7257eb71a564034f9419ee651c7d0e5f7aa6bfbd18bafb5c5c033b093bb2fa3',
            access_token_url="https://owner-api.teslamotors.com/oauth/token",
            authorize_url="https://owner-api.teslamotors.com/oauth/token",
            base_url="https://owner-api.teslamotors.com/",
        )

        self.get_access_token(email,password)
        self.start_session()
Esempio n. 6
0
    def __init__(self):
        super(ORCIDSignIn, self).__init__('orcid')

        auth_url = os.environ.get('ORCID_AUTH_URL')
        base_url = os.environ.get('ORCID_BASE_URL')
        token_url = os.environ.get('ORCID_TOKEN_URL')

        self.service = OAuth2Service(name='orcid',
                                     client_id=self.consumer_id,
                                     client_secret=self.consumer_secret,
                                     authorize_url=auth_url,
                                     base_url=base_url,
                                     access_token_url=token_url)
Esempio n. 7
0
 def __init__(self):
     super(GoogleSignIn, self).__init__('google')
     response = urllib3.PoolManager().request(
         'GET',
         'https://accounts.google.com/.well-known/openid-configuration')
     google_params = json.loads(response.data.decode('utf-8'))
     self.service = OAuth2Service(
         name='google',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url=google_params.get('authorization_endpoint'),
         base_url=google_params.get('userinfo_endpoint'),
         access_token_url=google_params.get('token_endpoint'))
Esempio n. 8
0
    def __init__(self,
                 client_id,
                 client_secret,
                 token_url,
                 scope_url,
                 name='test'):
        self.access_token = None
        self.scope_url = scope_url

        self.service = OAuth2Service(name=name,
                                     client_id=client_id,
                                     client_secret=client_secret,
                                     access_token_url=token_url)
Esempio n. 9
0
 def __init__(self):
     credentials = OAUTH_CREDENTIALS['vk']
     self.consumer_id = credentials['id']
     self.consumer_secret = credentials['secret']
     self.scope = credentials['scope']
     self.service = OAuth2Service(
         name='vk',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url='https://oauth.vk.com/authorize',           
         access_token_url='https://oauth.vk.com/access_token',
         base_url='https://oauth.vk.com/'
     )
Esempio n. 10
0
    def __init__(self):

        super(CASignIn, self).__init__('CA')
        self.next_page = None
        cainfo = urllib2.urlopen(self.discovery_endpoint)
        ca_params = json.load(cainfo)
        self.service = OAuth2Service(
            name='CA',
            client_id=self.consumer_id,
            client_secret=self.consumer_secret,
            authorize_url=ca_params.get('authorization_endpoint'),
            base_url=ca_params.get('userinfo_endpoint'),
            access_token_url=ca_params.get('token_endpoint'))
Esempio n. 11
0
    def __init__(self):
        self.consumer_id = current_app.config['MS_CLIENT_ID']
        self.consumer_secret = current_app.config['MS_CLIENT_SECRET']

        self.service = OAuth2Service(
            name='microsoft',
            client_id=current_app.config['MS_CLIENT_ID'],
            client_secret=current_app.config['MS_CLIENT_SECRET'],
            authorize_url=
            'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
            access_token_url=
            'https://login.microsoftonline.com/common/oauth2/v2.0/token',
            base_url='https://graph.microsoft.com/v1.0/')
Esempio n. 12
0
    def __init__(self, client_id, client_secret):
        self.access_token = None

        self.service = OAuth2Service(
            name="Patcher",
            client_id=client_id,
            client_secret=client_secret,
            access_token_url="https://oauth2.googleapis.com/token",
            authorize_url="https://accounts.google.com/o/oauth2/v2/auth",
            base_url="https://www.googleapis.com",
        )

        self.get_access_token()
Esempio n. 13
0
 def __init__(self):
     self.provider_name = 'facebook'
     credentials = current_app.config['OAUTH_CREDENTIALS'][self.provider_name]
     self.consumer_id = credentials['id']
     self.consumer_secret = credentials['secret']
     self.service = OAuth2Service(
         name='facebook',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url='https://graph.facebook.com/oauth/authorize',
         access_token_url='https://graph.facebook.com/oauth/access_token',
         base_url='https://graph.facebook.com/'
     )
Esempio n. 14
0
    def __init__(self):
        super().__init__()

        base_url = current_app.config['OAUTH_CREDENTIALS']['blender-id'].get(
            'base_url', 'https://www.blender.org/id/')

        self.service = OAuth2Service(
            name='blender-id',
            client_id=self.consumer_id,
            client_secret=self.consumer_secret,
            authorize_url='%soauth/authorize' % base_url,
            access_token_url='%soauth/token' % base_url,
            base_url='%sapi/' % base_url)
Esempio n. 15
0
def agave_oauth(request):
    # check for token
    token = OAuthToken().cyverse_get_token(request.user.id)
    if token:
        # get token and pass
        OAuthToken().check_token(token)
        url = request.path
        return load_cyverse_files(request, url, token)
    else:

        service = OAuth2Service(
            name='copo_api',
            client_id='KOm9gFBPVwq6sfCMgumZRJG5j8wa',
            client_secret='gAnX96MinyBfZ_gsvkr0nEDLpR8a',
            access_token_url='https://agave.iplantc.org/oauth2/token',
            authorize_url='https://agave.iplantc.org/oauth2/authorize',
            base_url='https://agave.iplantc.org/oauth2/')

        # the return URL is used to validate the request
        params = {'redirect_uri': 'http://127.0.0.1:8000/copo/agave_oauth',
                  'response_type': 'code'}
        if not 'code' in request.GET:
            # save url for initial page

            url = service.get_authorize_url(**params)
            return redirect(url)
        else:

            # once the above URL is consumed by a client we can ask for an access
            # token. note that the code is retrieved from the redirect URL above,
            # as set by the provider
            code = request.GET['code']

            params = {
                "grant_type": "authorization_code",
                "code": code,
                "client_id": "KOm9gFBPVwq6sfCMgumZRJG5j8wa",
                "client_secret": "gAnX96MinyBfZ_gsvkr0nEDLpR8a",
                "redirect_uri": "http://127.0.0.1:8000/copo/agave_oauth"
            }

            r = requests.post("https://agave.iplantc.org/oauth2/token", data=params)

            if r.status_code == 401:
                # refresh token
                pass
            else:
                # save token
                t = json.loads(r.content.decode('utf-8'))
                OAuthToken().cyverse_save_token(request.user.id, t)
                return redirect(request.session['datafile_url'])
Esempio n. 16
0
    def __init__(self):
        super(GitlabSignIn, self).__init__('gitlab')

        self.service = OAuth2Service(
            name='gitlab',
            client_id=self.consumer_id,
            client_secret=self.consumer_secret,
            authorize_url='http://sdrshgitlabv.camhres.ca/oauth/authorize',
            #authorize_url='https://github.com/login/oauth/authorize',
            base_url='http://sdrshgitlabv.camhres.ca',
            #base_url='https://github.com/login/',
            access_token_url='http://sdrshgitlabv.camhres.ca/oauth/token'
            #access_token_url='https://github.com/login/oauth/access_token'
        )
Esempio n. 17
0
 def __init__(self):
     super(GoogleSignIn, self).__init__("google")
     googleinfo = requests.get(
         "https://accounts.google.com/.well-known/openid-configuration")
     googleinfo.raise_for_status()
     google_params = googleinfo.json()
     self.service = OAuth2Service(
         name="google",
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url=google_params.get("authorization_endpoint"),
         base_url=google_params.get("userinfo_endpoint"),
         access_token_url=google_params.get("token_endpoint"),
     )
Esempio n. 18
0
def getsession():
    print("Getting new Session for " + args.base_url)
    return OAuth2Service(
        client_id=args.client_id,
        client_secret=args.client_secret,
        access_token_url=args.sso,
        base_url=args.base_url
    ).get_auth_session(
        data =  {
            'scope':'openid',
            'grant_type':'client_credentials'
        },
        decoder = json.loads
    )
Esempio n. 19
0
    def __init__(self,
                 client_id,
                 client_secret,
                 base_url=None,
                 access_token=None):
        self.oauth_service = OAuth2Service(name='yahoo',
                                           base_url=base_url,
                                           client_id=client_id,
                                           client_secret=client_secret,
                                           authorize_url=self.request_auth_url,
                                           access_token_url=self.get_token_url)

        if access_token:
            self.oauth_session = self.oauth_service.get_session(access_token)
Esempio n. 20
0
 def __init__(self):
     super(GoogleSignIn, self).__init__('google')
     # Gets the Google open-id configuration and loads it in a dictionary
     googleinfo = requests.get(
         'https://accounts.google.com/.well-known/openid-configuration')
     google_params = googleinfo.json()
     # Instanciates the OAuth2Service using the previously loaded Google parameters
     self.service = OAuth2Service(
         name='google',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url=google_params['authorization_endpoint'],
         base_url=google_params['userinfo_endpoint'],
         access_token_url=google_params['token_endpoint'])
Esempio n. 21
0
 def __init__(self):
     super(GoogleSignIn, self).__init__('google')
     url = 'https://accounts.google.com/.well-known/openid-configuration'
     response = http.request('GET', url)
     googleinfo = response.data
     google_params = json.loads(googleinfo)
     self.service = OAuth2Service(
         name='google',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url='https://accounts.google.com/o/oauth2/v2/auth',
         access_token_url=
         'https://accounts.google.com/o/oauth2/v2/tokeninfo',
         base_url='https://accounts.google.com/')
Esempio n. 22
0
    def __init__(self):
        from urllib.parse import urljoin
        super().__init__()

        base_url = current_app.config['BLENDER_ID_ENDPOINT']

        self.service = OAuth2Service(
            name='blender-id',
            client_id=self.consumer_id,
            client_secret=self.consumer_secret,
            authorize_url=urljoin(base_url, 'oauth/authorize'),
            access_token_url=urljoin(base_url, 'oauth/token'),
            base_url=urljoin(base_url, 'api/'),
        )
Esempio n. 23
0
 def __init__(self):
     super(GoogleSignIn, self).__init__('google')
     #googleinfo = urllib2.urlopen('https://accounts.google.com/.well-known/openid-configuration')
     #google_params = json.load(googleinfo)
     #self.openid_config = json.load(urlopen(self.openid_url))
     self.service = OAuth2Service(
         name='google',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url='https://accounts.google.com/o/oauth2/auth',
         access_token_url='https://accounts.google.com/o/oauth2/token',
         base_url='https://www.googleapis.com/oauth2/v1/'
         #userinfo_endpoint='https://openidconnect.googleapis.com/v1/userinfo'
     )
 def __init__(self,
              client_id,
              secret_key,
              redirect_uri=None,
              base_uri='https://api.banregio.com'):
     self.redirect_uri = redirect_uri
     self.base_uri = base_uri
     self.refresh_token = None
     self.api = OAuth2Service(
         client_id=client_id,
         client_secret=secret_key,
         name='apibanregio',
         authorize_url='{0}/oauth/authorize'.format(self.base_uri),
         access_token_url='{0}/oauth/token'.format(self.base_uri),
         base_url=self.base_uri)
Esempio n. 25
0
    def __init__(self, client_id, client_secret, base_url, access_token_url,
                 authorize_url):
        """Create a secure session to interact with an API."""
        self._service = OAuth2Service(name="",
                                      client_id=client_id,
                                      client_secret=client_secret,
                                      base_url=base_url,
                                      access_token_url=access_token_url,
                                      authorize_url=authorize_url)

        with concurrent.futures.ThreadPoolExecutor() as executor:
            future_token = executor.submit(self._get_code)
            future_authenticate = executor.submit(self._authenticate)
            token = future_token.result()
            self.session = self._get_session(token)
Esempio n. 26
0
    def _get_oauth_service(self):
        """
        get oauth service to be used to get access token

        returns oauthService
        """

        access_token_url = urljoin(self.base_url, "oauth/token")
        oauth_service = OAuth2Service(client_id=self.client_id,
                                      client_secret=self.client_secret,
                                      name="irida",
                                      access_token_url=access_token_url,
                                      base_url=self.base_url)

        return oauth_service
Esempio n. 27
0
    def _get_access_code(self, token=''):
        logging.debug('get_access_code')

        # self._service = OAuth2Service(
        #     name='thingiverse',
        #     client_id='719ce807b9ceac053033',
        #     client_secret='45d1bb0958c45b7716e671ebe5723ace',
        #     access_token_url='https://www.thingiverse.com/login/oauth/access_token',
        #     authorize_url='https://www.thingiverse.com/login/oauth/authorize',
        #     base_url='https://api.thingiverse.com')

        # perplexedphoenix
        self._service = OAuth2Service(
            name='thingiverse',
            client_id=self._appinfo['client_id'],
            client_secret=self._appinfo['client_secret'],
            access_token_url=
            'https://www.thingiverse.com/login/oauth/access_token',
            authorize_url='https://www.thingiverse.com/login/oauth/authorize',
            base_url='https://api.thingiverse.com')

        if not token:
            # let's get the url to go to
            params = {
                'redirect_uri': self._appinfo['redirect_uri'],
                'response_type': 'code'
            }
            url = self._service.get_authorize_url(**params)

            # nope
            # req = urllib2.Request(url)
            # fd = urllib2.urlopen(req)
            # data = fd.readlines()
            # fd.close()
            # print data

            logging.info(url)

            if self.txt_url_mode == False:
                webbrowser.open_new(url)

            else:
                f = open('url.txt', 'w')
                f.write(url)
                f.close()
                sleep(30.0)

            self._fetch_access_code()
Esempio n. 28
0
def get_portal_oauth():

    portal_base = current_app.config.get('FLOW_PORTAL_SITE')
    client_id = current_app.config.get('FLOW_PORTAL_SSO_CLIENT_ID')
    client_secret = current_app.config.get('FLOW_PORTAL_SSO_CLIENT_SECRET')
    authorize_url = '%s/auth/concord_id/authorize' % (portal_base)
    access_token_url = '%s/auth/concord_id/access_token' % (portal_base)

    portal_oauth = OAuth2Service(name='portal',
                                 client_id=client_id,
                                 client_secret=client_secret,
                                 authorize_url=authorize_url,
                                 access_token_url=access_token_url,
                                 base_url=portal_base)

    return portal_oauth
Esempio n. 29
0
 def __init__(self):
     """ Constructor method. Polls directly from google openid
     config for up-to-date info
     """
     super(GoogleSignIn, self).__init__('google')
     googleinfo = urlopen(
         'https://accounts.google.com/.well-known/openid-configuration')
     reader = codecs.getreader("utf-8")  # decodes the JSON
     google_params = json.load(reader(googleinfo))
     self.service = OAuth2Service(
         name='google',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url=google_params.get('authorization_endpoint'),
         base_url=google_params.get('userinfo_endpoint'),
         access_token_url=google_params.get('token_endpoint'))
Esempio n. 30
0
    def __init__(self):
        self.client_id = "01edd9199cd143e28d9f1dbc3e77dcff"
        self.secret = "k3kE3WGarYtQlkC14uRCfAIVRon0kyYx"
        self.redirect_uri = "http://127.0.0.1:8000"

        self.url = "https://us.api.blizzard.com/hearthstone/cards"
        self.token_url = "https://us.battle.net/oauth/token"
        self.auth_url = "https://us.battle.net/oauth/authorize"

        self.oauth_service = OAuth2Service(
            name="bnet",
            client_id=self.client_id,
            client_secret=self.secret,
            access_token_url=self.token_url,
            authorize_url=self.auth_url,
            base_url="https://us.api.blizzard.com/")