authenticate.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:RaspberryEcho 作者: ericpotvin 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号