Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use URL constructor in the samples #1424

Merged
merged 1 commit into from Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions samples/oauth2.js
Expand Up @@ -17,7 +17,6 @@ const fs = require('fs');
const path = require('path');
const http = require('http');
const url = require('url');
const querystring = require('querystring');
const opn = require('opn');
const destroyer = require('server-destroy');

Expand Down Expand Up @@ -61,10 +60,10 @@ async function authenticate(scopes) {
.createServer(async (req, res) => {
try {
if (req.url.indexOf('/oauth2callback') > -1) {
const qs = querystring.parse(url.parse(req.url).query);
const qs = new url.URL(req.url).searchParams;
res.end('Authentication successful! Please return to the console.');
server.destroy();
const {tokens} = await oauth2Client.getToken(qs.code);
const {tokens} = await oauth2Client.getToken(qs.get('code'));
oauth2Client.credentials = tokens;
resolve(oauth2Client);
}
Expand Down
9 changes: 4 additions & 5 deletions samples/sampleclient.js
Expand Up @@ -20,7 +20,6 @@
const {google} = require('googleapis');
const http = require('http');
const url = require('url');
const querystring = require('querystring');
const opn = require('opn');
const destroyer = require('server-destroy');
const fs = require('fs');
Expand Down Expand Up @@ -54,12 +53,12 @@ class SampleClient {
throw new Error(invalidRedirectUri);
}
const redirectUri = keys.redirect_uris[keys.redirect_uris.length - 1];
const parts = url.parse(redirectUri, false);
const parts = new url.URL(redirectUri);
if (
redirectUri.length === 0 ||
parts.port !== '3000' ||
parts.hostname !== 'localhost' ||
parts.path !== '/oauth2callback'
parts.pathname !== '/oauth2callback'
) {
throw new Error(invalidRedirectUri);
}
Expand All @@ -86,12 +85,12 @@ class SampleClient {
.createServer(async (req, res) => {
try {
if (req.url.indexOf('/oauth2callback') > -1) {
const qs = querystring.parse(url.parse(req.url).query);
const qs = new url.URL(req.url).searchParams;
res.end(
'Authentication successful! Please return to the console.'
);
server.destroy();
const {tokens} = await this.oAuth2Client.getToken(qs.code);
const {tokens} = await this.oAuth2Client.getToken(qs.get('code'));
this.oAuth2Client.credentials = tokens;
resolve(this.oAuth2Client);
}
Expand Down