TwitchOAuth2
Twitch authentication with OAuth 2. Result tokens can be used for API libraries, chat libraries or something else.
Twitch Authentication Documentation
Installation
Add this line to your application's Gemfile:
gem 'twitch_oauth2'
And then execute:
bundle install
Or install it yourself as:
gem install twitch_oauth2
Usage
Initialization
require 'twitch_oauth2'
client = TwitchOAuth2::Client.new(
client_id: 'application_client_id',
client_secret: 'application_client_secret',
scopes: %w[user:read:email bits:read] # default is `nil`
redirect_uri: 'application_redirect_uri' # default is `http://localhost`
)
Check tokens
tokens = previously_saved_tokens
# => { access_token: 'abcdef', refresh_token: 'ghikjl' }
# Can be empty.
client.check_tokens **tokens
The first run
You can pass nothing to #check_tokens
, then client will generate new ones.
You will be asked to open a Twitch link in a browser and login as user
for whom tokens are intended.
Reusing tokens
Then, if you pass tokens, client will validate them and return themselves or refresh and return new ones.
Explicitly refresh tokens
You can refresh tokens manually:
client.refreshed_tokens refresh_token: 'ghikjl'
This is used internally in #check_tokens
, and can be used separately
for failed requests to API.
Development
After checking out the repo, run bundle install
to install dependencies.
Then, run bundle exec rake spec
to run the tests.
We're using VCR cassettes with filtered sensitive data, so you don't need for real credentials (like Twitch Client ID and Client Secret) for changing existing methods, but you need for them to add new requests. You can read how to get them here.
To install this gem onto your local machine, run bundle exec rake install
.
To release a new version, update the version number in version.rb
,
and then run bundle exec rake release
, which will create a git tag
for the version, push git commits and tags, and push the .gem
file
to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub.
License
The gem is available as open source under the terms of the MIT License.