duojs / duo

A next-generation package manager for the front-end
3.42k stars 118 forks source link

Adding duo-authenticate #491

Closed dominicbarnes closed 8 years ago

dominicbarnes commented 9 years ago

This adds a new bin to duo which is expressly dedicated to setting up a ~/.netrc file for new users:


  Usage: duo-authenticate [options]

  Automatically add a github personal access token to your ~/.netrc file

  Options:

    -h, --help                 output usage information
    -f, --force                create a new token even if there already is one
    -t, --token <token>        use a previously-generated github access token
    -u, --username <username>  github username (used to generate a token)
    -p, --password <password>  github password (used to generate a token)
    -c, --code <code>          github two-factor authentication code (if needed)

Some sample uses:

# take a token you've generated already and add it to your `.netrc`
$ duo-authenticate --token <token>

# if there already is a token, it gives an error, unless you force
$ duo-authenticate --token <token> --force

# you can also provide your username and password, which will be used with the github API
# to generate a brand new token (using the name "Duo CLI")
$ duo-authenticate --username <user> --password <pass>

# if you use 2FA, you can add your code too (it will fail if you don't)
$ duo-authenticate --username <user> --password <pass> --code <code>

The end-result is that the api.github.com host for your ~/.netrc will be configured: (while not clobbering any other values in the file)

machine api.github.com
  login: x-oauth-basic
  password: <token>

This resolves #37 (and probably others)

dominicbarnes commented 9 years ago

I'm still learning how this /authorizations endpoint works in the Github API, so we may have to tweak the configuration we use. (namely things like scopes)

I'm going to be testing out this new flow pretty soon, to make sure the generated token is actually useful before we merge this PR.

dominicbarnes commented 9 years ago

All right, after researching, it looks like all duo ever needs is the repo scope. (w/o a scope, it only has access to public repos, the former gives it access to private ones as well)

That being said, this PR is ready to go! (pending feedback from @duojs/owners)

matthewmueller commented 9 years ago

nice work dude, looks great :-)