How to use oauth2client - 10 common examples

To help you get started, we’ve selected a few oauth2client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NYPL-Simplified / circulation / tests / admin / test_google_oauth_admin_authentication_provider.py View on Github external
def step2_exchange(self, auth_code):
                raise GoogleClient.FlowExchangeError("mock error")
        self.google.dummy_client = ExceptionRaisingClient()
github google / citest / citest / gcp_testing / gcp_agent.py View on Github external
api = default_api
      version = version or default_version

    if version is None:
      version = GcpAgent.determine_current_version(api)

    http = httplib2.Http()
    http = apiclient.http.set_user_agent(
        http, 'citest/{version}'.format(version=citest.__version__))
    credentials = None
    if credentials_path is not None:
      logger.info('Authenticating %s %s', api, version)
      credentials = ServiceAccountCredentials.from_json_keyfile_name(
          credentials_path, scopes=scopes)
    else:
      credentials = GoogleCredentials.get_application_default()
      if scopes and credentials.create_scoped_required():
        credentials = credentials.create_scoped(scopes)

    http = credentials.authorize(http)
    logger.info('Constructing %s service...', api)
    return apiclient.discovery.build(api, version, http=http)
github googleapis / oauth2client / tests / test_client.py View on Github external
def test_scope_is_required(self):
        with self.assertRaises(TypeError):
            client.OAuth2WebServerFlow('client_id+1')
github contactless / wirenboard / examples / test_suite / hw_test_common / gdocs.py View on Github external
def __init__(self, url, key_fname):
        scope = ['https://spreadsheets.google.com/feeds']
        credentials = ServiceAccountCredentials.from_json_keyfile_name(key_fname, scope)
        self.gc = gspread.authorize(credentials)

        self.wks = self.gc.open_by_url(url)
        self.worksheet = self.wks.get_worksheet(0)
github kubeflow / kubeflow / testing / test_deploy.py View on Github external
def teardown_minikube(args):
  """Delete the VM used for minikube."""

  credentials = GoogleCredentials.get_application_default()
  gce = discovery.build("compute", "v1", credentials=credentials)
  instances = gce.instances()

  request = instances.delete(
      project=args.project, zone=args.zone, instance=args.vm_name)

  response = request.execute()

  op_id = response.get("name")
  final_op = vm_util.wait_for_operation(gce, args.project, args.zone, op_id)

  logging.info("Final result for delete operation: %s", final_op)
  if final_op.get("status") != "DONE":
    raise ValueError("Delete operation has status %s", final_op.get("status"))

  if final_op.get("error"):
github googleapis / oauth2client / tests / test_client.py View on Github external
def test_to_from_json_service_account_scoped(self):
        credentials_file = datafile(
            os.path.join('gcloud', client._WELL_KNOWN_CREDENTIALS_FILE))
        creds1 = client.GoogleCredentials.from_stream(credentials_file)
        creds1 = creds1.create_scoped(['dummy_scope'])
        # Convert to and then back from json.
        creds2 = client.GoogleCredentials.from_json(creds1.to_json())

        creds1_vals = creds1.__dict__
        creds1_vals.pop('_signer')
        creds2_vals = creds2.__dict__
        creds2_vals.pop('_signer')
        self.assertEqual(creds1_vals, creds2_vals)
github googleapis / oauth2client / scripts / run_system_tests.py View on Github external
def run_user_json():
    with open(USER_KEY_PATH, 'r') as file_object:
        client_credentials = json.load(file_object)

    credentials = client.GoogleCredentials(
        access_token=None,
        client_id=client_credentials['client_id'],
        client_secret=client_credentials['client_secret'],
        refresh_token=client_credentials['refresh_token'],
        token_expiry=None,
        token_uri=oauth2client.GOOGLE_TOKEN_URI,
        user_agent='Python client library',
    )

    _check_user_info(credentials, USER_KEY_EMAIL)
github googleapis / oauth2client / tests / contrib / django_util / test_django_models.py View on Github external
def setUp(self):
        self.fake_model = tests_models.CredentialsModel()
        self.fake_model_field = self.fake_model._meta.get_field('credentials')
        self.field = models.CredentialsField(null=True)
        self.credentials = client.Credentials()
        self.pickle_str = _helpers._from_bytes(
            base64.b64encode(pickle.dumps(self.credentials)))
        self.jsonpickle_str = _helpers._from_bytes(
            base64.b64encode(jsonpickle.encode(self.credentials).encode()))
github googleapis / oauth2client / tests / contrib / test_dictionary_storage.py View on Github external
def _generate_credentials(scopes=None):
    return client.OAuth2Credentials(
        'access_tokenz',
        'client_idz',
        'client_secretz',
        'refresh_tokenz',
        '3600',
        oauth2client.GOOGLE_TOKEN_URI,
        'Test',
        id_token={
            'sub': '123',
            'email': 'user@example.com'
        },
        scopes=scopes)
github googleapis / oauth2client / tests / test_client.py View on Github external
def _do_revoke_test_helper(self, response, content,
                               error_msg, logger, store=None):
        credentials = client.OAuth2Credentials(
            None, None, None, None, None, None, None,
            revoke_uri=oauth2client.GOOGLE_REVOKE_URI)
        credentials.store = store

        http = http_mock.HttpMock(headers=response, data=content)
        token = u's3kr3tz'

        if response.status == http_client.OK:
            self.assertFalse(credentials.invalid)
            self.assertIsNone(credentials._do_revoke(http, token))
            self.assertTrue(credentials.invalid)
            if store is not None:
                store.delete.assert_called_once_with()
        else:
            self.assertFalse(credentials.invalid)
            with self.assertRaises(client.TokenRevokeError) as exc_manager: