twitch_oauth2 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3dafbbd8897dad15761967a8ff1d9842438948cc88c753955e1d3c121b0fb4f8
4
- data.tar.gz: 1cad9f6de68da7ab3f0052aab03f57dac98122b0e542dae33f75a29d7a379462
3
+ metadata.gz: 2d1f094b1681b2963cb183234ade2f76b29b32b719c9fd35a591ceede9574238
4
+ data.tar.gz: a29358eda7e23e9bcfeeff0dd8c0398e59cd7343045fba050609daf18d47934f
5
5
  SHA512:
6
- metadata.gz: e0736d7951b1ad4c0faa6b8b582fd22966096a8bd7b038996e104c0414ae80903f27653adf8e9b6a71c663c6f795cc138ae544905ff45067b8d9f26fb61f6990
7
- data.tar.gz: 94e1bad7e2b47eaf0d2dce14e73f7a08a1525e0b9bffa788789f66a428a4bbe9e18e71b338dd3de4a7d1cc8db4a792329096ab0f6e691354c47b655821153c2b
6
+ metadata.gz: 8e0786a7b94aad31eff0f7dcc9c0c4600c0dcb229592864b9d74cc73482ca984179194eeb3fc29218df16f1d17133e13289064f6ea4e273e4615ceacdb59d64d
7
+ data.tar.gz: e37c722c4afbe51870734fac69e9af8e133ee9fd7dea600c2297b3e20b3be72f4b6a67ac64ceff20a8798d68cab841f8d44a1b212de7bef1fd8a33119c7a3dda
@@ -2,8 +2,14 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 0.3.0 (2020-12-05)
6
+
5
7
  ## 0.2.0 (2020-11-05)
6
8
 
9
+ * Add an ability to generate Application tokens.
10
+ Useful for the actual, Helix, Twitch API.
11
+ * Update dependencies.
12
+
7
13
  ## 0.1.0 (2020-05-23)
8
14
 
9
15
  * Initial release
data/README.md CHANGED
@@ -71,8 +71,16 @@ You can pass nothing to `#check_tokens`, then client will generate new ones.
71
71
  If you've specified `:token_type` as `:application` or have not specify it at all (default),
72
72
  there will be an Application Access Token (without refresh token).
73
73
 
74
- Otherwise, for User Access Token you will be asked to open a Twitch link in a browser
75
- and login as user for whom tokens are intended.
74
+ Otherwise, for User Access Token here will be raised a `TwitchOAuth2::Error` with Twitch link
75
+ inside `#metadata[:link]`.
76
+
77
+ If you have a web-application with N users, you can redirect them to this link
78
+ and use `redirect_uri` to your application for callbacks.
79
+
80
+ Otherwise, if you have something like CLI tool, you can print instructions with a link for user.
81
+
82
+ Then you can use `#token(token_type: :user, code: 'a code from params in redirect uri')`
83
+ and get your `:access_token` and `:refresh_token`.
76
84
 
77
85
  #### Reusing tokens
78
86
 
@@ -46,26 +46,29 @@ module TwitchOAuth2
46
46
  refresh(refresh_token: refresh_token).slice(:access_token, :refresh_token)
47
47
  end
48
48
 
49
- private
49
+ def token(token_type:, code: nil)
50
+ response = CONNECTION.post(
51
+ 'token',
52
+ client_id: @client_id,
53
+ client_secret: @client_secret,
54
+ code: code,
55
+ grant_type: grant_type_by_token_type(token_type),
56
+ redirect_uri: @redirect_uri
57
+ )
50
58
 
51
- def flow(token_type:)
52
- code = request_code if token_type == :user
59
+ return response.body if response.success?
53
60
 
54
- token(code: code, token_type: token_type).slice(:access_token, :refresh_token)
61
+ raise Error, response.body[:message]
55
62
  end
56
63
 
57
- def request_code
58
- link = authorize
64
+ private
59
65
 
60
- puts <<~TEXT
61
- 1. Open URL in your browser:
62
- #{link}
63
- 2. Login to Twitch.
64
- 3. Copy the `code` parameter from redirected URL.
65
- 4. Insert below:
66
- TEXT
66
+ def flow(token_type:)
67
+ if token_type == :user
68
+ raise Error.new('Use `error.metadata[:link]` for getting new tokens', link: authorize)
69
+ end
67
70
 
68
- $stdin.gets.chomp
71
+ token(token_type: token_type).slice(:access_token, :refresh_token)
69
72
  end
70
73
 
71
74
  def authorize
@@ -83,21 +86,6 @@ module TwitchOAuth2
83
86
  raise Error, response.body[:message]
84
87
  end
85
88
 
86
- def token(code:, token_type:)
87
- response = CONNECTION.post(
88
- 'token',
89
- client_id: @client_id,
90
- client_secret: @client_secret,
91
- code: code,
92
- grant_type: grant_type_by_token_type(token_type),
93
- redirect_uri: @redirect_uri
94
- )
95
-
96
- return response.body if response.success?
97
-
98
- raise Error, response.body[:message]
99
- end
100
-
101
89
  def grant_type_by_token_type(token_type)
102
90
  case token_type
103
91
  when :user then :authorization_code
@@ -1,6 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwitchOAuth2
4
+ ## Error during Twitch OAuth2 operations
4
5
  class Error < StandardError
6
+ attr_reader :metadata
7
+
8
+ def initialize(message, metadata = {})
9
+ super message
10
+
11
+ @metadata = metadata
12
+ end
5
13
  end
6
14
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TwitchOAuth2
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitch_oauth2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-04 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.4.0
75
+ version: 0.5.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.4.0
82
+ version: 0.5.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: toys
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: 0.19.0
131
+ version: 0.20.0
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: 0.19.0
138
+ version: 0.20.0
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: vcr
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.93.1
159
+ version: '1.0'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 0.93.1
166
+ version: '1.0'
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rubocop-performance
169
169
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - "~>"
186
186
  - !ruby/object:Gem::Version
187
- version: '1.44'
187
+ version: '2.0'
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - "~>"
193
193
  - !ruby/object:Gem::Version
194
- version: '1.44'
194
+ version: '2.0'
195
195
  description: |
196
196
  Twitch authentication with OAuth 2.
197
197
  Result tokens can be used for API libraries, chat libraries