How to use the oauth2client.client.SignedJwtAssertionCredentials function in oauth2client

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 maybelinot / df2gspread / df2gspread / utils.py View on Github external
# handle regular json format where key is separate
                client_email = client_data['installed']['client_id']
                if private_key is None:
                    raise RuntimeError('You must have the private key file \
                                       with the regular json file. Try creating a new \
                                       public/private key pair and downloading as json.')
            else:
                # handle newer case where json file has everything in it
                client_email = client_data['client_email']
                private_key = client_data['private_key']

    if client_email is None or private_key is None:
        raise RuntimeError(
            'Client email and/or private key not provided by inputs.')

    credentials = client.SignedJwtAssertionCredentials(
        client_email, private_key, SCOPES)

    return credentials
github MirakelX / mirakel-android / scripts / upload_apks.py View on Github external
def upload(package, service, apk, track):

  # Load the service key and email from the Google Developer Service Account json file
  service_settings = json.load(service)

  # Create an httplib2.Http object to handle our HTTP requests and authorize it
  # with the Credentials. Note that the first parameter, service_account_name,
  # is the Email address created for the Service account. It must be the email
  # address associated with the key that was created.
  credentials = client.SignedJwtAssertionCredentials(
      service_settings['client_email'],
      service_settings['private_key'],
      scope='https://www.googleapis.com/auth/androidpublisher')
  http = httplib2.Http()
  http = credentials.authorize(http)

  service = build('androidpublisher', 'v2', http=http)

  try:
    edit_request = service.edits().insert(body={}, packageName=package)
    result = edit_request.execute()
    edit_id = result['id']

    apk_response = service.edits().apks().upload(
        editId=edit_id,
        packageName=package,
github mg6maciej / VielenGamesAndroidClient / ci / basic_upload_apks.py View on Github external
def main():

  f = file('key.p12', 'rb')
  key = f.read()
  f.close()

  # Authenticate and construct service.
  credentials = client.SignedJwtAssertionCredentials(
      SERVICE_ACCOUNT_EMAIL,
      key,
      scope='https://www.googleapis.com/auth/androidpublisher')
  http = httplib2.Http()
  http = credentials.authorize(http)

  service = build('androidpublisher', 'v2', http=http)

  # Process flags and read their values.
  flags = argparser.parse_args()
  package_name = flags.package_name
  apk_file = flags.apk_file

  try:
    edit_request = service.edits().insert(body={}, packageName=package_name)
    result = edit_request.execute()
github cair / deep-rts / scripts / python / FileServer.py View on Github external
def upload(backupFile, backupFileName):


    """Email of the Service Account"""
    SERVICE_ACCOUNT_EMAIL = 'pydrive@phd-drive.iam.gserviceaccount.com'

    """Path to the Service Account's Private Key file"""
    SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'phd-drive.p12'

    f = open(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
    key = f.read()
    f.close()

    credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL, key,
        scope='https://www.googleapis.com/auth/drive', sub='email')
    http = httplib2.Http()
    credentials.authorize(http)

    gauth = GoogleAuth()
    gauth.credentials = credentials

    drive = GoogleDrive(gauth)

    file1 = drive.CreateFile({'title': backupFileName, "parents" : [{"id":"0B7FoN03AUUdZVlNETEtWLS1VTzQ"}]} )  # Create GoogleDriveFile instance with title 'Hello.txt'

    file1.SetContentFile(backupFile);
    file1.Upload()
github OpenNews / schedule-data-loader / update_data.py View on Github external
def authenticate_with_google():
    '''
    Connect to Google Spreadsheet with gspread library.
    '''
    credentials = SignedJwtAssertionCredentials(
        GOOGLE_API_CONFIG['CLIENT_EMAIL'], GOOGLE_API_CONFIG['PRIVATE_KEY'], GOOGLE_API_CONFIG['SCOPE']
    )
    google_api_conn = gspread.authorize(credentials)
    
    return google_api_conn
github googlearchive / billing-export-python / main.py View on Github external
def UseRemoteGCS():
    """Use remote GCS via a signed certificate."""
    logging.debug('Using remote gcs.')
    try:
        from oauth2client.client import SignedJwtAssertionCredentials
    except ImportError:
        logging.error('For local testing with remote GCS, install pycrypto.')
        return
    http_object = httplib2.Http(timeout=60)
    service_account = config.service_account
    private_key_pem_file = config.private_key_pem_file
    scope = 'https://www.googleapis.com/auth/devstorage.full_control'
    private_key = file(private_key_pem_file, 'rb').read()
    certificate = SignedJwtAssertionCredentials(service_account,
                                                private_key,
                                                scope)
    certificate.refresh(http_object)
    gcs_common.set_access_token(certificate.access_token)
github kkamkou / gitmostwanted.com / gitmostwanted / bigquery / query.py View on Github external
def service():
    config = app.config['GOOGLE_BIGQUERY']

    with open(config['private_key_path'], 'rb') as f:
        private_key = f.read()

    auth = SignedJwtAssertionCredentials(config['email'], private_key, config['url'])
    return discovery.build(config['service_name'], config['version'], http=auth.authorize(Http()))
github akrherz / iem / scripts / cscap / util.py View on Github external
def get_driveclient():
    """ Return an authorized apiclient """
    client_email = CONFIG['service_account']
    with open("CSCAP-6886c10d6ffb.p12") as f:
        private_key = f.read()

    credentials = SignedJwtAssertionCredentials(
        client_email, private_key,
        'https://www.googleapis.com/auth/drive')

    http_auth = credentials.authorize(Http())

    return build('drive', 'v2', http=http_auth)
github repertory / docker-redash / redash / query_runner / big_query.py View on Github external
def _get_bigquery_service(self):
        scope = [
            "https://www.googleapis.com/auth/bigquery",
            "https://www.googleapis.com/auth/drive"
        ]

        key = json.loads(b64decode(self.configuration['jsonKeyFile']))

        credentials = SignedJwtAssertionCredentials(key['client_email'], key['private_key'], scope=scope)
        http = httplib2.Http(timeout=settings.BIGQUERY_HTTP_TIMEOUT)
        http = credentials.authorize(http)

        return build("bigquery", "v2", http=http)
github playgameservices / management-tools / publishing-sample / games-config.py View on Github external
if flags.p12 is not None and flags.svcAccount is None:
    parser.error('--svcAccount is needed when specifying a key file')
  if flags.p12 is None and flags.svcAccount is not None:
    parser.error('--p12 is needed when specifying a service account')

  if flags.operation in ['list', 'insert'] and flags.appId is None:
    parser.error('insert and list operations require appId')
  elif flags.operation in ['update', 'patch', 'insert'] and flags.incsv is None:
    parser.error('update/patch operations requires --incsv ')

  if flags.p12:
    f = file(flags.p12, 'rb')
    key = f.read()
    f.close()

    creds = SignedJwtAssertionCredentials(flags.svcAccount, key, SCOPE)

  else:
    flow = flow_from_clientsecrets(CLIENT_SECRETS, scope=SCOPE)
    storage = Storage(OAUTH2_STORAGE)

    creds = storage.get()

    if creds is None or creds.invalid:
      creds = run_flow(flow, storage, flags)

  http = httplib2.Http()
  http = creds.authorize(http)

  # build the api using the discovery document.
  service = build('gamesConfiguration','v1configuration', http=http)