From a4618f9641c9a09ed0665e8c005a13294d0d6826 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Tue, 29 Jan 2019 11:56:19 -0800 Subject: [PATCH] docs: use the People API for samples (#609) --- README.md | 12 +++++------- browser-test/test.oauth2.ts | 8 +------- samples/oauth2-codeVerifier.js | 8 ++++---- samples/oauth2.js | 8 ++++---- samples/puppeteer/oauth2-test.js | 4 ++-- samples/verifyIdToken.js | 10 ++-------- 6 files changed, 18 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index fbbaf2e4..e886ae2e 100644 --- a/README.md +++ b/README.md @@ -97,9 +97,9 @@ const keys = require('./oauth2.keys.json'); */ async function main() { const oAuth2Client = await getAuthenticatedClient(); - // Make a simple request to the Google Plus API using our pre-authenticated client. The `request()` method - // takes an AxiosRequestConfig object. Visit https://github.com/axios/axios#request-config. - const url = 'https://www.googleapis.com/plus/v1/people?query=pizza'; + // Make a simple request to the People API using our pre-authenticated client. The `request()` method + // takes an GaxiosOptions object. Visit https://github.com/JustinBeckwith/gaxios. + const url = 'https://people.googleapis.com/v1/people/me?personFields=names'; const res = await oAuth2Client.request({url}); console.log(res.data); @@ -128,7 +128,7 @@ function getAuthenticatedClient() { // Generate the url that will be used for the consent dialog. const authorizeUrl = oAuth2Client.generateAuthUrl({ access_type: 'offline', - scope: 'https://www.googleapis.com/auth/plus.me', + scope: 'https://www.googleapis.com/auth/userinfo.profile', }); // Open an http server to accept the oauth callback. In this simple example, the @@ -204,7 +204,7 @@ const authorizeUrl = oAuth2Client.generateAuthUrl({ // To get a refresh token, you MUST set access_type to `offline`. access_type: 'offline', // set the appropriate scopes - scope: 'https://www.googleapis.com/auth/plus.me', + scope: 'https://www.googleapis.com/auth/userinfo.profile', // A refresh token is only returned the first time the user // consents to providing access. For illustration purposes, // setting the prompt to 'consent' will force this consent @@ -348,8 +348,6 @@ This library is licensed under Apache 2.0. Full license text is available in [LI [Application Default Credentials]: https://cloud.google.com/docs/authentication/getting-started [apptype]: https://user-images.githubusercontent.com/534619/36553844-3f9a863c-17b2-11e8-904a-29f6cd5f807a.png [authdocs]: https://developers.google.com/accounts/docs/OAuth2Login -[axios]: https://github.com/axios/axios -[axiosOpts]: https://github.com/axios/axios#request-config [bugs]: https://github.com/googleapis/google-auth-library-nodejs/issues [codecov-image]: https://codecov.io/gh/googleapis/google-auth-library-nodejs/branch/master/graph/badge.svg [codecov-url]: https://codecov.io/gh/googleapis/google-auth-library-nodejs diff --git a/browser-test/test.oauth2.ts b/browser-test/test.oauth2.ts index 7262c23d..e69ab67b 100644 --- a/browser-test/test.oauth2.ts +++ b/browser-test/test.oauth2.ts @@ -16,21 +16,16 @@ /// -import {AxiosError, AxiosPromise, AxiosRequestConfig} from 'axios'; import * as base64js from 'base64-js'; import {assert} from 'chai'; -import * as fs from 'fs'; -import * as path from 'path'; import * as sinon from 'sinon'; -import {BodyResponseCallback} from '../src/transporters'; - // Not all browsers support `TextEncoder`. The following `require` will // provide a fast UTF8-only replacement for those browsers that don't support // text encoding natively. require('fast-text-encoding'); -import {CodeChallengeMethod, DefaultTransporter, GoogleAuth, OAuth2Client} from '../src'; +import {CodeChallengeMethod, OAuth2Client} from '../src'; import {CertificateFormat} from '../src/auth/oauth2client'; import {JwkCertificate} from '../src/crypto/crypto'; @@ -39,7 +34,6 @@ const CLIENT_SECRET = 'CLIENT_SECRET'; const REDIRECT_URI = 'REDIRECT'; const ACCESS_TYPE = 'offline'; const SCOPE = 'scopex'; -const baseUrl = 'https://oauth2.googleapis.com'; const FEDERATED_SIGNON_JWK_CERTS = [ { 'kid': '4665c2781899014617337df9cbf220686505a06c', diff --git a/samples/oauth2-codeVerifier.js b/samples/oauth2-codeVerifier.js index 5ba95dac..4ec9208d 100644 --- a/samples/oauth2-codeVerifier.js +++ b/samples/oauth2-codeVerifier.js @@ -27,9 +27,9 @@ const keys = require('./oauth2.keys.json'); */ async function main() { const oAuth2Client = await getAuthenticatedClient(); - // Make a simple request to the Google Plus API using our pre-authenticated client. The `request()` method - // takes an AxiosRequestConfig object. Visit https://github.com/axios/axios#request-config. - const url = 'https://www.googleapis.com/plus/v1/people?query=pizza'; + // Make a simple request to the People API using our pre-authenticated client. The `request()` method + // takes an GaxiosOptions object. Visit https://github.com/JustinBeckwith/gaxios. + const url = 'https://people.googleapis.com/v1/people/me?personFields=names'; const res = await oAuth2Client.request({url}); console.log(res.data); } @@ -55,7 +55,7 @@ async function getAuthenticatedClient() { // Generate the url that will be used for the consent dialog. const authorizeUrl = oAuth2Client.generateAuthUrl({ access_type: 'offline', - scope: 'https://www.googleapis.com/auth/plus.me', + scope: 'https://www.googleapis.com/auth/userinfo.profile', // When using `generateCodeVerifier`, make sure to use code_challenge_method 'S256'. code_challenge_method: 'S256', // Pass along the generated code challenge. diff --git a/samples/oauth2.js b/samples/oauth2.js index 0cc4e89c..cfded95a 100644 --- a/samples/oauth2.js +++ b/samples/oauth2.js @@ -27,9 +27,9 @@ const keys = require('./oauth2.keys.json'); */ async function main() { const oAuth2Client = await getAuthenticatedClient(); - // Make a simple request to the Google Plus API using our pre-authenticated client. The `request()` method - // takes an AxiosRequestConfig object. Visit https://github.com/axios/axios#request-config. - const url = 'https://www.googleapis.com/plus/v1/people?query=pizza'; + // Make a simple request to the People API using our pre-authenticated client. The `request()` method + // takes an GaxiosOptions object. Visit https://github.com/JustinBeckwith/gaxios. + const url = 'https://people.googleapis.com/v1/people/me?personFields=names'; const res = await oAuth2Client.request({url}); console.log(res.data); @@ -58,7 +58,7 @@ function getAuthenticatedClient() { // Generate the url that will be used for the consent dialog. const authorizeUrl = oAuth2Client.generateAuthUrl({ access_type: 'offline', - scope: 'https://www.googleapis.com/auth/plus.me', + scope: 'https://www.googleapis.com/auth/userinfo.profile', }); // Open an http server to accept the oauth callback. In this simple example, the diff --git a/samples/puppeteer/oauth2-test.js b/samples/puppeteer/oauth2-test.js index ef6ca473..0d4d6228 100644 --- a/samples/puppeteer/oauth2-test.js +++ b/samples/puppeteer/oauth2-test.js @@ -36,7 +36,7 @@ const config = require('../config.keys.json'); async function main() { const oAuth2Client = await getAuthenticatedClient(); - const url = 'https://www.googleapis.com/plus/v1/people?query=pizza'; + const url = 'https://people.googleapis.com/v1/people/me?personFields=names'; const res = await oAuth2Client.request({url}); console.log(res.data); } @@ -55,7 +55,7 @@ function getAuthenticatedClient() { // Generate the url that will be used for the consent dialog. const authorizeUrl = oAuth2Client.generateAuthUrl({ access_type: 'offline', - scope: 'https://www.googleapis.com/auth/plus.me', + scope: 'https://www.googleapis.com/auth/userinfo.profile', prompt: 'consent', }); diff --git a/samples/verifyIdToken.js b/samples/verifyIdToken.js index e54a50a8..c0554c7e 100644 --- a/samples/verifyIdToken.js +++ b/samples/verifyIdToken.js @@ -36,7 +36,7 @@ async function main() { console.log(ticket); // You can use this info to get user information too. - const url = `https://www.googleapis.com/plus/v1/people/me`; + const url = `https://people.googleapis.com/v1/people/me?personFields=names`; const res = await oAuth2Client.request({url}); console.log(res.data); } @@ -57,13 +57,7 @@ function getAuthenticatedClient() { // Generate the url that will be used for the consent dialog. const authorizeUrl = oAuth2Client.generateAuthUrl({ - scope: [ - 'https://www.googleapis.com/auth/plus.login', - 'https://www.googleapis.com/auth/plus.me', - 'https://www.googleapis.com/auth/userinfo.email', - 'https://www.googleapis.com/auth/userinfo.profile', - 'email', - ], + scope: 'https://www.googleapis.com/auth/userinfo.profile', }); // Open an http server to accept the oauth callback. In this simple example, the