def main(): parser = argparse.ArgumentParser(description='Authenticate user and obtain an API token to access the ' 'Captricity API. Assumes that you have already registered an ' 'application on Captricity.\n' 'See https://shreddr.captricity.com/developer/#register for more info.' ) parser.add_argument('--endpoint', required=True, help='The URL to the API server you are accessing, like https://shreddr.captricity.com') parser.add_argument('--client-id', required=True, help='Client ID for a registered third party application on Captricity.') parser.add_argument('--client-secret-key', required=True, help='Client Secret Key for a registered third party application on Captricity.') parser.add_argument('--port', default=8765, help='Port number for listening to the callback request') args = parser.parse_args() # Generate login url, with callback as localhost with specified port number (default 8765) login_url = args.endpoint + "/accounts/request-access/" callback_url = "http://localhost:" + str(args.port) params = { 'return-url': callback_url, 'third-party-id': args.client_id } params['signature'] = generate_request_access_signature(params, args.client_secret_key) login_url += '?' + urllib.urlencode(params) webbrowser.open(login_url) SocketServer.TCPServer(('', int(args.port)), CallbackHandler).handle_request() print 'Your API token is:', API_TOKEN
def get_account_access_request_url(self, return_url): login_url = self.endpoint + '/accounts/request-access/' params = { 'return-url': return_url, 'third-party-id': self.third_party_id, } params['signature'] = generate_request_access_signature( params, self.secret_key) login_url += '?' + urllib.urlencode(params) return login_url
def main(): parser = argparse.ArgumentParser( description='Authenticate user and obtain an API token to access the ' 'Captricity API. Assumes that you have already registered an ' 'application on Captricity.\n' 'See https://shreddr.captricity.com/developer/#register for more info.' ) parser.add_argument( '--endpoint', required=True, help= 'The URL to the API server you are accessing, like https://shreddr.captricity.com' ) parser.add_argument( '--client-id', required=True, help='Client ID for a registered third party application on Captricity.' ) parser.add_argument( '--client-secret-key', required=True, help= 'Client Secret Key for a registered third party application on Captricity.' ) parser.add_argument( '--port', default=8765, help='Port number for listening to the callback request') args = parser.parse_args() # Generate login url, with callback as localhost with specified port number (default 8765) login_url = args.endpoint + "/accounts/request-access/" callback_url = "http://localhost:" + str(args.port) params = {'return-url': callback_url, 'third-party-id': args.client_id} params['signature'] = generate_request_access_signature( params, args.client_secret_key) login_url += '?' + urllib.urlencode(params) webbrowser.open(login_url) SocketServer.TCPServer(('', int(args.port)), CallbackHandler).handle_request() print 'Your API token is:', API_TOKEN