def auth_return(request):
if not xsrfutil.validate_token(settings.SECRET_KEY, str(request.GET['state']),
request.user.username):
return HttpResponseBadRequest()
credential = FLOW.step2_exchange(request.GET)
http = httplib2.Http()
http = credential.authorize(http)
resp, data = http.request("https://beam.pro/api/v1/users/current")
data = json.loads(data)
print data
channelId = None
if 'channel' in data:
channelId = data['channel']['id']
name = data['channel'].get("name") or "(unnamed)"
internal_label = "%s-%s" % (channelId, name)
ac = BeamAppCreds(user=request.user, label=internal_label)
ac.save()
storage = Storage(BeamCredentialsModel, 'id', ac, 'credential')
storage.put(credential)
pu = BeamUpdate(credentials=ac, user=request.user, type="beam")
pu.save()
return HttpResponseRedirect("/beam/")
评论列表
文章目录