Lightweight wrapper to sanely handle OAuth tokens with Octokit
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
spec
.circle-ruby
.gitignore
.prospectus
.rspec
.rubocop.yml
.travis.yml
CHANGELOG.md
Gemfile
LICENSE
README.md
Rakefile
octoauth.gemspec

README.md

octoauth

Gem Version Build Status Coverage Status Code Quality MIT Licensed

Authentication wrapper for GitHub's API

Usage

Get your authentication token quickly and simply:

require 'octoauth'

auth = Octoauth.new note: 'my_cool_app'
puts "My token is #{auth.token}"

This will prompt the user for a username/password and potentially 2FA token using userinput. A note is required, and is what the token will appear as in the user's GitHub tokens list.

If you want to store this token and reuse it, just drop it into a file. The default file is ~/.octoauth.yml. Subsequent runs with the same file and note will load the same token without prompting the user:

auth = Octoauth.new note: 'my_cooler_app', file: :default
puts "My token is #{auth.token}"
auth.save

other_auth = Octoauth.new note: 'other_nice_app', file: '~/.other_app_config.yml'
puts "The other token is #{other_auth.token}"
other_auth.save

Multiple files can be specified, and it will try them in order looking for a valid token. If this fails, it will use the first file listed for any future saving of tokens:

auth = Octoauth.new note: 'my_app', files: ['./.octoauth.yml', '/etc/octoauth', :default]

The above examples get us the basic scope, which means some read-only public access. For other scopes, specify them when creating the token:

auth = Octoauth.new note: 'my_app', scopes: ['gist', 'delete_repo']

If you're trying to use this with a GitHub Enterprise deployment, you can specify an alternate API endpoint:

auth = Octoauth.new note: 'enterprise_app', api_endpoint: 'https://sekrit.codez.com/api/v3/'

If an alternate endpoint is provided, that string is included as part of the saved config, so you can generate a token for GitHub and multiple alternate endpoints with the same note in the same config file.

Installation

gem install octoauth

License

octoauth is released under the MIT License. See the bundled LICENSE file for details.