Skip to content

Commit

Permalink
Update samples and docs for 2.0 (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Aug 30, 2018
1 parent 17a9d5f commit 46790b2
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 22 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,12 @@ async function main() {
keys.private_key,
['https://www.googleapis.com/auth/cloud-platform'],
);
await client.authorize();
const url = `https://www.googleapis.com/dns/v1/projects/${keys.project_id}`;
const res = await client.request({url});
console.log(res.data);
}

main().catch(console.error);

```

The parameters for the JWT auth client including how to use it with a `.pem` file are explained in [samples/jwt.js](samples/jwt.js).
Expand Down Expand Up @@ -302,7 +300,6 @@ async function main() {
// load the JWT or UserRefreshClient from the keys
const client = auth.fromJSON(keys);
client.scopes = ['https://www.googleapis.com/auth/cloud-platform'];
await client.authorize();
const url = `https://www.googleapis.com/dns/v1/projects/${keys.project_id}`;
const res = await client.request({url});
console.log(res.data);
Expand Down Expand Up @@ -369,10 +366,7 @@ This library is licensed under Apache 2.0. Full license text is available in [LI
[oauth]: https://developers.google.com/identity/protocols/OAuth2
[snyk-image]: https://snyk.io/test/github/google/google-auth-library-nodejs/badge.svg
[snyk-url]: https://snyk.io/test/github/google/google-auth-library-nodejs
[stability]: http://nodejs.org/api/stream.html#stream_stream
[stackoverflow]: http://stackoverflow.com/questions/tagged/google-auth-library-nodejs
[stream]: http://nodejs.org/api/stream.html#stream_class_stream_readable
[devconsole]: https://console.developer.google.com
[options]: https://github.com/google/google-auth-library-nodejs/tree/master#options
[gcloud]: https://github.com/GoogleCloudPlatform/gcloud-node
[cloudplatform]: https://developers.google.com/cloud/
2 changes: 1 addition & 1 deletion samples/adc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const { auth } = require('google-auth-library');
*/
async function main() {
const client = await auth.getClient();
const projectId = await auth.getDefaultProjectId();
const projectId = await auth.getProjectId();
const url = `https://www.googleapis.com/dns/v1/projects/${projectId}`;
const res = await client.request({ url });
console.log(res.data);
Expand Down
3 changes: 1 addition & 2 deletions samples/authRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const axios = require('axios');
* Acquire a client, and make a request to an API that's enabled by default.
*/
async function main() {
const client = await auth.getClient();
const projectId = await auth.getDefaultProjectId();
const projectId = await auth.getProjectId();
const url = `https://www.googleapis.com/dns/v1/projects/${projectId}`;
const opts = await auth.authorizeRequest();
const res = await axios.get(url, opts);
Expand Down
12 changes: 6 additions & 6 deletions samples/creds.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
/**
* Import the GoogleAuth library, and create a new GoogleAuth client.
*/
const { GoogleAuth } = require('google-auth-library');
const { auth } = require('google-auth-library');

/**
* Acquire a client, and make a request to an API that's enabled by default.
*/
async function main() {
const credentials = require('jwt.keys.json');
const scopes = 'https://www.googleapis.com/auth/cloud-platform';
const auth = new GoogleAuth({ credentials, scopes });
const client = await auth.getClient();
const projectId = await auth.getDefaultProjectId();
const client = await auth.getClient({
credentials: require('./jwt.keys.json'),
scopes: 'https://www.googleapis.com/auth/cloud-platform'
});
const projectId = await auth.getProjectId();
const url = `https://www.googleapis.com/dns/v1/projects/${projectId}`;
const res = await client.request({ url });
console.log(res.data);
Expand Down
1 change: 0 additions & 1 deletion samples/fromJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const keys = JSON.parse(keysEnvVar);
async function main() {
const client = auth.fromJSON(keys);
client.scopes = ['https://www.googleapis.com/auth/cloud-platform'];
await client.authorize();
const url = `https://www.googleapis.com/dns/v1/projects/${keys.project_id}`;
const res = await client.request({ url });
console.log(res.data);
Expand Down
2 changes: 1 addition & 1 deletion samples/keepalive.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function main() {
const client = await auth.getClient({
scopes: 'https://www.googleapis.com/auth/cloud-platform'
});
const projectId = await auth.getDefaultProjectId();
const projectId = await auth.getProjectId();
const url = `https://www.googleapis.com/dns/v1/projects/${projectId}`;

// create a new agent with keepAlive enabled
Expand Down
7 changes: 3 additions & 4 deletions samples/keyfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,17 @@
/**
* Import the GoogleAuth library, and create a new GoogleAuth client.
*/
const { GoogleAuth } = require('google-auth-library');
const { auth } = require('google-auth-library');

/**
* Acquire a client, and make a request to an API that's enabled by default.
*/
async function main() {
const auth = new GoogleAuth({
const client = await auth.getClient({
keyFilename: 'jwt.keys.json',
scopes: 'https://www.googleapis.com/auth/cloud-platform'
});
const client = await auth.getClient();
const projectId = await auth.getDefaultProjectId();
const projectId = await auth.getProjectId();
const url = `https://www.googleapis.com/dns/v1/projects/${projectId}`;
const res = await client.request({ url });
console.log(res.data);
Expand Down
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache-2.0",
"dependencies": {
"axios": "^0.18.0",
"google-auth-library": "^1.6.1",
"google-auth-library": "^2.0.0",
"opn": "^5.3.0"
},
"devDependencies": {
Expand Down

0 comments on commit 46790b2

Please sign in to comment.