twitter_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/README.md +47 -6
- data/VERSION +1 -1
- data/lib/twitter_oauth2/client.rb +7 -7
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3fd74a639d0b5217a59d0d8f1dd573f57458fac49ca9ec80eb41e061d061c0e
|
4
|
+
data.tar.gz: a688d0dc6bb2d8bf702d95149bfa5f184825de78cde6e9d2fa1c287343d529c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b29998b2bf147f510b8e82cdfa576d7f262da34f9717229cd8495bba0d473542a5275a86b1d30f7a2c6bbd4b4142fb8823c3030428e4273b636b3835f1acd251
|
7
|
+
data.tar.gz: 2433d26ad4187321ba4af6c0b3f8b059a95b3ffb616fcacd8becc7fa8dc2fab672c6628937eec7bc68a11f43181e3387ec6d24ee6ef55bcc7cfeb857497d5346
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# TwitterOAuth2
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Twitter OAuth2 Client Library in Ruby.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,50 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
This gem is built on `rack/oauth2` gem.
|
24
|
+
Basically, the usage is same with [the underling gem](https://github.com/nov/rack-oauth2/wiki).
|
25
|
+
|
26
|
+
The only difference is that this gem is supporting PKCE as default, since [Twitter **requires** it](https://developer.twitter.com/en/docs/twitter-api/oauth2).
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'twitter_oauth2'
|
30
|
+
|
31
|
+
client = TwitterOAuth2::Client.new(
|
32
|
+
identifier: '<YOUR-CLIENT-ID>',
|
33
|
+
redirect_uri: '<YOUR-CALLBACK-URL>'
|
34
|
+
)
|
35
|
+
|
36
|
+
authorization_uri = client.authorization_uri(
|
37
|
+
scope: [
|
38
|
+
:'users.read',
|
39
|
+
:'tweet.read',
|
40
|
+
:'offline.access'
|
41
|
+
],
|
42
|
+
state: SecureRandom.hex(16)
|
43
|
+
)
|
44
|
+
|
45
|
+
# NOTE:
|
46
|
+
# When 'TwitterOAuth2::Client#authorization_uri is called,
|
47
|
+
# PKCE `code_verifier` is automatically generated.
|
48
|
+
# You can get it here.
|
49
|
+
code_verifier = client.code_verifier
|
50
|
+
|
51
|
+
puts authorization_uri
|
52
|
+
`open "#{authorization_uri}"`
|
53
|
+
|
54
|
+
print 'code: ' and STDOUT.flush
|
55
|
+
code = gets.chop
|
56
|
+
|
57
|
+
# NOTE: Obtaining Access Token & Refresh Token using Authorization Code
|
58
|
+
client.authorization_code = code
|
59
|
+
token_response = client.access_token! code_verifier
|
60
|
+
|
61
|
+
# NOTE: Refreshing Access Token using Refresh Token
|
62
|
+
client.refresh_token = token_response.refresh_token
|
63
|
+
client.access_token!
|
64
|
+
```
|
65
|
+
|
66
|
+
For more usage, read [the underling gem's wiki](https://github.com/nov/rack-oauth2/wiki).
|
26
67
|
|
27
68
|
## Development
|
28
69
|
|
@@ -40,4 +81,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
81
|
|
41
82
|
## Code of Conduct
|
42
83
|
|
43
|
-
Everyone interacting in the
|
84
|
+
Everyone interacting in the TwitterOAuth2 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/twitter_oauth2/blob/master/CODE_OF_CONDUCT.md).
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -1,5 +1,7 @@
|
|
1
1
|
module TwitterOAuth2
|
2
2
|
class Client < Rack::OAuth2::Client
|
3
|
+
attr_accessor :code_verifier
|
4
|
+
|
3
5
|
def initialize(attributes)
|
4
6
|
attributes_with_default = {
|
5
7
|
authorization_endpoint: 'https://twitter.com/i/oauth2/authorize',
|
@@ -9,33 +11,31 @@ module TwitterOAuth2
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def authorization_uri(params = {})
|
12
|
-
code_challenge
|
14
|
+
code_challenge = pkce_session!
|
13
15
|
authorization_uri = super({
|
14
16
|
code_challenge: code_challenge,
|
15
17
|
code_challenge_method: :s256
|
16
18
|
}.merge(params))
|
17
|
-
[authorization_uri, code_verifier]
|
18
19
|
end
|
19
20
|
|
20
21
|
def access_token!(*args)
|
21
22
|
options = args.extract_options!
|
22
23
|
super :body, {
|
23
|
-
code_verifier: args.first
|
24
|
+
code_verifier: args.first || self.code_verifier
|
24
25
|
}.merge(options)
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
|
-
def
|
30
|
-
code_verifier = Base64.urlsafe_encode64(
|
30
|
+
def pkce_session!
|
31
|
+
self.code_verifier = Base64.urlsafe_encode64(
|
31
32
|
SecureRandom.random_bytes(32),
|
32
33
|
padding: false
|
33
34
|
)
|
34
|
-
|
35
|
+
Base64.urlsafe_encode64(
|
35
36
|
OpenSSL::Digest::SHA256.digest(code_verifier),
|
36
37
|
padding: false
|
37
38
|
)
|
38
|
-
[code_challenge, code_verifier]
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_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
|
- nov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack-oauth2
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
version: '0'
|
150
150
|
requirements: []
|
151
|
-
rubygems_version: 3.
|
151
|
+
rubygems_version: 3.0.3
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: Twitter OAuth 2.0 Client
|