Example #1
0
    def refresh(self, request=None):
        """Refreshes the credential's access token.

    Args:
      request: google.auth.transport.Request, The object used to make HTTP
        requests. If not provided, a default request will be used.

    Raises:
      google.auth.exceptions.RefreshError: If the credentials could not be
      refreshed.
    """
        with self._lock:
            if request is None:
                request = transport.create_request()
            self._locked_refresh(request)
            # Save the new tokens back to disk, if these credentials are disk-backed.
            if self._filename:
                self._locked_write()
Example #2
0
  def _fetch_id_token_data(self):
    """Fetches verification details from Google for the OAuth2.0 token.

    See more: https://developers.google.com/identity/sign-in/web/backend-auth

    Raises:
      CredentialsError: If no id_token is present.
    """
    if not self.id_token:
      raise CredentialsError('Failed to fetch token data. No id_token present.')

    request = transport.create_request()
    if self.expired:
      # The id_token needs to be unexpired, in order to request data about it.
      self.refresh(request)

    self._id_token_data = google.oauth2.id_token.verify_oauth2_token(
        self.id_token, request)
Example #3
0
 def test_request_is_google_auth_httplib2_compatible(self):
     request = transport.create_request()
     self.assertIsInstance(request, google_auth_httplib2.Request)
Example #4
0
 def test_create_request_returns_request_with_forced_user_agent(self):
     request = transport.create_request()
     self.assertIsInstance(request, transport.Request)
Example #5
0
 def test_create_request_uses_provided_http(self):
     request = transport.create_request(http=self.mock_http)
     self.assertEqual(request.http, self.mock_http)
Example #6
0
 def test_create_request_uses_default_http(self, mock_create_http):
     request = transport.create_request()
     self.assertEqual(request.http, mock_create_http.return_value)