{"id":21519335,"url":"https://github.com/alexwayfer/twitch_oauth2","last_synced_at":"2025-04-09T22:09:00.283Z","repository":{"id":38311604,"uuid":"250803099","full_name":"AlexWayfer/twitch_oauth2","owner":"AlexWayfer","description":"Twitch authentication with OAuth 2.","archived":false,"fork":false,"pushed_at":"2025-04-04T14:05:33.000Z","size":197,"stargazers_count":4,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-09T22:08:50.457Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexWayfer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-28T13:33:42.000Z","updated_at":"2025-03-09T06:33:55.000Z","dependencies_parsed_at":"2023-02-13T22:15:57.531Z","dependency_job_id":"ab6cf5f6-a491-4e6d-805f-eb142ff5de19","html_url":"https://github.com/AlexWayfer/twitch_oauth2","commit_stats":{"total_commits":97,"total_committers":2,"mean_commits":48.5,"dds":0.4639175257731959,"last_synced_commit":"99c186ced004c068a1e1fa8e8a28a36451a4cf97"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexWayfer%2Ftwitch_oauth2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexWayfer%2Ftwitch_oauth2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexWayfer%2Ftwitch_oauth2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexWayfer%2Ftwitch_oauth2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexWayfer","download_url":"https://codeload.github.com/AlexWayfer/twitch_oauth2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119294,"owners_count":21050755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-24T00:57:28.264Z","updated_at":"2025-04-09T22:09:00.263Z","avatar_url":"https://github.com/AlexWayfer.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TwitchOAuth2\n\n[![Cirrus CI - Base Branch Build Status](https://img.shields.io/cirrus/github/AlexWayfer/twitch_oauth2?style=flat-square)](https://cirrus-ci.com/github/AlexWayfer/twitch_oauth2)\n[![Codecov branch](https://img.shields.io/codecov/c/github/AlexWayfer/twitch_oauth2/main.svg?style=flat-square)](https://codecov.io/gh/AlexWayfer/twitch_oauth2)\n[![Code Climate](https://img.shields.io/codeclimate/maintainability/AlexWayfer/twitch_oauth2.svg?style=flat-square)](https://codeclimate.com/github/AlexWayfer/twitch_oauth2)\n[![Depfu](https://img.shields.io/depfu/AlexWayfer/twitch_oauth2?style=flat-square)](https://depfu.com/repos/github/AlexWayfer/twitch_oauth2)\n[![Inline docs](https://inch-ci.org/github/AlexWayfer/twitch_oauth2.svg?branch=main)](https://inch-ci.org/github/AlexWayfer/twitch_oauth2)\n[![license](https://img.shields.io/github/license/AlexWayfer/twitch_oauth2.svg?style=flat-square)](https://github.com/AlexWayfer/twitch_oauth2/blob/main/LICENSE.txt)\n[![Gem](https://img.shields.io/gem/v/twitch_oauth2.svg?style=flat-square)](https://rubygems.org/gems/twitch_oauth2)\n\nTwitch authentication with OAuth 2.\nResult tokens can be used for API libraries, chat libraries or something else.\n\n[Twitch Authentication Documentation](https://dev.twitch.tv/docs/authentication)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'twitch_oauth2'\n```\n\nAnd then execute:\n\n```\nbundle install\n```\n\nOr install it yourself as:\n\n```\ngem install twitch_oauth2\n```\n\n## Usage\n\nSince version `0.5.0`, the main object here is `TwitchOAuth2::Tokens` which receives\nand internally uses `client` for necessary requests. This approach allows:\n\n*   get an actual `access_token` with validations, refreshing and other things inside;\n*   share and reuse an instance of this class, for example between API and IRC clients;\n*   initialize 2 instances for user token and application token, but with the same `client` object.\n\n### Initialization\n\nClient, for requests:\n\n```ruby\nrequire 'twitch_oauth2'\n\nclient = TwitchOAuth2::Client.new(\n  client_id: 'application_client_id',\n  client_secret: 'application_client_secret',\n  redirect_uri: 'application_redirect_uri' # default is `http://localhost`\n)\n```\n\nTokens, for their storage and refreshing:\n\n```ruby\ntokens = TwitchOAuth2::Tokens.new(\n  client: client, # initialized above, or can be a `Hash` with values for `Client` initialization\n  # all other arguments are optional\n  access_token: 'somewhere_received_access_token', # default is `nil`\n  refresh_token: 'refresh_token_from_the_same_place', # default is `nil`\n  token_type: :user, # default is `:application`\n  scopes: %w[user:read:email bits:read] # default is `nil`, but it's not so useful\n)\n```\n\n### Check tokens\n\nPlease, use `Tokens#valid?` method after initialization, especially for empty initial tokens,\nespecially for User Access Token.\n\nIf method returned `false` — direct user to `tokens#authorize_link`.\n\nFor a web-application with N users, you can use `:redirect_uri` argument for `Client`\ninitialization as your application callback and redirect them to `#authorize_link`.\n\nFor something like a CLI tool you can print instructions for user with received link.\n\n#### Application Access Token\n\nIt's simpler, has less permissions, and it's the default `:token_type`.\n\nApplication Access Tokens have no `refresh_token` right now and have longer life time,\nso the logic here is simpler: you can pass nothing to `Tokens.new` — the client will generate\nnew `access_token`, and regenerate when it's will be outdated.\n\n#### User Access Token\n\nIf you need for `:user` token and you have no actual `access_token` or `refresh_token`\n(checkable by `Tokens#valid?`), **you have to direct user** to `tokens#authorize_link`.\n\nAfter successful user login there will be redirect from Twitch to the `:redirect_uri`\n(by default is `localhost`) with the `code` query argument.\n**You have to pass it** to the `Tokens#code=` for `access_token` and `refresh_token` generation,\nthey will be available right after it.\n\nIt's one-time manual operation for User Access Token, further the gem will give you actual tokens\nand refresh them as necessary (right now `refresh_token`, getting after `code`, has no life time).\n\nWithout checking tokens the `TwitchOAuth2::AuthorizeError` will be raised on `#access_token` call,\nand it can interrupt some operations, like API library initialization.\n\nThe reference for such behavior is [the official Google API gem](https://github.com/googleapis/google-api-ruby-client/blob/39ae3527722a003b389a2f7f5275ab9c6e93bb5e/samples/cli/lib/base_cli.rb`).\n\nAnother reference, [`twitch` package for JavaScript](https://d-fischer.github.io/twitch/),\nhas refreshing logic, but [requires initial correct tokens from you](https://d-fischer.github.io/twitch-chat-client/docs/examples/basic-bot.html),\nand doesn't care how you'll get them.\n\n\n### Get tokens\n\nThe main method is `Tokens#access_token`: it's used in API libraries, in chat libraries, etc.\n\nIt has refreshing logic inside for cases when it's outdated.\nBut if there is no initial `refresh_token` — be aware and read the documentation below.\n\nThere is also `#refresh_token` getter, just for storing it or something else,\nit's more important internally.\n\n#### Reusing tokens\n\nThen, or if you pass tokens to initialization, client will validate them and return themselves\nor refresh and return new ones.\n\n## Development\n\nAfter checking out the repo, run `bundle install` to install dependencies.\n\nThen, run `toys rspec` to run the tests.\n\nTo install this gem onto your local machine, run `toys gem install`.\n\nTo release a new version, run `toys gem release %version%`.\nSee how it works [here](https://github.com/AlexWayfer/gem_toys#release).\n\n## Contributing\n\nBug reports and pull requests are welcome on [GitHub](https://github.com/AlexWayfer/twitch_oauth2).\n\n## License\n\nThe gem is available as open source under the terms of the\n[MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexwayfer%2Ftwitch_oauth2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexwayfer%2Ftwitch_oauth2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexwayfer%2Ftwitch_oauth2/lists"}