def code(self, var=None, **params):
""" The code page
"""
client_id = Config.get_config(Config.FIELD_CLIENT_ID)
client_secret = Config.get_config(Config.FIELD_CLIENT_SECRET)
code = urllib.quote(cherrypy.request.params['code'])
callback = cherrypy.url()
payload = {
"client_id" : client_id,
"client_secret" : client_secret,
"code" : code,
"grant_type" : "authorization_code",
"redirect_uri" : callback
}
result = requests.post(AlexaService.AMAZON_TOKEN_URL, data=payload)
result = result.json()
# Save the refresh token and reset access token
Config.save_config(
Config.FIELD_REFRESH_TOKEN,
format(result['refresh_token'])
)
Config.save_config(Config.FIELD_ACCESS_TOKEN, "")
html = "<b>Success!</b><br/>"
html += "Refresh token has been added to your credentials file.<br/>"
html += "You may now reboot the Pi or restart the service.<br/>"
html += "Your token: %s" % result['refresh_token']
return html
评论列表
文章目录