Beispiel #1
0
 def __init__(self,
              name="",
              client_id=None,
              client_secret=None,
              emulator=False,
              debug=True,
              template_folder='templates'):
     self.name = name
     self.emulator = emulator
     self.debug = debug
     self.web = flask.Flask(self.name,
                            static_folder=os.path.join(
                                os.path.dirname(os.path.abspath(__file__)),
                                'emulator'),
                            static_url_path='/emulator')
     self.template_folder = template_folder
     self.logger = self.web.logger
     self.emulator_service = Emulator(app=self)
     self.subscriptions = Subscriptions(app=self)
     self.oauth = rauth.OAuth2Service(
         name=self.name,
         client_id=client_id,
         client_secret=client_secret,
         access_token_url=self.OAUTH_ACCESS_TOKEN_URL,
         authorize_url=self.OAUTH_AUTHORIZE_URL,
         base_url=self.OAUTH_API_BASE_URL)
Beispiel #2
0
 def oauth(self):
     return rauth.OAuth2Service(
         client_id=self.CLIENT_ID,
         client_secret=self.CLIENT_SECRET,
         name='github',
         access_token_url='https://github.com/login/oauth/access_token',
         authorize_url='https://github.com/login/oauth/authorize',
     )
Beispiel #3
0
def get_oauth_service():
    client_id, client_secret = json.loads(
        base64.b64decode(constants.CLIENT_DATA))
    return rauth.OAuth2Service(client_id=client_id,
                               client_secret=client_secret,
                               access_token_url=constants.ENDPOINT_ACCESS,
                               authorize_url=constants.ENDPOINT_AUTHORIZE,
                               base_url=constants.ENDPOINT_BASE)
Beispiel #4
0
 def __init__(self, credentials):
     super().__init__('purecloud', credentials)
     self._service = rauth.OAuth2Service(
         name=self.name,
         client_id=self.client_id,
         client_secret=self.client_secret,
         authorize_url=self.AUTHORIZE_URL,
         access_token_url=self.ACCESS_TOKEN_URL,
         base_url=self.BASE_URL
     )
Beispiel #5
0
def get_oauth2_token(email='', password=''):
    """Get the OAuth2 token by simulating a browser session."""
    # get the authorization URL
    oura = rauth.OAuth2Service(client_id=OURA_CLIENT_ID,
                               client_secret=OURA_CLIENT_SECRET,
                               name='oura',
                               authorize_url=OURA_AUTHORIZE_URL,
                               access_token_url=OURA_ACCESS_TOKEN_URL,
                               base_url=OURA_BASE_URL)

    url = oura.get_authorize_url(scope='email personal daily',
                                 response_type='code',
                                 redirect_uri=REDIRECT_URI)

    # simulate a browser session to automate email + password entry
    br = mechanize.Browser()
    br.set_handle_equiv(False)
    br.set_handle_gzip(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)

    br.open(url)
    br.select_form(nr=0)

    # fill in email and password to first form
    br.form['email'] = email
    br.form['password'] = password
    br.submit()

    # set full permissions on second form and retrieve the authorization code
    br.select_form(nr=0)
    br.find_control(name="scope_personal").items[0].selected = True
    br.find_control(name="scope_daily").items[0].selected = True
    br.submit(name="allow")
    url = br.geturl()
    code = url[url.index('?code=') + 6:]

    # retrieve the access token
    data = {
        'grant_type': 'authorization_code',
        'code': code,
        'redirect_uri': REDIRECT_URI
    }
    auth = requests.auth.HTTPBasicAuth(OURA_CLIENT_ID, OURA_CLIENT_SECRET)
    resp = requests.post(OURA_ACCESS_TOKEN_URL, data=data, auth=auth).json()

    return resp['access_token']
    def __init__(self, remote):
        self.remote = remote

        self.service = rauth.OAuth2Service(
            name="git-annex-remote",
            client_id=self.oauth_client_id,
            client_secret=self.oauth_client_secret,
            access_token_url=self.access_token_url,
            authorize_url=self.authorize_url,
            base_url=self.base_url)

        self.refresh_token = self.access_token = None
        self.access_token_expiration = DATETIME_MIN

        self.swift_token = self.swift_endpoint = None
        self.swift_token_expiration = DATETIME_MIN
Beispiel #7
0
 def __init__(self, 
             name="",
             client_id=None,
             client_secret=None,
             scopes=OAUTH_SCOPES,
             debug=False,
             template_folder='templates',
             **flaskargs):
     self.name = name
     self.debug = debug
     self.web = flask.Flask(self.name, **flaskargs)
     self.template_folder = template_folder
     self.logger = self.web.logger
     self.scopes = scopes
     self.subscriptions = Subscriptions(app=self)
     self.oauth = rauth.OAuth2Service(name=self.name,
                               client_id=client_id,
                               client_secret=client_secret,
                               access_token_url=OAUTH_ACCESS_TOKEN_URL,
                               authorize_url=OAUTH_AUTHORIZE_URL,
                               base_url=OAUTH_API_BASE_URL)
def query_setup():
	project_path = 'C:/Users/Joe/Projects/fantasy_football/'

	#read in the api keys
	with open(project_path+'yahoo_api_key.json') as api:
		file = json.load(api)
		key = file['consumer_key']
		secret = file['consumer_secret']

	#create OAuth2 object
	oauth = rauth.OAuth2Service(client_id=key,
								client_secret=secret,
								name='yahoo',
								access_token_url='https://api.login.yahoo.com/oauth2/get_token',
								authorize_url='https://api.login.yahoo.com/oauth2/request_auth',
								base_url='https://fantasysports.yahooapis.com/')

	access_token = create_access_token(oauth)
	s = oauth.get_session(token=access_token)
	#return session
	return s, oauth.base_url
 def backgroundTask():
     service = rauth.OAuth2Service(
         client_id=self.clientId,
         client_secret=self.clientSecret,
         access_token_url='https://api.netatmo.net/oauth2/token')
     if time.time() > self.tokenTTL:
         session = self.__requestSession(service)
     else:
         session = rauth.OAuth2Session(self.clientId,
                                       self.clientSecret,
                                       access_token=self.accessToken,
                                       service=service)
     response = session.get(
         'https://api.netatmo.com/api/getstationsdata')
     data = response.json()
     if 'error' in data and data['error']['code'] in [2, 3]:
         # Token is expired. Request new
         session = self.__requestSession(service)
         response = session.get(
             'https://api.netatmo.com/api/getstationsdata')
         data = response.json()
     self.__parseValues(data)
 def handleRequest(self, plugin, path, params, request, **kwargs):
     # Web requests
     if path in ['activate', 'code']:
         service = rauth.OAuth2Service(
             client_id=self.clientId,
             client_secret=self.clientSecret,
             access_token_url='https://api.netatmo.net/oauth2/token',
             authorize_url='https://api.netatmo.net/oauth2/authorize')
         if path == 'activate':
             params = {
                 'redirect_uri': '%s/netatmo/code' % request.base(),
                 'response_type': 'code'
             }
             url = service.get_authorize_url(**params)
             return WebResponseJson({'url': url})
         if path == 'code':
             data = {
                 'code': params['code'],
                 'grant_type': 'authorization_code',
                 'redirect_uri': '%s/netatmo/code' % request.base()
             }
             session = service.get_auth_session(
                 data=data, decoder=self.__decodeAccessToken)
             return WebResponseRedirect('%s/plugins?settings=netatmo' %
                                        request.base())
     if path == 'logout':
         self.accessToken = ''
         self.refreshToken = ''
         self.tokenTTL = 0
         self.setConfig(
             'oauth', {
                 'accessToken': self.accessToken,
                 'refreshToken': self.refreshToken,
                 'tokenTTL': self.tokenTTL,
             })
         self.configuration['oauth'].activated = False
         return WebResponseJson({'success': True})
     return None
 def __service(self):
     return rauth.OAuth2Service(client_id=self.clientId,
                                client_secret=self.clientSecret,
                                access_token_url=self.accessTokenUrl,
                                authorize_url=self.authorizeUrl,
                                base_url=self.baseUrl)
Beispiel #12
0
QUERY = ''
TITLES = None
LYRICS = None
SONGS = None
P_COUNT = None
PD = None
SELECTED = None
PHONEMES = None
COMPARE = []

# Genius Authentication Flow

genius = rauth.OAuth2Service(
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    base_url=BASE_URL,
    authorize_url=BASE_URL + '/oauth/authorize',
    access_token_url=BASE_URL + '/oauth/token',
)


@app.route('/')
def renderInit():
    # Session should only exist if the user has authenticated with Genius
    if (session):
        auth, acc, name = True, session['avatar_url'], session['name']
    else:
        auth, acc, name = False, '', ''
    if not SELECTED == None:
        return render_template("results.html",
                               auth=auth,
Beispiel #13
0
    def authorize(self):
        if self.cookies == None:
            return 0
        oauth = rauth.OAuth2Service(self.key,
                                    self.secret,
                                    authorize_url=auth_url,
                                    access_token_url=access_url,
                                    base_url=base_url)
        self.state = sha1(str(random())).hexdigest()

        params = {
            'scope': 'identity,read',
            'response_type': 'code',
            'redirect_uri': self.redirect_uri,
            'state': self.state,
            'duration': 'permanent'
        }
        headers = {'User-Agent': user_agent}

        authorize_url = oauth.get_authorize_url(**params)
        r = requests.get(authorize_url, headers=headers, cookies=self.cookies)
        if r.status_code != 200:
            self.clearState()
            return r.status_code

        data = {
            'uh':
            re.search('name="uh" value="([^"]*)',
                      r.text).group(1).encode('ascii'),
            'client_id':
            re.search('name="client_id" value="([^"]*)',
                      r.text).group(1).encode('ascii'),
            'redirect_uri':
            re.search('name="redirect_uri" value="([^"]*)',
                      r.text).group(1).encode('ascii'),
            'scope':
            re.search('name="scope" value="([^"]*)',
                      r.text).group(1).encode('ascii'),
            'state':
            re.search('name="state" value="([^"]*)',
                      r.text).group(1).encode('ascii'),
            'duration':
            re.search('name="duration" value="([^"]*)',
                      r.text).group(1).encode('ascii'),
            'authorize':
            'Allow'
        }

        r = requests.post('https://ssl.reddit.com/api/v1/authorize',
                          data=data,
                          headers=headers,
                          cookies=self.cookies,
                          verify=False)
        if r.status_code != 200:
            self.clearState()
            return r.status_code

        url_split1 = r.url.split('?')
        domain = url_split1[0]
        url_split2 = url_split1[1].split('&')
        params = dict()
        for entry in url_split2:
            url_split3 = entry.split('=')
            params[url_split3[0].encode('ascii')] = url_split3[1].encode(
                'ascii')
        if domain != self.redirect_uri or params['state'] != self.state:
            self.clearState()
            return 0
        self.code = params['code']
        self.service = oauth
        return r.status_code