omniauth-twitchtv2 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: edb0c195f852ffc1186501076e8565298175e186b2ef74f4626517096d17d9ab
4
+ data.tar.gz: 57fa18c318d73e4a7f6880712a087a0814f039f88795f63897eac2c113b7c5bf
5
+ SHA512:
6
+ metadata.gz: 32045c9a362321cb4930da29cd5af652a097650fc6850962145702dbdd619982bf75311f5bbc0ae264b2a37048d4cf1669cfd0bfcec9c11b0d8383b6551aab9d
7
+ data.tar.gz: 8d7adc1af4b7ca7033da65fa04bbd0fef8b5c97dcf824ee12b83661337305c63b2ce8df5d8c5bf96aa389a6636f464c86ab88989eb5aad399c9dfd0e4477facf
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Claudio Poli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # OmniAuth Twitchtv2 Strategy
2
+
3
+ [![Test](https://github.com/icoretech/omniauth-twitchtv2/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/icoretech/omniauth-twitchtv2/actions/workflows/test.yml?query=branch%3Amain)
4
+ [![Gem Version](https://img.shields.io/gem/v/omniauth-twitchtv2.svg)](https://rubygems.org/gems/omniauth-twitchtv2)
5
+
6
+ `omniauth-twitchtv2` provides a Twitch OAuth2 strategy for OmniAuth.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'omniauth-twitchtv2'
14
+ ```
15
+
16
+ Then run:
17
+
18
+ ```bash
19
+ bundle install
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Configure OmniAuth in your Rack/Rails app:
25
+
26
+ ```ruby
27
+ Rails.application.config.middleware.use OmniAuth::Builder do
28
+ provider :twitchtv,
29
+ ENV.fetch('TWITCH_CLIENT_ID'),
30
+ ENV.fetch('TWITCH_CLIENT_SECRET'),
31
+ scope: 'user:read:email'
32
+ end
33
+ ```
34
+
35
+ ## Auth Hash
36
+
37
+ Example payload from `request.env['omniauth.auth']` (realistic shape, anonymized):
38
+
39
+ ```json
40
+ {
41
+ "uid": "12345678",
42
+ "info": {
43
+ "name": "sample_user",
44
+ "nickname": "sample_user",
45
+ "email": "sample@example.test",
46
+ "image": "https://static-cdn.jtvnw.net/jtv_user_pictures/example-profile_image-300x300.png",
47
+ "description": "Streaming something cool",
48
+ "urls": {
49
+ "twitchtv": "https://www.twitch.tv/sample_user"
50
+ }
51
+ },
52
+ "credentials": {
53
+ "token": "sample-access-token",
54
+ "refresh_token": "sample-refresh-token",
55
+ "expires_at": 1710000000,
56
+ "expires": true
57
+ },
58
+ "extra": {
59
+ "raw_info": {
60
+ "id": "12345678",
61
+ "login": "sample_user",
62
+ "display_name": "sample_user",
63
+ "type": "",
64
+ "broadcaster_type": "",
65
+ "description": "Streaming something cool",
66
+ "profile_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/example-profile_image-300x300.png",
67
+ "offline_image_url": "",
68
+ "view_count": 42,
69
+ "email": "sample@example.test",
70
+ "created_at": "2020-01-01T00:00:00Z"
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ `info.email` is returned only when your app requests a scope that exposes email (for example `user:read:email`).
77
+
78
+ ## Development
79
+
80
+ ```bash
81
+ bundle install
82
+ bundle exec rake
83
+ ```
84
+
85
+ Run Rails integration tests with an explicit Rails version:
86
+
87
+ ```bash
88
+ RAILS_VERSION='~> 8.1.0' bundle install
89
+ RAILS_VERSION='~> 8.1.0' bundle exec rake test_rails_integration
90
+ ```
91
+
92
+ ## Compatibility
93
+
94
+ - Ruby: `>= 3.2` (tested on `3.2`, `3.3`, `3.4`, `4.0`)
95
+ - `omniauth-oauth2`: `>= 1.8`, `< 1.9`
96
+ - Rails integration lanes: `~> 7.1.0`, `~> 7.2.0`, `~> 8.0.0`, `~> 8.1.0`
97
+
98
+ ## Release
99
+
100
+ Tag releases as `vX.Y.Z`; GitHub Actions publishes the gem to RubyGems.
101
+
102
+ ## License
103
+
104
+ MIT
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-oauth2'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ # OmniAuth strategy for Twitch OAuth2.
8
+ class Twitchtv < OmniAuth::Strategies::OAuth2
9
+ option :name, 'twitchtv'
10
+
11
+ option :client_options,
12
+ site: 'https://api.twitch.tv',
13
+ authorize_url: 'https://id.twitch.tv/oauth2/authorize',
14
+ token_url: 'https://id.twitch.tv/oauth2/token',
15
+ auth_scheme: :request_body,
16
+ connection_opts: {
17
+ headers: {
18
+ user_agent: 'icoretech-omniauth-twitchtv2 gem',
19
+ accept: 'application/json',
20
+ content_type: 'application/json'
21
+ }
22
+ }
23
+
24
+ option :authorize_options, %i[scope force_verify]
25
+
26
+ uid { raw_info['id'].to_s }
27
+
28
+ info do
29
+ {
30
+ name: raw_info['display_name'] || raw_info['login'],
31
+ nickname: raw_info['login'],
32
+ email: raw_info['email'],
33
+ image: raw_info['profile_image_url'],
34
+ description: blank_to_nil(raw_info['description']),
35
+ urls: profile_url ? { twitchtv: profile_url } : nil
36
+ }.compact
37
+ end
38
+
39
+ extra do
40
+ {
41
+ 'raw_info' => raw_info
42
+ }
43
+ end
44
+
45
+ def raw_info
46
+ @raw_info ||= begin
47
+ response = access_token.get('helix/users', headers: { 'Client-Id' => options.client_id })
48
+ users = response.parsed.fetch('data', [])
49
+ users.first || {}
50
+ end
51
+ end
52
+
53
+ def profile_url
54
+ login = raw_info['login']
55
+ return nil if login.to_s.empty?
56
+
57
+ "https://www.twitch.tv/#{login}"
58
+ end
59
+
60
+ # Ensure token exchange uses a stable callback URI that matches provider config.
61
+ def callback_url
62
+ options[:callback_url] || super
63
+ end
64
+
65
+ # Prevent authorization response params from being appended to redirect_uri.
66
+ def query_string
67
+ return '' if request.params['code']
68
+
69
+ super
70
+ end
71
+
72
+ private
73
+
74
+ def blank_to_nil(value)
75
+ return nil if value.respond_to?(:empty?) && value.empty?
76
+
77
+ value
78
+ end
79
+ end
80
+
81
+ Twitchtv2 = Twitchtv
82
+ end
83
+ end
84
+
85
+ OmniAuth.config.add_camelization 'twitchtv', 'Twitchtv'
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Twitchtv2
5
+ VERSION = '1.0.1'
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/twitchtv2/version'
4
+ require 'omniauth/strategies/twitchtv'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-twitchtv2/version'
4
+
5
+ module Omniauth
6
+ module Twitchtv
7
+ VERSION = OmniAuth::Twitchtv2::VERSION unless const_defined?(:VERSION)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth-twitchtv2'
4
+
5
+ module Omniauth
6
+ module Twitchtv
7
+ class TwitchtvError < OmniAuth::Error; end unless const_defined?(:TwitchtvError)
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/twitchtv2/version'
4
+
5
+ # Backward compatibility for historical constant usage.
6
+ module Omniauth
7
+ module Twitchtv2
8
+ VERSION = OmniAuth::Twitchtv2::VERSION unless const_defined?(:VERSION)
9
+ end
10
+
11
+ module Twitchtv
12
+ VERSION = OmniAuth::Twitchtv2::VERSION unless const_defined?(:VERSION)
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/twitchtv2'
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'omniauth/twitchtv2/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'omniauth-twitchtv2'
9
+ spec.version = OmniAuth::Twitchtv2::VERSION
10
+ spec.authors = ['Claudio Poli']
11
+ spec.email = ['masterkain@gmail.com']
12
+
13
+ spec.summary = 'OmniAuth strategy for Twitch OAuth2 authentication.'
14
+ spec.description = 'OAuth2 strategy for OmniAuth that authenticates users with Twitch and exposes account metadata.'
15
+ spec.homepage = 'https://github.com/icoretech/omniauth-twitchtv2'
16
+ spec.license = 'MIT'
17
+ spec.required_ruby_version = '>= 3.2'
18
+
19
+ spec.metadata['source_code_uri'] = 'https://github.com/icoretech/omniauth-twitchtv2'
20
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/icoretech/omniauth-twitchtv2/issues'
21
+ spec.metadata['changelog_uri'] = 'https://github.com/icoretech/omniauth-twitchtv2/releases'
22
+ spec.metadata['rubygems_mfa_required'] = 'true'
23
+
24
+ spec.files = Dir[
25
+ 'lib/**/*.rb',
26
+ 'README*',
27
+ 'LICENSE*',
28
+ '*.gemspec'
29
+ ]
30
+ spec.require_paths = ['lib']
31
+
32
+ spec.add_dependency 'cgi', '>= 0.3.6'
33
+ spec.add_dependency 'omniauth-oauth2', '>= 1.8', '< 1.9'
34
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-twitchtv2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Claudio Poli
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: cgi
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 0.3.6
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.3.6
26
+ - !ruby/object:Gem::Dependency
27
+ name: omniauth-oauth2
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '1.8'
33
+ - - "<"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.9'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '1.8'
43
+ - - "<"
44
+ - !ruby/object:Gem::Version
45
+ version: '1.9'
46
+ description: OAuth2 strategy for OmniAuth that authenticates users with Twitch and
47
+ exposes account metadata.
48
+ email:
49
+ - masterkain@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - LICENSE.txt
55
+ - README.md
56
+ - lib/omniauth-twitchtv.rb
57
+ - lib/omniauth-twitchtv/version.rb
58
+ - lib/omniauth-twitchtv2.rb
59
+ - lib/omniauth-twitchtv2/version.rb
60
+ - lib/omniauth/strategies/twitchtv.rb
61
+ - lib/omniauth/twitchtv2.rb
62
+ - lib/omniauth/twitchtv2/version.rb
63
+ - omniauth-twitchtv2.gemspec
64
+ homepage: https://github.com/icoretech/omniauth-twitchtv2
65
+ licenses:
66
+ - MIT
67
+ metadata:
68
+ source_code_uri: https://github.com/icoretech/omniauth-twitchtv2
69
+ bug_tracker_uri: https://github.com/icoretech/omniauth-twitchtv2/issues
70
+ changelog_uri: https://github.com/icoretech/omniauth-twitchtv2/releases
71
+ rubygems_mfa_required: 'true'
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '3.2'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.6.9
87
+ specification_version: 4
88
+ summary: OmniAuth strategy for Twitch OAuth2 authentication.
89
+ test_files: []