def authorize(path_to_auth = None): if path_to_auth == None: path_to_auth = 'auth.json' if os.path.isfile(path_to_auth): with open(path_to_auth) as json_file: auth = json.load(json_file) sObj = Splitwise(auth['consumer_key'],auth['consumer_secret'],auth['access_token']) else: print("No pre-existing authorization found. Creating new auth") auth = {} # Go to https://secure.splitwise.com/apps/new and register the app to get your consumer key and secret auth['consumer_key'] = input("Please enter your consumer key:\n") auth['consumer_secret'] = input("Please enter your consumer secret:\n") sObj = Splitwise(auth['consumer_key'],auth['consumer_secret']) url, auth['secret'] = sObj.getAuthorizeURL() print("Authroize via the following URL") print(url) auth['oauth_token'] = url.split("=")[1] auth['oauth_verifier'] = input("Please enter the oauth_verifier:\n") auth['access_token'] = sObj.getAccessToken(auth['oauth_token'],auth['secret'],auth['oauth_verifier']) print("Successfully Authorized\n") sObj.setAccessToken(auth['access_token']) save = input("Save these credentials for future use? (y/n):\n") if save == "y": with open(path_to_auth, 'w') as outfile: json.dump(auth, outfile, indent=4) print("auth.json file has been saved in the current directory. Keep this file safe.") return sObj
def authorize(): oauth_token = request.args.get('oauth_token') oauth_verifier = request.args.get('oauth_verifier') wise = Splitwise('consumer_key', 'consumer_secret') access_token = wise.getAccessToken(oauth_token, session[KEY_SECRET], oauth_verifier) session[KEY_ACCESS_TOKEN] = access_token return redirect(url_for('friends'))
def authorize_step2(): oauth_token = request.args.get('oauth_token') oauth_verifier = request.args.get('oauth_verifier') spltwse = Splitwise(consumer_key, consumer_secret) access_token = spltwse.getAccessToken(oauth_token, session['secret'], oauth_verifier) session['access_token'] = access_token return "Authorization successful"
def authorize(): if 'secret' not in session: return redirect(url_for("home")) oauth_token = request.args.get('oauth_token') oauth_verifier = request.args.get('oauth_verifier') sObj = Splitwise(consumer_key, secret_key) access_token = sObj.getAccessToken(oauth_token,session['secret'],oauth_verifier) session['access_token'] = access_token sObj.setAccessToken(session['access_token']) createGroup([[sObj.getCurrentUser().getFirstName(),sObj.getCurrentUser().getLastName(), sObj.getCurrentUser().getEmail()]], "The Room") return redirect(url_for("home"))
def get_access_token(config): sw = Splitwise(config.splitwise_key, config.splitwise_secret) url, secret = sw.getAuthorizeURL() print(url, secret) oauth_token = url.split('=')[1] oauth_verifier = input("oauth_verfier: ") access_token = sw.getAccessToken(oauth_token, secret, oauth_verifier) print("Add access_token to configuration for next time:") access_token_config = str(access_token).replace("'", '"') print(f'"splitwise_access_token": {access_token_config}') return access_token
def authorize(): if 'secret' not in session: return redirect(url_for("home")) oauth_token = request.args.get('oauth_token') oauth_verifier = request.args.get('oauth_verifier') sObj = Splitwise(Config.consumer_key,Config.consumer_secret) access_token = sObj.getAccessToken(oauth_token,session['secret'],oauth_verifier) session['access_token'] = access_token return redirect(url_for("home"))
def authorize(): if 'secret' not in session: return redirect(url_for("home")) oauth_token = request.args.get('oauth_token') oauth_verifier = request.args.get('oauth_verifier') sObj = Splitwise(consumer_key, secret_key) access_token = sObj.getAccessToken(oauth_token,session['secret'],oauth_verifier) session['access_token'] = access_token sObj.setAccessToken(session['access_token']) ram = ['Ram','Muthukumaran', '*****@*****.**'] david = ["David",'Terpay','*****@*****.**'] # createGroup([[sObj.getCurrentUser().getFirstName(),sObj.getCurrentUser().getLastName(), sObj.getCurrentUser().getEmail()],ram,david], "The Room") return redirect(url_for("home"))
def authorize(self) -> None: """ Authorizes app to Splitwise """ if not self.login_secret: #TODO trigger error self.login() sObj = Splitwise(self.consumer_key, self.consumer_secret) self.access_token = sObj.getAccessToken(self.oauth_token, self.login_secret, self.oauth_verifier)
def spauthed(self): if 'secret' not in session: return redirect('/home/login') oauth_token = request.args.get('oauth_token') oauth_verifier = request.args.get('oauth_verifier') sObj = Splitwise(Config.consumer_key, Config.consumer_secret) access_token = sObj.getAccessToken(oauth_token, session['secret'], oauth_verifier) session['access_token'] = access_token return redirect('/home/login')
def authorize(): if 'secret' not in session_flask: return redirect(url_for("home")) oauth_token = request_flask.args.get('oauth_token') oauth_verifier = request_flask.args.get('oauth_verifier') sObj = Splitwise(consumer_key, consumer_secret) access_token = sObj.getAccessToken(oauth_token, session_flask['secret'], oauth_verifier) session_flask['access_token'] = access_token external_tokens['splitwise'] = access_token return redirect(url_for("loggedin"))
def splitwiseLogin(): if 'splitwisesecret' not in session or 'oauth_token' not in request.args or 'oauth_verifier' not in request.args: sObj = Splitwise(Config.splitwise_consumer_key,Config.splitwise_consumer_secret) url, secret = sObj.getAuthorizeURL() session['splitwisesecret'] = secret return redirect(url) else: oauth_token = request.args.get('oauth_token') oauth_verifier = request.args.get('oauth_verifier') sObj = Splitwise(Config.splitwise_consumer_key,Config.splitwise_consumer_secret) access_token = sObj.getAccessToken(oauth_token,session['splitwisesecret'],oauth_verifier) session['splitwiseaccesstoken'] = access_token return redirect(url_for('home')) return render_template("home.html")
def splitwiseLogin(): if SPLITWISE_OAUTH_TOKEN not in request.args or SPLITWISE_OAUTH_VERIFIER not in request.args: if FACEBOOK_ACCOUNT_LINKING_TOKEN not in request.args or FACEBOOK_REDIRECT_URI not in request.args: abort(404) app.logger.debug("User trying to provide splitwise access") sObj = Splitwise(app.config["SPLITWISE_CONSUMER_KEY"],app.config["SPLITWISE_CONSUMER_SECRET"]) url, secret = sObj.getAuthorizeURL() session[SPLITWISE_SECRET] = secret session[FACEBOOK_ACCOUNT_LINKING_TOKEN] = request.args[FACEBOOK_ACCOUNT_LINKING_TOKEN] session[FACEBOOK_REDIRECT_URI] = request.args[FACEBOOK_REDIRECT_URI] return redirect(url) else: oauth_token = request.args.get(SPLITWISE_OAUTH_TOKEN) oauth_verifier = request.args.get(SPLITWISE_OAUTH_VERIFIER) sObj = Splitwise(app.config["SPLITWISE_CONSUMER_KEY"],app.config["SPLITWISE_CONSUMER_SECRET"]) access_token = sObj.getAccessToken(oauth_token,session[SPLITWISE_SECRET],oauth_verifier) messenger = FacebookMessenger(app.config['FACEBOOK_PAGE_ACCESS_TOKEN'],app.config['FACEBOOK_VERIFY_TOKEN']) facebook_receipient_id = messenger.getRecepientId(session[FACEBOOK_ACCOUNT_LINKING_TOKEN]) authorization_code = None if facebook_receipient_id is not None: user = User.query.filter_by(user_id=facebook_receipient_id).first() if not user: user = User() user.user_id = str(facebook_receipient_id) user.splitwise_token = access_token[SPLITWISE_OAUTH_TOKEN] user.splitwise_token_secret = access_token[SPLITWISE_OAUTH_TOKEN_SECRET] user.save() authorization_code = 'success' redirect_url = urllib.unquote(session[FACEBOOK_REDIRECT_URI]) if authorization_code: redirect_url += '&authorization_code='+authorization_code return redirect(redirect_url)
def authorize(): print session secret = "" with open('secret', 'r') as f: secret = f.readline() secret = secret.strip() oauth_token = request.args.get('oauth_token') oauth_verifier = request.args.get('oauth_verifier') consumer_key = '' consumer_secret = '' sObj = Splitwise(consumer_key, consumer_secret) access_token = sObj.getAccessToken(oauth_token, secret, oauth_verifier) print "type of access = ", type(access_token) with open('accesstoken.json', 'w') as f: json.dump(access_token, f) session['access_token'] = access_token print "*" * 50 print url_for("splitwise.friends") return redirect(url_for("splitwise.friends"))
class SplitwiseOAuthManager(object): CONSUMER_KEY = 'fACzGnELB2PJ9yj00KFhamAEXARtq4HNXKkc2649' CONSUMER_SECRET = '4JhR47gtvqfB5bKTNPvdtK2yKYeRCDp2JbRyFlnR' def __init__(self, userId=None, auth_token=None): self.userId = userId self.splitwise_handle = Splitwise(SplitwiseOAuthManager.CONSUMER_KEY, SplitwiseOAuthManager.CONSUMER_SECRET) self.auth_token = auth_token def request_authorized_url(self): self.url, self._secret = self.splitwise_handle.getAuthorizeURL() logger.info("Received url=%s and secrect=%s" %(self.url, self._secret)) query_param = urlparse(self.url).query if 'oauth_token' in query_param: self.auth_token=query_param.split('=')[1] session = UserSession(userId=self.userId, oauth_token=self.auth_token, secret=self._secret) UserSessionManager().persist_user_session(session) return tinyurl.create_one(self.url) def request_access_token(self, auth_verifier=None): mgr = UserSessionManager() session = mgr.get_session_from_oauth_token(self.auth_token) logger.info("User session %s" %repr(session)) access_token = self.splitwise_handle.getAccessToken(session.oauth_token, session.secret, auth_verifier) session.access_token = access_token mgr.persist_user_session(session) return access_token def get_access_token(self): mgr = UserSessionManager() session = mgr.get_session_from_userid(self.userId) result = session.access_token if session else None return result
from splitwise import Splitwise # Go to https://secure.splitwise.com/oauth_clients and get the key and secret sObj = Splitwise("key", "secret") url, secret = sObj.getAuthorizeURL() # go to URL ad obtain verification code access_token = sObj.getAccessToken(url.split('=')[1], secret, "verification code") sObj.setAccessToken(access_token) # Parameters to search for expenses a_group_id = None a_friendship_id = None a_expense_bundle_id = None a_description = None a_details = None a_payment = None a_cost = None a_date_start = None a_date_end = None a_category_id = None # Parameters to substitute to found expenses b_group_id = None b_friendship_id = None b_expense_bundle_id = None b_description = None b_details = None b_payment = None b_cost = None