def request_splitwise_auth(self): """ Authorize this object with Splitwise """ CONSUMER_KEY, CONSUMER_SECRET = self.keychain.get_api_credentials( "splitwise") sw_client = Splitwise(CONSUMER_KEY, CONSUMER_SECRET) # Begin authentication workflow url, _ = sw_client.getOAuth2AuthorizeURL(self.homepage) print("Please authorize integration with Splitwise: {}".format(url))
config = read_config(CONFIG_PATH) client_id = config['oauth']['client_id'] client_secret = config['oauth']['client_secret'] redirect_uri = config['oauth']['redirect_uri'] server_addr = config['server']['addr'] server_port = config.getint('server', 'port') server_debug = config.getboolean('server', 'debug') # TODO: initiate the oauth from a route instead of CLI to make this a web app s = Splitwise(client_id, client_secret) # see if we already have an access token, otherwise initialize the OAuth flow if config.has_option('oauth', 'access_token'): access_token = json.loads(config['oauth']['access_token']) s.setOAuth2AccessToken(access_token) else: print("No access token found. Initiating Splitwise integration") server_thread = threading.Thread(target=app.run, args=(server_addr, server_port, server_debug)) server_thread.start() # TODO: use url_for in 'with app.app_context():'. requires setting SERVER_NAME env var redirect_uri = redirect_uri + '/authorized' url, state = s.getOAuth2AuthorizeURL(redirect_uri) webbrowser.open_new_tab(url) server_thread.join() with open(EXPENSE_PATH) as fp: exp_data = json.load(fp) # print(s.getCurrentUser().getId()) add_group_expense(exp_data)