Skip to content

Commit

Permalink
docs: use the People API for samples (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Jan 29, 2019
1 parent a61dddf commit a4618f9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 32 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions browser-test/test.oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@

/// <reference path='../node_modules/@types/sinon/ts3.1/index.d.ts'>

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';

Expand All @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions samples/oauth2-codeVerifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions samples/oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions samples/puppeteer/oauth2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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',
});

Expand Down
10 changes: 2 additions & 8 deletions samples/verifyIdToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
Expand Down

0 comments on commit a4618f9

Please sign in to comment.