Skip to content

Commit 3a5b7bd

Browse files
build: replace local-auth with auth in samples (#3849)
* build: replace local-auth with auth in samples
1 parent 1e2be3e commit 3a5b7bd

38 files changed

+215
-143
lines changed

samples/analytics/analytics.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
const {google} = require('googleapis');
1717
const path = require('path');
18-
const {authenticate} = require('@google-cloud/local-auth');
1918

2019
const analytics = google.analytics('v3');
2120

@@ -36,11 +35,12 @@ const variations = [
3635

3736
async function runSample() {
3837
// Obtain user credentials to use for the request
39-
const auth = await authenticate({
38+
const auth = new google.auth.GoogleAuth({
4039
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
4140
scopes: 'https://www.googleapis.com/auth/analytics',
4241
});
43-
google.options({auth});
42+
const client = await auth.getClient();
43+
google.options({auth: client});
4444

4545
const res = await analytics.management.experiments.insert({
4646
accountId: 'your-accountId',

samples/analyticsReporting/batchGet.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515

1616
const {google} = require('googleapis');
1717
const path = require('path');
18-
const {authenticate} = require('@google-cloud/local-auth');
1918

2019
const analyticsreporting = google.analyticsreporting('v4');
2120

2221
async function runSample() {
2322
// Obtain user credentials to use for the request
24-
const auth = await authenticate({
23+
const auth = new google.auth.GoogleAuth({
2524
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
2625
scopes: 'https://www.googleapis.com/auth/analytics',
2726
});
28-
google.options({auth});
27+
const client = await auth.getClient();
28+
google.options({auth: client});
2929

3030
const res = await analyticsreporting.reports.batchGet({
3131
requestBody: {

samples/blogger/insert.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515

1616
const path = require('path');
1717
const {google} = require('googleapis');
18-
const {authenticate} = require('@google-cloud/local-auth');
1918

2019
const blogger = google.blogger('v3');
2120

2221
async function runSample() {
2322
// Obtain user credentials to use for the request
24-
const auth = await authenticate({
23+
const auth = new google.auth.GoogleAuth({
2524
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
2625
scopes: 'https://www.googleapis.com/auth/blogger',
2726
});
28-
google.options({auth});
27+
const client = await auth.getClient();
28+
google.options({auth: client});
2929

3030
const res = await blogger.posts.insert({
3131
blogId: '4340475495955554224',

samples/docs/create.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515

1616
const path = require('path');
1717
const {google} = require('googleapis');
18-
const {authenticate} = require('@google-cloud/local-auth');
1918

2019
const docs = google.docs('v1');
2120

2221
async function runSample() {
2322
// Obtain user credentials to use for the request
24-
const auth = await authenticate({
23+
const auth = new google.auth.GoogleAuth({
2524
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
2625
scopes: 'https://www.googleapis.com/auth/documents',
2726
});
28-
google.options({auth});
27+
const client = await auth.getClient();
28+
google.options({auth: client});
2929

3030
// The initial call to create the doc will have a title but no content.
3131
// This is a limitation of the underlying API.

samples/docs/get.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@
1616
const path = require('path');
1717
const util = require('util');
1818
const {google} = require('googleapis');
19-
const {authenticate} = require('@google-cloud/local-auth');
2019

2120
const docs = google.docs('v1');
2221

2322
async function runSample() {
2423
// Obtain user credentials to use for the request
25-
const auth = await authenticate({
24+
const auth = new google.auth.GoogleAuth({
2625
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
2726
scopes: 'https://www.googleapis.com/auth/documents',
2827
});
29-
google.options({auth});
28+
const client = await auth.getClient();
29+
google.options({auth: client});
3030

3131
const res = await docs.documents.get({
3232
documentId: '1XPbMENiP5bWP_cbqc0bEWbq78vmUf-rWQ6aB6FVZJyc',

samples/drive/download.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ const {google} = require('googleapis');
1717
const fs = require('fs');
1818
const os = require('os');
1919
const path = require('path');
20-
const {authenticate} = require('@google-cloud/local-auth');
2120
const crypto = require('crypto');
2221
const uuid = crypto.randomUUID();
2322

2423
const drive = google.drive('v3');
2524

2625
async function runSample(fileId) {
2726
// Obtain user credentials to use for the request
28-
const auth = await authenticate({
27+
const auth = new google.auth.GoogleAuth({
2928
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
3029
scopes: [
3130
'https://www.googleapis.com/auth/drive',
@@ -37,7 +36,8 @@ async function runSample(fileId) {
3736
'https://www.googleapis.com/auth/drive.readonly',
3837
],
3938
});
40-
google.options({auth});
39+
const client = await auth.getClient();
40+
google.options({auth: client});
4141

4242
// For converting document formats, and for downloading template
4343
// documents, see the method drive.files.export():

samples/drive/export.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ const {google} = require('googleapis');
1717
const fs = require('fs');
1818
const os = require('os');
1919
const path = require('path');
20-
const {authenticate} = require('@google-cloud/local-auth');
2120

2221
const drive = google.drive('v3');
2322

2423
async function runSample() {
2524
// [START main_body]
2625
// Obtain user credentials to use for the request
27-
const auth = await authenticate({
26+
const auth = new google.auth.GoogleAuth({
2827
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
2928
scopes: 'https://www.googleapis.com/auth/drive.readonly',
3029
});
31-
google.options({auth});
30+
const client = await auth.getClient();
31+
google.options({auth: client});
3232

3333
const fileId = '1EkgdLY3T-_9hWml0VssdDWQZLEc8qqpMB77Nvsx6khA';
3434
const destPath = path.join(os.tmpdir(), 'important.pdf');

samples/drive/list.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515

1616
const path = require('path');
1717
const {google} = require('googleapis');
18-
const {authenticate} = require('@google-cloud/local-auth');
1918

2019
const drive = google.drive('v3');
2120

2221
async function runSample(query) {
2322
// Obtain user credentials to use for the request
24-
const auth = await authenticate({
23+
const auth = new google.auth.GoogleAuth({
2524
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
2625
scopes: 'https://www.googleapis.com/auth/drive.metadata.readonly',
2726
});
28-
google.options({auth});
27+
const client = await auth.getClient();
28+
google.options({auth: client});
2929

3030
const params = {pageSize: 3};
3131
params.q = query;

samples/drive/quickstart.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515

1616
// [START main_body]
1717
const path = require('path');
18-
const {authenticate} = require('@google-cloud/local-auth');
1918
const {google} = require('googleapis');
2019

2120
/**
2221
* Lists the names and IDs of up to 10 files.
2322
*/
2423
async function runSample() {
2524
// Obtain user credentials to use for the request
26-
const auth = await authenticate({
25+
const auth = new google.auth.GoogleAuth({
2726
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
2827
scopes: 'https://www.googleapis.com/auth/drive.metadata.readonly',
2928
});
30-
google.options({auth});
29+
const client = await auth.getClient();
30+
google.options({auth: client});
3131

3232
const service = google.drive('v3');
3333
const res = await service.files.list({
@@ -43,6 +43,7 @@ async function runSample() {
4343
console.log(`${file.name} (${file.id})`);
4444
}
4545
}
46+
return res.data;
4647
}
4748
if (module === require.main) {
4849
runSample().catch(console.error);

samples/drive/upload.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ const fs = require('fs');
1717
const path = require('path');
1818
const readline = require('readline');
1919
const {google} = require('googleapis');
20-
const {authenticate} = require('@google-cloud/local-auth');
2120

2221
const drive = google.drive('v3');
2322

2423
async function runSample(fileName) {
2524
// Obtain user credentials to use for the request
26-
const auth = await authenticate({
25+
const auth = new google.auth.GoogleAuth({
2726
keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
2827
scopes: 'https://www.googleapis.com/auth/drive.file',
2928
});
30-
google.options({auth});
29+
const client = await auth.getClient();
30+
google.options({auth: client});
3131

3232
const fileSize = fs.statSync(fileName).size;
3333
const res = await drive.files.create(

0 commit comments

Comments
 (0)