Get started with authentication
Application Default Credentials (ADC) let your application use service accountcredentials to access BigQuery resources as its own identity.
Note that BigQuery doesn't support the use ofAPI keys.
Before you begin
Select the tab for how you plan to use the samples on this page:
C#
To use the .NET samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
Go
To use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
Java
To use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
Node.js
To use the Node.js samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
PHP
To use the PHP samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
Python
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
Ruby
To use the Ruby samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
For more information, see Set up authentication for a local development environment.
For information about setting up authentication for a production environment, see Set up Application Default Credentials for code running on Google Cloud.
Application Default Credentials
Client libraries can useApplication Default Credentials to easily authenticate with Google APIs and send requests to those APIs. With Application Default Credentials, you can test your application locally and deploy it without changing the underlying code. For more information, see Authenticate for using client libraries.
When you create a service object with theBigQuery ClientLibraries and don't pass in explicitcredentials, your application authenticates using Application DefaultCredentials. The following samples show how to authenticate toBigQuery by using ADC.
C#
Before trying this sample, follow theC# setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryC# API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeBefore you begin.
usingGoogle.Apis.Bigquery.v2.Data;usingGoogle.Cloud.BigQuery.V2;publicclassBigQueryCreateDataset{publicBigQueryDatasetCreateDataset(stringprojectId="your-project-id",stringlocation="US"){BigQueryClientclient=BigQueryClient.Create(projectId);vardataset=newDataset{// Specify the geographic location where the dataset should reside.Location=location};// Create the datasetreturnclient.CreateDataset(datasetId:"your_new_dataset_id",dataset);}}Go
Before trying this sample, follow theGo setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryGo API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeBefore you begin.
// Sample bigquery-quickstart creates a Google BigQuery dataset.packagemainimport("context""fmt""log""cloud.google.com/go/bigquery")funcmain(){ctx:=context.Background()// Sets your Google Cloud Platform project ID.projectID:="YOUR_PROJECT_ID"// Creates a client.client,err:=bigquery.NewClient(ctx,projectID)iferr!=nil{log.Fatalf("bigquery.NewClient: %v",err)}deferclient.Close()// Sets the name for the new dataset.datasetName:="my_new_dataset"// Creates the new BigQuery dataset.iferr:=client.Dataset(datasetName).Create(ctx,&bigquery.DatasetMetadata{});err!=nil{log.Fatalf("Failed to create dataset: %v",err)}fmt.Printf("Dataset created\n")}Java
Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeBefore you begin.
publicstaticvoidimplicit(){// Instantiate a client. If you don't specify credentials when constructing a client, the// client library will look for credentials in the environment, such as the// GOOGLE_APPLICATION_CREDENTIALS environment variable.BigQuerybigquery=BigQueryOptions.getDefaultInstance().getService();// Use the client.System.out.println("Datasets:");for(Datasetdataset:bigquery.listDatasets().iterateAll()){System.out.printf("%s%n",dataset.getDatasetId().getDataset());}}Node.js
Before trying this sample, follow theNode.js setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryNode.js API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeBefore you begin.
// Import the Google Cloud client library using default credentialsconst{BigQuery}=require('@google-cloud/bigquery');constbigquery=newBigQuery();PHP
Before trying this sample, follow thePHP setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPHP API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeBefore you begin.
use Google\Cloud\BigQuery\BigQueryClient;/** Uncomment and populate these variables in your code *///$projectId = 'The Google project ID';$bigQuery = new BigQueryClient([ 'projectId' => $projectId,]);Python
Before trying this sample, follow thePython setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryPython API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeBefore you begin.
Ruby
Before trying this sample, follow theRuby setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryRuby API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, seeBefore you begin.
require"google/cloud/bigquery"# This uses Application Default Credentials to authenticate.# @see https://cloud.google.com/bigquery/docs/authentication/getting-startedbigquery=Google::Cloud::Bigquery.newsql="SELECT "\"CONCAT('https://stackoverflow.com/questions/', CAST(id as STRING)) as url, view_count "\"FROM `bigquery-public-data.stackoverflow.posts_questions` "\"WHERE tags like '%google-bigquery%' "\"ORDER BY view_count DESC LIMIT 10"results=bigquery.querysqlresults.eachdo|row|puts"#{row[:url]}:#{row[:view_count]} views"endWhat's next
- Learn more aboutBigQuery authentication.
- Learn how toauthenticate with end-user credentials.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.