def _oauth2_callback(self, provider, access_token_url):
        code = self.request.get('code', None)
        error = self.request.get('error', None)
        callback_url = self._callback_uri_for(provider)
        consumer_key, consumer_secret, scope = self._get_consumer_info_for(provider)

        if error:
            raise Exception(error)

        payload = {
          'code': code,
          'client_id': consumer_key,
          'client_secret': consumer_secret,
          'redirect_uri': callback_url,
          'grant_type': 'authorization_code'
        }

        resp = urlfetch.fetch(
          url=access_token_url,
          payload=urlencode(payload),
          method=urlfetch.POST,
          headers={'Content-Type': 'application/x-www-form-urlencoded'}
        )

        auth_info = getattr(self, self.TOKEN_RESPONSE_PARSERS[provider])(resp.content)
        user_data = getattr(self, '_get_%s_user_info' % provider)(auth_info, key=consumer_key, secret=consumer_secret)

        return (user_data, auth_info)
Update the state of a light.
dataset/ETHPy150Open ibagrak/algae/gae/libs/simpleauth/handler.py/SimpleAuthHandler._oauth2_callback--crossover with--dataset/ETHPy150Open tomwilkie/awesomation/src/appengine/devices/hue.py/HueLight.sync