twitch_oauth2 0.2.0 → 0.3.0
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +10 -2
- data/lib/twitch_oauth2/client.rb +17 -29
- data/lib/twitch_oauth2/error.rb +8 -0
- data/lib/twitch_oauth2/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d1f094b1681b2963cb183234ade2f76b29b32b719c9fd35a591ceede9574238
|
4
|
+
data.tar.gz: a29358eda7e23e9bcfeeff0dd8c0398e59cd7343045fba050609daf18d47934f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e0786a7b94aad31eff0f7dcc9c0c4600c0dcb229592864b9d74cc73482ca984179194eeb3fc29218df16f1d17133e13289064f6ea4e273e4615ceacdb59d64d
|
7
|
+
data.tar.gz: e37c722c4afbe51870734fac69e9af8e133ee9fd7dea600c2297b3e20b3be72f4b6a67ac64ceff20a8798d68cab841f8d44a1b212de7bef1fd8a33119c7a3dda
|
data/CHANGELOG.md
CHANGED
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
|
75
|
-
|
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
|
|
data/lib/twitch_oauth2/client.rb
CHANGED
@@ -46,26 +46,29 @@ module TwitchOAuth2
|
|
46
46
|
refresh(refresh_token: refresh_token).slice(:access_token, :refresh_token)
|
47
47
|
end
|
48
48
|
|
49
|
-
|
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
|
-
|
52
|
-
code = request_code if token_type == :user
|
59
|
+
return response.body if response.success?
|
53
60
|
|
54
|
-
|
61
|
+
raise Error, response.body[:message]
|
55
62
|
end
|
56
63
|
|
57
|
-
|
58
|
-
link = authorize
|
64
|
+
private
|
59
65
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
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
|
data/lib/twitch_oauth2/error.rb
CHANGED
@@ -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
|
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.
|
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
|
+
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.
|
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.
|
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.
|
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.
|
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
|
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
|
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: '
|
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: '
|
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
|