glogin 0.14.0 → 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/lib/glogin/auth.rb +2 -2
- data/lib/glogin/cookie.rb +34 -25
- data/lib/glogin/version.rb +1 -1
- data/test/glogin/test_cookie.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56ba569dbb60a5e6e480c86cf2b5e103c6bd42d695e57d16bfc9b94a9b819526
|
4
|
+
data.tar.gz: 4cd694c79226b6a7946caf4adac29ea10326f7944f89facb7b578c2ea1bc9034
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37236f4de0ef6c6984c450cf03c0c6a79f51564911d3cf8a35408158d57153bfbda6c966cb0f5aa678e96c4482f89142d189f1d5054efd5b4c10227a01aa75d3
|
7
|
+
data.tar.gz: 0f3a77248cd9c7ec6c925693ee125b8a34b86fd1def5d3f7e4bf45265d4a7ae46bf36b628444ce669e8da164116d57c88af6fb953e803520f6209bb3f066b954
|
data/Gemfile
CHANGED
@@ -24,11 +24,11 @@
|
|
24
24
|
source 'https://rubygems.org'
|
25
25
|
gemspec
|
26
26
|
|
27
|
-
gem 'minitest', '5.
|
27
|
+
gem 'minitest', '5.21.2', require: false
|
28
28
|
gem 'rake', '13.1.0', require: false
|
29
29
|
gem 'rdoc', '6.6.1', require: false
|
30
30
|
gem 'rspec-rails', '6.1.0', require: false
|
31
|
-
gem 'rubocop', '1.60.
|
31
|
+
gem 'rubocop', '1.60.2', require: false
|
32
32
|
gem 'rubocop-rspec', '2.26.1', require: false
|
33
33
|
gem 'simplecov', '0.22.0', require: false
|
34
34
|
gem 'webmock', '3.19.1', require: false
|
data/lib/glogin/auth.rb
CHANGED
@@ -56,9 +56,9 @@ module GLogin
|
|
56
56
|
if @secret.empty?
|
57
57
|
return {
|
58
58
|
'id' => 526_301,
|
59
|
-
'type' => 'User',
|
60
59
|
'login' => 'yegor256',
|
61
|
-
'avatar_url' => 'https://github.com/yegor256.png'
|
60
|
+
'avatar_url' => 'https://github.com/yegor256.png',
|
61
|
+
'bearer' => ''
|
62
62
|
}
|
63
63
|
end
|
64
64
|
raise 'Code can\'t be nil' if code.nil?
|
data/lib/glogin/cookie.rb
CHANGED
@@ -39,19 +39,29 @@ module GLogin
|
|
39
39
|
#
|
40
40
|
class Cookie
|
41
41
|
# Closed cookie.
|
42
|
+
#
|
43
|
+
# An instance of this class is created when a cookie arrives
|
44
|
+
# to the application. The cookie text is provided to the class
|
45
|
+
# as the first parameter. Then, when an instance of the class
|
46
|
+
# is created, the value encypted inside the cookie text may
|
47
|
+
# be retrieved through the +to_user+ method.
|
42
48
|
class Closed
|
43
49
|
def initialize(text, secret, context = '')
|
44
50
|
raise 'Text can\'t be nil' if text.nil?
|
45
51
|
@text = text
|
46
52
|
raise 'Secret can\'t be nil' if secret.nil?
|
47
53
|
@secret = secret
|
54
|
+
raise 'Context can\'t be nil' if context.nil?
|
48
55
|
@context = context.to_s
|
49
56
|
end
|
50
57
|
|
51
|
-
# Returns a hash with
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
58
|
+
# Returns a hash with four elements: `id`, `login`, `avatar`, and `bearer`.
|
59
|
+
#
|
60
|
+
# If the `secret` is empty, the text will not be decrypted, but used
|
61
|
+
# "as is". This may be helpful during testing.
|
62
|
+
#
|
63
|
+
# If the data is not valid, an exception
|
64
|
+
# `GLogin::Codec::DecodingError` will be raised, which you have
|
55
65
|
# to catch in your applicaiton and ignore the login attempt.
|
56
66
|
def to_user
|
57
67
|
plain = Codec.new(@secret).decrypt(@text)
|
@@ -68,38 +78,37 @@ module GLogin
|
|
68
78
|
|
69
79
|
# Open
|
70
80
|
class Open
|
71
|
-
|
81
|
+
attr_reader :id, :login, :avatar_url, :bearer
|
82
|
+
|
83
|
+
# Here comes the JSON you receive from Auth.user().
|
84
|
+
#
|
85
|
+
# The JSON is a Hash where every key is a string. When the class is instantiated,
|
86
|
+
# its methods `id`, `login`, and `avatar_url` may be used to retrieve
|
87
|
+
# the data inside the JSON, but this is not what this class is mainly about.
|
88
|
+
#
|
89
|
+
# The method +to_s+ returns an encrypted cookie string, that may be
|
90
|
+
# sent to the user as a +Set-Cookie+ HTTP header.
|
72
91
|
def initialize(json, secret, context = '')
|
73
92
|
raise 'JSON can\'t be nil' if json.nil?
|
74
|
-
|
93
|
+
raise 'JSON must contain "id" key' if json['id'].nil?
|
94
|
+
@id = json['id']
|
95
|
+
@login = json['login'] || ''
|
96
|
+
@avatar_url = json['avatar_url'] || ''
|
97
|
+
@bearer = json['bearer'] || ''
|
75
98
|
raise 'Secret can\'t be nil' if secret.nil?
|
76
99
|
@secret = secret
|
100
|
+
raise 'Context can\'t be nil' if context.nil?
|
77
101
|
@context = context.to_s
|
78
102
|
end
|
79
103
|
|
80
|
-
# GitHub id of the authenticated user
|
81
|
-
def id
|
82
|
-
@json['id']
|
83
|
-
end
|
84
|
-
|
85
|
-
# GitHub login name of the authenticated user
|
86
|
-
def login
|
87
|
-
@json['login']
|
88
|
-
end
|
89
|
-
|
90
|
-
# GitHub avatar URL of the authenticated user
|
91
|
-
def avatar_url
|
92
|
-
@json['avatar_url']
|
93
|
-
end
|
94
|
-
|
95
104
|
# Returns the text you should drop back to the user as a cookie.
|
96
105
|
def to_s
|
97
106
|
Codec.new(@secret).encrypt(
|
98
107
|
[
|
99
|
-
id,
|
100
|
-
login,
|
101
|
-
avatar_url,
|
102
|
-
@
|
108
|
+
@id,
|
109
|
+
@login,
|
110
|
+
@avatar_url,
|
111
|
+
@bearer,
|
103
112
|
@context
|
104
113
|
].join(GLogin::SPLIT)
|
105
114
|
)
|
data/lib/glogin/version.rb
CHANGED
data/test/glogin/test_cookie.rb
CHANGED
@@ -31,7 +31,7 @@ class TestCookie < Minitest::Test
|
|
31
31
|
GLogin::Cookie::Open.new(
|
32
32
|
JSON.parse(
|
33
33
|
"{\"id\":\"123\",
|
34
|
-
\"login\":\"yegor256\",
|
34
|
+
\"login\":\"yegor256\",\"bearer\":\"\",
|
35
35
|
\"avatar_url\":\"https://avatars1.githubusercontent.com/u/526301\"}"
|
36
36
|
),
|
37
37
|
secret
|
@@ -47,7 +47,7 @@ class TestCookie < Minitest::Test
|
|
47
47
|
context = '127.0.0.1'
|
48
48
|
user = GLogin::Cookie::Closed.new(
|
49
49
|
GLogin::Cookie::Open.new(
|
50
|
-
JSON.parse('{"id":"123","login":"jeffrey","avatar_url":"#"}'),
|
50
|
+
JSON.parse('{"id":"123","login":"jeffrey","avatar_url":"#","bearer":""}'),
|
51
51
|
secret,
|
52
52
|
context
|
53
53
|
).to_s,
|
@@ -81,7 +81,7 @@ class TestCookie < Minitest::Test
|
|
81
81
|
assert_raises GLogin::Codec::DecodingError do
|
82
82
|
GLogin::Cookie::Closed.new(
|
83
83
|
GLogin::Cookie::Open.new(
|
84
|
-
JSON.parse('{"login":"x","avatar_url":"x"}'),
|
84
|
+
JSON.parse('{"login":"x","avatar_url":"x","id":"1","bearer":""}'),
|
85
85
|
'secret-1'
|
86
86
|
).to_s,
|
87
87
|
'secret-2'
|
@@ -94,7 +94,7 @@ class TestCookie < Minitest::Test
|
|
94
94
|
assert_raises GLogin::Codec::DecodingError do
|
95
95
|
GLogin::Cookie::Closed.new(
|
96
96
|
GLogin::Cookie::Open.new(
|
97
|
-
JSON.parse('{"login":"x","avatar_url":"x"}'),
|
97
|
+
JSON.parse('{"login":"x","avatar_url":"x","id":"","bearer":""}'),
|
98
98
|
secret,
|
99
99
|
'context-1'
|
100
100
|
).to_s,
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glogin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.14.
|
4
|
+
version: 0.14.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base58
|