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

Add headless oauth support #28

Merged
merged 6 commits into from
Jan 27, 2018
Merged

Add headless oauth support #28

merged 6 commits into from
Jan 27, 2018

Conversation

sqrrrl
Copy link
Member

@sqrrrl sqrrrl commented Jan 26, 2018

Adds --no-localhost option to login command + refactors auth a little.

Planning a subsequent change to upgrade the client lib & auth library to the recently released version (v25.x for client, v1.x) since the new auth library has support for code_verifier in the oauth flow which will makes things more secure.

Copy link
Contributor

@grant grant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits (snake case, let).
Is port 0 fine?

index.js Outdated
@@ -40,6 +40,9 @@ const recursive = require('recursive-readdir');
const Spinner = require('cli-spinner').Spinner;
const splitLines = require('split-lines');
const url = require('url');
const readline = require('readline');

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove \n.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

index.js Outdated
*/
function authorizeWithLocalhost(opts) {
return new Promise((resolve, reject) => {
var server = http.createServer(function(req, res) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use (req, res) =>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

index.js Outdated
function authorizeWithLocalhost(opts) {
return new Promise((resolve, reject) => {
var server = http.createServer(function(req, res) {
var url_parts = url.parse(req.url, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use urlParts. No snake case. Here and elsewhere.

index.js Outdated
reject(err);
} else {
res(token);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's shorten when possible:

if (err) return reject(err);
return res(token);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

index.js Outdated
* to handle the auth response. False if manual entry used.
*/
function authorize(useLocalhost) {
var opts = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use let instead of var everywhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

index.js Outdated
function authorizeWithoutLocalhost(opts) {
oauth2Client._redirectUri = REDIRECT_URI_OOB;
var authUrl = oauth2Client.generateAuthUrl(opts);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove \n

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

index.js Outdated
}
var authCode = useLocalhost ?
authorizeWithLocalhost(opts) :
authorizeWithoutLocalhost(opts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great ternary!

index.js Outdated
server.shutdown();
}).withShutdown();

server.listen(0, () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listen on port 0? I assume it's not in use. o.w. we'll get ERR_SERVER_ALREADY_LISTEN.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 just means pick an unused ephemeral port. For installed app flows, port is ignored for registered callback localhost URLs, specifically for this reason -- hardcoded ports can cause conflicts if there's already a service running on it.

@grant
Copy link
Contributor

grant commented Jan 26, 2018

Fixes #2.

@sqrrrl
Copy link
Member Author

sqrrrl commented Jan 27, 2018

PTAL

@grant grant merged commit 41794a1 into google:master Jan 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants