示例#1
0
def menu():
	credentials = common.loadCredentials()
	print 'Do you want to:'
	print '1. Generate an access token for the first time'
	print '2. Refresh your access token?'
	print '3. Generate an access token for uploads'
	selected = raw_input('Select one:')
	if selected == '1':
		print 'Open the following URL in your browser and login with your Circ credentials:'
		print 'https://auth.getcirc.com/?client_id=' + credentials['CLIENT_ID'] + '&response_type=code&redirect_uri=' + REDIRECT_URI + '&state=' + STATE
		response = raw_input('Enter the full response URL here:')
		try:
			code = re.search('code=(.*?)$', response).group(1)
		except KeyError:
			print 'ERROR: No code param found in response URL'
			sys.exit(2)
		grantType = 'authorization_code'
		clientSig = hashlib.md5(credentials['CLIENT_SECRET'] + 'client_id' + credentials['CLIENT_ID'] + 'code' + code + 'grant_type' + grantType + 'redirect_uri' + REDIRECT_URI + 'state' + STATE).hexdigest()
		response = common.request('access',baseUrl='https://api.circ.io/oauth/',
			client_id=credentials['CLIENT_ID'] ,
			code=code,
			grant_type=grantType,
			redirect_uri=REDIRECT_URI,
			state=STATE,
			client_sig=clientSig)
		print response
		credentials['ACCESS_TOKEN'] = response['access_token']
		credentials['REFRESH_TOKEN'] = response['refresh_token']
		common.saveCredentials(credentials)
	elif selected == '2':
		grantType = 'refresh_token'
		clientSig = hashlib.md5(credentials['CLIENT_SECRET'] + 'client_id' + credentials['CLIENT_ID'] + 'grant_type' + grantType + 'redirect_uri' + REDIRECT_URI + 'refresh_token' + credentials['REFRESH_TOKEN'] ).hexdigest()
		response = common.request('access',baseUrl='https://api.circ.io/oauth/',
			client_id=credentials['CLIENT_ID'] ,
			refresh_token=credentials['REFRESH_TOKEN'] ,
			grant_type=grantType,
			redirect_uri=REDIRECT_URI,
			client_sig=clientSig)
		credentials['ACCESS_TOKEN'] = response['access_token']
		credentials['REFRESH_TOKEN'] = response['refresh_token']
		common.saveCredentials(credentials)
	elif selected == '3':
		grantType = 'refresh_token'
		clientSig = hashlib.md5(credentials['CLIENT_SECRET'] + 'client_id' + credentials['CLIENT_ID'] + 'grant_type' + grantType + 'redirect_uri' + REDIRECT_URI + 'refresh_token' + credentials['REFRESH_TOKEN'] ).hexdigest()
		response = common.request('access',baseUrl='https://api.circ.io/oauth/',
			client_id=credentials['CLIENT_ID'] ,
			refresh_token=credentials['REFRESH_TOKEN'] ,
			grant_type=grantType,
			redirect_uri=REDIRECT_URI,
			client_sig=clientSig)
		credentials['HTTP_ACCESS_TOKEN'] = response['access_token']
		credentials['REFRESH_TOKEN'] = response['refresh_token']
		common.saveCredentials(credentials)
	else:
		menu()
示例#2
0
文件: circ.py 项目: johanfrick/circux
# script for communicating with http://getcirc.com/
#
from __future__ import division

import getopt
import hashlib
import requests
import urllib
import sys
import signal
import os
import datetime
import common
import base64

credentials = common.loadCredentials()

def main():
	signal.signal(signal.SIGINT, signal_handler)
	try:
		opts, args = getopt.getopt(sys.argv[1:], '', ['ls=', 'send=', 'get=', 'delete-all='])
	except getopt.GetoptError, err:
		print str(err)
		usage()
		sys.exit(2)

	if not opts:
		usage()
		sys.exit(2)

	for option, argument in opts: