-
Notifications
You must be signed in to change notification settings - Fork 437
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
Conversation
There was a problem hiding this 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'); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove \n.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use (req, res) =>
.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); | ||
} |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove \n
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, () => { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
Fixes #2. |
PTAL |
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.