Skip to content

Instantly share code, notes, and snippets.

@shehaaz
Last active August 29, 2015 14:00
Show Gist options
  • Save shehaaz/26957b6302e915251d86 to your computer and use it in GitHub Desktop.
Save shehaaz/26957b6302e915251d86 to your computer and use it in GitHub Desktop.
@app.route('/auth')
def auth():
# here we want to get the ?code=<authorizationcode>
code = request.args.get('code')
if code == None:
return "Error"
else:
#exchange authorization code for an access token,
#make a POST request to the access token url endpoint:
r=requests.post("https://api.moves-app.com/oauth/v1/access_token?grant_type=authorization_code&code="+str(code)+"&client_id=CLIENT_ID&client_secret=CLIENT_SECRET")
logging.basicConfig(filename='users.log',level=logging.INFO)
logger = logging.getLogger("USER_LOGGER")
logger.info(r.text)
js = json.loads(r.text)
try:
access_token = js['access_token']
user_id = js['user_id']
validate = requests.get("https://api.moves-app.com/oauth/v1/tokeninfo?access_token="+str(access_token))
return validate.text
except:
error_code = js['error']
return error_code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment