def PollForAuthentication(self, callback):
    if not hasattr(self, '_device_code'):
      raise ScenarioLoginError('Must call GetUserCode() on a device before using the '
                               'PollForAuthentication() method.')

    http_client = httpclient.AsyncHTTPClient()

    def _OnLogin(response):
      if not response.code in (200, 302):
        raise ScenarioLoginError('Error during login process:%s' % response.error)
      self._user_cookie = self._GetUserCookieFromResponse(response)
      self._SaveAuthentication()
      callback(True)

    def _OnPollTokenEndpoint(response):
      json_response = www_util.ParseJSONResponse(response)
      if 'error' in json_response:
        callback(False)
      else:
        refresh_token = json_response.get('refresh_token')
        url = 'https://%s:%d/auth/google?refresh_token=%s' % \
              (ServerEnvironment.GetHost(), options.options.port, refresh_token)
        http_client.fetch(url, method='POST',
                          callback=_OnLogin,
                          body=json.dumps({}),
                          validate_cert=False, follow_redirects=False,
                          headers={'Content-Type': 'application/json'})

    url = _GOOGLE_OAUTH2_TOKEN_URL
    request_args = {'client_id': secrets.GetSecret('google_client_mobile_id'),
                    'client_secret': secrets.GetSecret('google_client_mobile_secret'),
                    'code': self._device_code,
                    'grant_type': 'http://oauth.net/grant_type/device/1.0'}

    http_client.fetch(url, method='POST',
                      body=urllib.urlencode(request_args),
                      callback=_OnPollTokenEndpoint)
Poll the google authorization service to find if the user code generated
dataset/ETHPy150Open viewfinderco/viewfinder/backend/watchdog/scenario.py/ScenarioDevice.PollForAuthentication