def login_success(): token = request.forms.get('token') session = rauth.OAuth2Session(config.GOOGLE_CLIENT_ID, config.GOOGLE_CLIENT_SECRET, token) json = session.get('https://www.googleapis.com/oauth2/v1/userinfo').json() if json is None: return def convert(inputt): if isinstance(inputt, dict): return {convert(key): convert(value) for key, value in inputt.iteritems()} elif isinstance(inputt, list): return [convert(element) for element in inputt] elif isinstance(inputt, unicode): return inputt.encode('utf-8') else: return input json = convert(json) name = json['name'].replace(" ", "_") user = User(name, json['picture'], "NASA", "For the Benefit of All") gameToken = user.name gameToken = gameToken.replace(" ", "_") USERS.addUser(user, gameToken) response.set_cookie("cosmosium_login", gameToken, max_age=60 * 60 * 5) loginTokens.append({'name': user.name, 'social_token': token, 'game_token': gameToken}) # now that we're logged in, send the user where they were trying to go, else to main page target = request.query.target or '/play' redirect(target)
def yelp_api( business_id ): #authentication header token = "w1LVuxMpFEu_41ys90r_45OvSkqnMKC51wMmmbcLS_UcqW8oSUZPEmHtibZL1sMw7s-j_xsS3njP41Yx8B0hGJr7eNAqQu1jQG41uo1izM67QfdfdIkIGV8B56H-V3Yx" session = rauth.OAuth2Session(access_token = token) business_id = str(business_id) request = session.get("https://api.yelp.com/v3/businesses/" + business_id, verify = False) data = request.json() session.close() return data;
def GitHub(user_model=None, access_token=None): """ return a UniversalClient client for GitHub, authenticated with the given access_token. If access_token is not passed, will look for the access_token associated with the user_model. """ if not access_token: try: access_token = user_model.social_auth.get(provider='github').tokens except: return None session = rauth.OAuth2Session(gh_client_key, gh_client_secret, access_token) return Client(gh_host, oauth=session, dataFilter=jsonFilter)
def GitHubEnterprise(user_model=None, access_token=None): """ return a UniversalClient client for GitHub Enterprise, authenticated with the given access_token. If access_token is not passed, will look for the access_token associated with the user_model. """ if not access_token: if not user_model.is_authenticated(): return None access_token = user_model.social_auth.get( provider='github-enterprise').tokens session = rauth.OAuth2Session(ghe_client_key, ghe_client_secret, access_token) return Client(ghe_host + '/api/v3', oauth=session, dataFilter=jsonFilter)
def __init__(self, client_id, client_secret, top_k, delay, search_term, **kwargs): """ Initialize the object. Set id and secret to obtain JWT Token. Create session with the token. Set other parameters and top_k for future api call. :param client_id: client_id :param client_secret: client_secret :param top_k: top-k constraint :param delay: time interval between a failed api call and the next api call :param search_term: the field for query string :param kwargs: other parameters """ deeperlib.api.simapi.SimpleApi.__init__(self) self.setTopk(top_k) self.setDelay(delay) self.setSearchTerm(search_term) self.setKwargs(kwargs) self.setURL('https://api.yelp.com/v3/businesses/search') self.setID(client_id, client_secret) self.setToken() self.setSession(session=rauth.OAuth2Session(access_token=self.__token["access_token"]))
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 login_success(): token = request.forms.get('token') session = rauth.OAuth2Session(config.GOOGLE_CLIENT_ID, config.GOOGLE_CLIENT_SECRET, token) json = session.get('https://www.googleapis.com/oauth2/v1/userinfo').json() if json is None: return def convert(input): if isinstance(input, dict): return {convert(key): convert(value) for key, value in input.iteritems()} elif isinstance(input, list): return [convert(element) for element in input] elif isinstance(input, unicode): return input.encode('utf-8') else: return input json = convert(json) user = createUser(json['name'], json['picture'], "NASA", "For the Benefit of All") gameToken = createToken(user.name) USERS.addUser(user, gameToken) response.set_cookie("cosmosium_login", gameToken, max_age=60 * 60 * 5) loginTokens.append({'name': user.name, 'social_token': token, 'game_token': gameToken}) redirect('/play')
def session(self, accessToken): return rauth.OAuth2Session(self.clientId, self.clientSecret, access_token=accessToken, service=self.__service())