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
Esempio n. 2
0
 def splogin(self):
     # do something with param1
     # and render template with param
     sObj = Splitwise(Config.consumer_key, Config.consumer_secret)
     url, secret = sObj.getAuthorizeURL()
     session['secret'] = secret
     #url ='/splitwise/auth'
     return redirect(url)
Esempio n. 3
0
def login():

    sObj = Splitwise(Config.consumer_key, Config.consumer_secret)
    url, secret = sObj.getAuthorizeURL()
    session['secret'] = secret

    #If user is logged in then url redirects to authorize route
    #Else url redirects to splitwise login website
    return redirect(url)
Esempio n. 4
0
def login():
    if request.method == 'POST':
        get_date_from = request.form['Get_Trans_Date_From']
        get_date_to = request.form['Get_Trans_Date_To']
        session['date_from'] = get_date_from
        session['date_to'] = get_date_to
    sObj = Splitwise(Config.consumer_key, Config.consumer_secret)
    url, secret = sObj.getAuthorizeURL()
    session['secret'] = secret
    return redirect(url)
Esempio n. 5
0
    def login(self) -> None:
        """
        Logs into Splitwise. Requires manually entering the token and verifier
        """

        sObj = Splitwise(self.consumer_key, self.consumer_secret)
        self.url, self.login_secret = sObj.getAuthorizeURL()
        print(self.url)
        self.oauth_token = input('token: ')
        self.oauth_verifier = input('verifier: ')
Esempio n. 6
0
def login():
	sObj = Splitwise(consumer_key, secret_key)
	url, secret = sObj.getAuthorizeURL()
	session['secret'] = secret
	firstName = request.form.get("fname")
	lastName = request.form.get("lname")
	email = request.form.get("email")
	print(firstName,lastName,email)
	cur.execute('INSERT INTO UserAccounts VALUES(NULL, 1, %s, %s, %s, 0, 0)',(email, firstName, lastName))
	cnx.commit()
	return redirect(url)
Esempio n. 7
0
    def get_or_request_splitwise_creds(self, request_to_splitwise):
        SplitwiseApiUtils.splitwise_request_object = request_to_splitwise[
            'list_to_splitwise']
        SplitwiseApiUtils.splitwise_friend = request_to_splitwise[
            'splitwise_friend']

        sObj = Splitwise(SplitwiseApiUtils.consumer_key,
                         SplitwiseApiUtils.consumer_secret)
        SplitwiseApiUtils.splitwise_obj = sObj
        SplitwiseApiUtils.url, SplitwiseApiUtils.secret = sObj.getAuthorizeURL(
        )
        webbrowser.open_new_tab(SplitwiseApiUtils.url)
Esempio n. 8
0
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
Esempio n. 9
0
def home():
    if 'access_token' in session:
        return redirect(url_for("splitwise.friends"))
    print "in home.."
    consumer_key = ''
    consumer_secret = ''
    sObj = Splitwise(consumer_key, consumer_secret)
    url, secret = sObj.getAuthorizeURL()
    print "secret = ", secret
    session['secret'] = secret
    with open('secret', 'w') as f:
        f.write(secret)
    session.permanent = True
    print "Redirecting to url", url
    return redirect(url)
Esempio n. 10
0
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")
Esempio n. 11
0
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)


            
Esempio n. 12
0
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
Esempio n. 13
0
def login():

    sObj = Splitwise(Config.consumer_key,Config.consumer_secret)
    url, secret = sObj.getAuthorizeURL()
    session['secret'] = secret
    return redirect(url)
Esempio n. 14
0
def authorize_step1():
    spltwse = Splitwise(consumer_key, consumer_secret)
    url, secret = spltwse.getAuthorizeURL()
    session['secret'] = secret

    return redirect(url)
Esempio n. 15
0
def login():
    wise = Splitwise('consumer_key', 'consumer_secret')
    url, secret = wise.getAuthorizeURL()
    session[KEY_SECRET] = secret
    return redirect(url)
Esempio n. 16
0
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