glogin 0.4.6 → 0.7.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 +5 -5
- data/.rubocop.yml +5 -1
- data/.rultor.yml +5 -13
- data/.simplecov +1 -1
- data/.travis.yml +2 -2
- data/Gemfile +4 -1
- data/LICENSE.txt +1 -1
- data/README.md +20 -27
- data/Rakefile +4 -2
- data/glogin.gemspec +13 -10
- data/lib/glogin.rb +4 -2
- data/lib/glogin/auth.rb +4 -2
- data/lib/glogin/codec.rb +46 -39
- data/lib/glogin/cookie.rb +27 -9
- data/lib/glogin/version.rb +5 -3
- data/logo.svg +19 -0
- data/test/glogin/test_auth.rb +3 -3
- data/test/glogin/test_codec.rb +13 -4
- data/test/glogin/test_cookie.rb +14 -8
- data/test/test__helper.rb +3 -1
- data/test/test_glogin.rb +4 -2
- metadata +51 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 23aa113e0458f6235f3a45c8e597f5305e1d692420a664fbe085c4ee0d55a6e3
|
4
|
+
data.tar.gz: 8d17e85d15c4bb738e56257a7ee483735667f83e22f5872b6b3003ee82b5e73f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4e44314580dcac9fc29be86b76c36285dd6d8dccf47b7d7d272d8d5873ef17400da51b32008c11506bae68a64f3e947094344556ff9e4f3edb948511cb2fb3f
|
7
|
+
data.tar.gz: d51ffeff0418ea61c3dbc5529dd5cc7752e472dae6136ea0f65e965ac869a937cac74a63959d652020703f410e8d32c3fa21db8416a8f4903786b0333ef8c8f9
|
data/.rubocop.yml
CHANGED
@@ -3,10 +3,12 @@ AllCops:
|
|
3
3
|
- 'bin/**/*'
|
4
4
|
- 'assets/**/*'
|
5
5
|
DisplayCopNames: true
|
6
|
-
TargetRubyVersion: 2.
|
6
|
+
TargetRubyVersion: 2.3
|
7
7
|
|
8
8
|
Metrics/MethodLength:
|
9
9
|
Enabled: false
|
10
|
+
Style/ClassAndModuleChildren:
|
11
|
+
Enabled: false
|
10
12
|
Layout/MultilineMethodCallIndentation:
|
11
13
|
Enabled: false
|
12
14
|
Metrics/AbcSize:
|
@@ -17,3 +19,5 @@ Metrics/CyclomaticComplexity:
|
|
17
19
|
Max: 10
|
18
20
|
Metrics/PerceivedComplexity:
|
19
21
|
Max: 10
|
22
|
+
Layout/EmptyLineAfterGuardClause:
|
23
|
+
Enabled: false
|
data/.rultor.yml
CHANGED
@@ -1,13 +1,11 @@
|
|
1
1
|
assets:
|
2
|
-
rubygems.yml:
|
3
|
-
s3cfg: zerocracy/home#assets/s3cfg
|
2
|
+
rubygems.yml: yegor256/home#assets/rubygems.yml
|
4
3
|
install: |
|
5
|
-
|
6
|
-
sudo
|
4
|
+
pdd -f /dev/null
|
5
|
+
sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
|
7
6
|
release:
|
8
7
|
script: |-
|
9
|
-
bundle
|
10
|
-
rake
|
8
|
+
bundle exec rake
|
11
9
|
rm -rf *.gem
|
12
10
|
sed -i "s/1\.0\.snapshot/${tag}/g" lib/glogin/version.rb
|
13
11
|
git add lib/glogin/version.rb
|
@@ -15,15 +13,9 @@ release:
|
|
15
13
|
gem build glogin.gemspec
|
16
14
|
chmod 0600 ../rubygems.yml
|
17
15
|
gem push *.gem --config-file ../rubygems.yml
|
18
|
-
commanders:
|
19
|
-
- yegor256
|
20
|
-
architect:
|
21
|
-
- yegor256
|
22
16
|
merge:
|
23
17
|
script: |-
|
24
|
-
bundle
|
25
|
-
rake
|
26
|
-
pdd
|
18
|
+
bundle exec rake
|
27
19
|
deploy:
|
28
20
|
script: |-
|
29
21
|
echo "There is nothing to deploy"
|
data/.simplecov
CHANGED
data/.travis.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
3
|
+
- 2.6.0
|
4
4
|
cache: bundler
|
5
5
|
branches:
|
6
6
|
only:
|
@@ -8,6 +8,6 @@ branches:
|
|
8
8
|
install:
|
9
9
|
- travis_retry bundle update
|
10
10
|
script:
|
11
|
-
- rake
|
11
|
+
- bundle exec rake
|
12
12
|
after_success:
|
13
13
|
- "bash <(curl -s https://codecov.io/bash)"
|
data/Gemfile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -20,4 +22,5 @@
|
|
20
22
|
# SOFTWARE.
|
21
23
|
|
22
24
|
source 'https://rubygems.org'
|
25
|
+
ruby '~>2.3'
|
23
26
|
gemspec
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,18 @@
|
|
1
|
+
<img src="/logo.svg" width="64px" height="64px"/>
|
2
|
+
|
1
3
|
[](https://www.0crat.com/p/C3RFVLU72)
|
2
4
|
[](http://www.rultor.com/p/yegor256/glogin)
|
3
|
-
[](https://www.jetbrains.com/ruby/)
|
4
6
|
|
5
7
|
[](https://travis-ci.org/yegor256/glogin)
|
6
8
|
[](http://www.0pdd.com/p?name=yegor256/glogin)
|
7
9
|
[](http://badge.fury.io/rb/glogin)
|
8
10
|
[](https://codeclimate.com/github/yegor256/glogin/maintainability)
|
9
11
|
[](https://codecov.io/github/yegor256/glogin?branch=master)
|
12
|
+
[](http://rubydoc.info/github/yegor256/glogin/master/frames)
|
10
13
|
|
11
|
-
|
14
|
+
[](https://hitsofcode.com/view/github/yegor256/glogin)
|
15
|
+
[](https://github.com/yegor256/glogin/blob/master/LICENSE.txt)
|
12
16
|
|
13
17
|
This simple gem will help you enable login/logout through
|
14
18
|
[GitHub OAuth](https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/)
|
@@ -16,6 +20,9 @@ for your web application. This is how it works with
|
|
16
20
|
[Sinatra](http://www.sinatrarb.com/),
|
17
21
|
but you can do something similar in any framework.
|
18
22
|
|
23
|
+
Read this blog post to get the idea:
|
24
|
+
[_Simplified GitHub Login for a Ruby Web App_](https://www.yegor256.com/2018/06/19/glogin.html)
|
25
|
+
|
19
26
|
First, somewhere in the global space, before the app starts:
|
20
27
|
|
21
28
|
```ruby
|
@@ -46,7 +53,7 @@ before '/*' do
|
|
46
53
|
# encrypt the value in the cookie.
|
47
54
|
secret
|
48
55
|
).to_user
|
49
|
-
rescue
|
56
|
+
rescue GLogin::Codec::DecodingError => _
|
50
57
|
# Nothing happens here, the user is not logged in.
|
51
58
|
cookies.delete(:glogin)
|
52
59
|
end
|
@@ -131,30 +138,16 @@ encrypted = codec.encrypt('Hello, world!')
|
|
131
138
|
decrypted = codec.decrypt(encrypted)
|
132
139
|
```
|
133
140
|
|
134
|
-
## How to contribute
|
135
|
-
|
136
|
-
Just submit a pull request. Make sure `rake` passes.
|
137
|
-
|
138
|
-
## License
|
141
|
+
## How to contribute
|
139
142
|
|
140
|
-
|
143
|
+
Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
|
144
|
+
Make sure you build is green before you contribute
|
145
|
+
your pull request. You will need to have [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
|
146
|
+
[Bundler](https://bundler.io/) installed. Then:
|
141
147
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
in the Software without restriction, including without limitation the rights
|
147
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
148
|
-
copies of the Software, and to permit persons to whom the Software is
|
149
|
-
furnished to do so, subject to the following conditions:
|
150
|
-
|
151
|
-
The above copyright notice and this permission notice shall be included in all
|
152
|
-
copies or substantial portions of the Software.
|
148
|
+
```
|
149
|
+
$ bundle update
|
150
|
+
$ bundle exec rake
|
151
|
+
```
|
153
152
|
|
154
|
-
|
155
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
156
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
157
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
158
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
159
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
160
|
-
SOFTWARE.
|
153
|
+
If it's clean and you don't see any error messages, submit your pull request.
|
data/Rakefile
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -61,7 +63,7 @@ RuboCop::RakeTask.new(:rubocop) do |task|
|
|
61
63
|
end
|
62
64
|
|
63
65
|
task :copyright do
|
64
|
-
sh "grep -q -r '
|
66
|
+
sh "grep -q -r '2017-#{Date.today.strftime('%Y')}' \
|
65
67
|
--include '*.rb' \
|
66
68
|
--include '*.txt' \
|
67
69
|
--include 'Rakefile' \
|
data/glogin.gemspec
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -31,7 +33,7 @@ Gem::Specification.new do |s|
|
|
31
33
|
s.required_rubygems_version = Gem::Requirement.new('>= 0')
|
32
34
|
end
|
33
35
|
s.rubygems_version = '2.2'
|
34
|
-
s.required_ruby_version = '~>2.
|
36
|
+
s.required_ruby_version = '~>2.3'
|
35
37
|
s.name = 'glogin'
|
36
38
|
s.version = GLogin::VERSION
|
37
39
|
s.license = 'MIT'
|
@@ -45,12 +47,13 @@ Gem::Specification.new do |s|
|
|
45
47
|
s.test_files = s.files.grep(%r{^(test)/})
|
46
48
|
s.rdoc_options = ['--charset=UTF-8']
|
47
49
|
s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
|
48
|
-
s.
|
49
|
-
s.add_development_dependency '
|
50
|
-
s.add_development_dependency '
|
51
|
-
s.add_development_dependency '
|
52
|
-
s.add_development_dependency '
|
53
|
-
s.add_development_dependency '
|
54
|
-
s.add_development_dependency 'rubocop
|
55
|
-
s.add_development_dependency '
|
50
|
+
s.add_runtime_dependency 'base58', '0.2.3'
|
51
|
+
s.add_development_dependency 'codecov', '0.1.14'
|
52
|
+
s.add_development_dependency 'minitest', '5.11.3'
|
53
|
+
s.add_development_dependency 'rake', '12.3.2'
|
54
|
+
s.add_development_dependency 'rdoc', '4.3.0'
|
55
|
+
s.add_development_dependency 'rspec-rails', '3.8.2'
|
56
|
+
s.add_development_dependency 'rubocop', '0.65.0'
|
57
|
+
s.add_development_dependency 'rubocop-rspec', '1.32.0'
|
58
|
+
s.add_development_dependency 'webmock', '3.5.1'
|
56
59
|
end
|
data/lib/glogin.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -26,7 +28,7 @@ require_relative 'glogin/cookie'
|
|
26
28
|
|
27
29
|
# GLogin main module.
|
28
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2017-
|
31
|
+
# Copyright:: Copyright (c) 2017-2020 Yegor Bugayenko
|
30
32
|
# License:: MIT
|
31
33
|
module GLogin
|
32
34
|
end
|
data/lib/glogin/auth.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -26,7 +28,7 @@ require 'cgi'
|
|
26
28
|
|
27
29
|
# GLogin main module.
|
28
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2017-
|
31
|
+
# Copyright:: Copyright (c) 2017-2020 Yegor Bugayenko
|
30
32
|
# License:: MIT
|
31
33
|
module GLogin
|
32
34
|
#
|
data/lib/glogin/codec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -22,59 +24,64 @@
|
|
22
24
|
require 'securerandom'
|
23
25
|
require 'openssl'
|
24
26
|
require 'digest/sha1'
|
25
|
-
require '
|
27
|
+
require 'base58'
|
26
28
|
|
27
29
|
# Codec.
|
28
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2017-
|
31
|
+
# Copyright:: Copyright (c) 2017-2020 Yegor Bugayenko
|
30
32
|
# License:: MIT
|
31
|
-
|
32
|
-
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
33
|
+
class GLogin::Codec
|
34
|
+
# When can't decode.
|
35
|
+
class DecodingError < StandardError; end
|
36
|
+
|
37
|
+
def initialize(secret = '')
|
38
|
+
raise 'Secret can\'t be nil' if secret.nil?
|
39
|
+
@secret = secret
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
42
|
+
def decrypt(text)
|
43
|
+
raise 'Text can\'t be nil' if text.nil?
|
44
|
+
if @secret.empty?
|
45
|
+
text
|
46
|
+
else
|
47
|
+
cpr = cipher
|
48
|
+
cpr.decrypt
|
49
|
+
cpr.key = digest
|
50
|
+
raise DecodingError unless /^[a-zA-Z0-9]+$/.match?(text)
|
51
|
+
plain = Base58.base58_to_binary(text)
|
52
|
+
raise DecodingError if plain.empty?
|
53
|
+
decrypted = cpr.update(plain)
|
54
|
+
decrypted << cpr.final
|
55
|
+
salt, body = decrypted.to_s.split(' ', 2)
|
56
|
+
raise DecodingError if salt.empty?
|
57
|
+
raise DecodingError if body.nil?
|
58
|
+
body.force_encoding('UTF-8')
|
59
|
+
body
|
59
60
|
end
|
61
|
+
rescue OpenSSL::Cipher::CipherError => e
|
62
|
+
raise DecodingError, e.message
|
63
|
+
end
|
60
64
|
|
61
|
-
|
62
|
-
|
65
|
+
def encrypt(text)
|
66
|
+
raise 'Text can\'t be nil' if text.nil?
|
67
|
+
if @secret.empty?
|
68
|
+
text
|
69
|
+
else
|
63
70
|
cpr = cipher
|
64
71
|
cpr.encrypt
|
65
72
|
cpr.key = digest
|
66
73
|
salt = SecureRandom.base64(Random.rand(8..32))
|
67
74
|
encrypted = cpr.update(salt + ' ' + text)
|
68
75
|
encrypted << cpr.final
|
69
|
-
|
76
|
+
Base58.binary_to_base58(encrypted)
|
70
77
|
end
|
78
|
+
end
|
71
79
|
|
72
|
-
|
73
|
-
|
74
|
-
|
80
|
+
def digest
|
81
|
+
Digest::SHA1.hexdigest(@secret)[0..31]
|
82
|
+
end
|
75
83
|
|
76
|
-
|
77
|
-
|
78
|
-
end
|
84
|
+
def cipher
|
85
|
+
OpenSSL::Cipher.new('aes-256-cbc')
|
79
86
|
end
|
80
87
|
end
|
data/lib/glogin/cookie.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -26,11 +28,11 @@ require_relative 'codec'
|
|
26
28
|
|
27
29
|
# GLogin main module.
|
28
30
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
29
|
-
# Copyright:: Copyright (c) 2017-
|
31
|
+
# Copyright:: Copyright (c) 2017-2020 Yegor Bugayenko
|
30
32
|
# License:: MIT
|
31
33
|
module GLogin
|
32
34
|
# Split symbol inside the cookie text
|
33
|
-
SPLIT = '|'
|
35
|
+
SPLIT = '|'
|
34
36
|
|
35
37
|
#
|
36
38
|
# Secure cookie
|
@@ -49,18 +51,18 @@ module GLogin
|
|
49
51
|
# Returns a hash with two elements: login and avatar.
|
50
52
|
# If the secret is empty, the text will be returned, without
|
51
53
|
# any decryption. If the data is not valid, an exception
|
52
|
-
#
|
54
|
+
# GLogin::Codec::DecodingError will be raised, which you have
|
53
55
|
# to catch in your applicaiton and ignore the login attempt.
|
54
56
|
def to_user
|
55
57
|
plain = Codec.new(@secret).decrypt(@text)
|
56
|
-
login, avatar, bearer, ctx = plain.split(GLogin::SPLIT,
|
58
|
+
id, login, avatar, bearer, ctx = plain.split(GLogin::SPLIT, 5)
|
57
59
|
if !@secret.empty? && ctx.to_s != @context
|
58
60
|
raise(
|
59
|
-
|
61
|
+
GLogin::Codec::DecodingError,
|
60
62
|
"Context '#{@context}' expected, but '#{ctx}' found"
|
61
63
|
)
|
62
64
|
end
|
63
|
-
{ login: login, avatar: avatar, bearer: bearer }
|
65
|
+
{ id: id, login: login, avatar: avatar, bearer: bearer }
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
@@ -75,12 +77,28 @@ module GLogin
|
|
75
77
|
@context = context.to_s
|
76
78
|
end
|
77
79
|
|
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
|
+
|
78
95
|
# Returns the text you should drop back to the user as a cookie.
|
79
96
|
def to_s
|
80
97
|
Codec.new(@secret).encrypt(
|
81
98
|
[
|
82
|
-
|
83
|
-
|
99
|
+
id,
|
100
|
+
login,
|
101
|
+
avatar_url,
|
84
102
|
@json['bearer'],
|
85
103
|
@context
|
86
104
|
].join(GLogin::SPLIT)
|
data/lib/glogin/version.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -21,8 +23,8 @@
|
|
21
23
|
|
22
24
|
# GLogin main module.
|
23
25
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
24
|
-
# Copyright:: Copyright (c) 2017-
|
26
|
+
# Copyright:: Copyright (c) 2017-2020 Yegor Bugayenko
|
25
27
|
# License:: MIT
|
26
28
|
module GLogin
|
27
|
-
VERSION = '0.
|
29
|
+
VERSION = '0.7.0'
|
28
30
|
end
|
data/logo.svg
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<svg width="314px" height="314px" viewBox="0 0 314 314" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
3
|
+
<!-- Generator: Sketch 43.2 (39069) - http://www.bohemiancoding.com/sketch -->
|
4
|
+
<title>Group 2</title>
|
5
|
+
<desc>Created with Sketch.</desc>
|
6
|
+
<defs></defs>
|
7
|
+
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
|
8
|
+
<g id="Group-2">
|
9
|
+
<g id="Group">
|
10
|
+
<circle id="Oval" fill="#053C5E" cx="157" cy="157" r="157"></circle>
|
11
|
+
<rect id="Rectangle" fill="#2B2B2B" x="0" y="234" width="233" height="68"></rect>
|
12
|
+
<text id="glogin" font-family="CourierNewPS-BoldMT, Courier New" font-size="50" font-weight="bold" fill="#FFFFFF">
|
13
|
+
<tspan x="28" y="282">glogin</tspan>
|
14
|
+
</text>
|
15
|
+
<path d="M135.676765,111.215287 C135.211714,113.540467 132.770932,120.688823 130.252813,127.100603 C127.734621,133.512383 125.2898,140.431445 124.819828,142.476214 C123.6868,147.405663 121.517836,147.185477 119.69487,141.95608 C116.899865,133.938362 105.171362,111.043501 103.859129,111.043501 C100.420089,111.043501 101.508757,114.986149 109.1771,130.30227 C113.739327,139.414532 118.032086,147.448041 118.716515,148.15443 C120.694817,150.196115 120.172626,154.319657 117.358599,158.877992 C113.567467,165.019055 107.570942,183.721189 108.054206,187.896804 C108.804956,194.383204 112.436054,192.210274 113.355359,184.724515 C114.48376,175.535577 120.945556,159.641154 124.897459,156.333653 C127.109021,154.482778 128.268636,151.905536 128.573284,148.163978 C128.818001,145.157747 131.906711,135.560972 135.437115,126.837819 C138.96752,118.114666 141.511492,110.079835 141.090434,108.982574 C139.755727,105.504315 136.554941,106.824333 135.676765,111.215287 M174.714659,126.841564 C169.37392,129.699438 169.197653,130.049915 167.452978,141.283475 C165.577352,153.360398 165.225112,168.513913 166.548289,180.203784 L167.566817,189.202501 L161.346213,191.9541 C154.601949,194.937416 150.91195,200.302465 153.156708,203.861146 C155.104824,206.949562 157.09025,206.70198 157.571826,203.310532 C158.083734,199.706169 166.097413,193.204052 170.29418,192.987978 C172.116999,192.894116 173.522874,191.717021 173.97823,189.903529 C174.383277,188.290613 177.740353,184.944554 181.438431,182.467858 C188.546172,177.707551 194.317883,170.450278 194.317883,166.273341 C194.317883,162.684548 189.493165,158.361603 185.487795,158.361603 C180.701636,158.361603 180.027195,155.239403 183.731222,150.229385 C188.308065,144.038966 188.284856,130.867646 183.690534,127.147387 C179.896537,124.075276 179.885006,124.074836 174.714659,126.841564 M182.67318,134.240439 C184.752542,140.153164 174.808961,161.185104 171.588639,157.68562 C169.868715,155.81653 172.863122,135.012708 175.266374,132.134564 C177.872553,129.013319 181.163896,129.949075 182.67318,134.240439 M184.854262,162.269586 C190.589839,163.855621 189.673839,167.881335 181.645765,176.371155 C177.281618,180.986262 173.904933,183.573859 173.371946,182.711474 C172.876636,181.91012 172.127869,176.711937 171.707987,171.159972 L170.944531,161.065463 L176.209475,161.200234 C179.105172,161.274339 182.995308,161.755548 184.854262,162.269586 M132.642184,172.492256 C131.593837,175.224098 133.152917,177.288844 136.264027,177.288844 C139.014965,177.288844 139.431396,176.221769 138.067531,172.667568 C137.039234,169.987871 133.645289,169.878218 132.642184,172.492256 M203.781503,185.840798 C203.781503,187.657595 209.264724,193.512152 210.966361,193.512152 C212.534035,193.512152 211.991059,187.391138 210.270768,185.670847 C208.092403,183.492409 203.781503,183.605293 203.781503,185.840798" id="Fill-6" fill="#427B8A" fill-rule="nonzero"></path>
|
16
|
+
</g>
|
17
|
+
</g>
|
18
|
+
</g>
|
19
|
+
</svg>
|
data/test/glogin/test_auth.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -27,13 +29,11 @@ class TestAuth < Minitest::Test
|
|
27
29
|
def test_authenticate_via_https
|
28
30
|
auth = GLogin::Auth.new('1234', '4433', 'https://example.org')
|
29
31
|
stub_request(:post, 'https://github.com/login/oauth/access_token').to_return(
|
30
|
-
status: 200,
|
31
32
|
body: {
|
32
33
|
access_token: 'some-token'
|
33
34
|
}.to_json
|
34
35
|
)
|
35
36
|
stub_request(:get, 'https://api.github.com/user').to_return(
|
36
|
-
status: 200,
|
37
37
|
body: {
|
38
38
|
auth_code: '437849732894732',
|
39
39
|
login: 'yegor256'
|
data/test/glogin/test_codec.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -20,6 +22,7 @@
|
|
20
22
|
# SOFTWARE.
|
21
23
|
|
22
24
|
require 'minitest/autorun'
|
25
|
+
require 'base64'
|
23
26
|
require_relative '../../lib/glogin/codec'
|
24
27
|
|
25
28
|
class TestCodec < Minitest::Test
|
@@ -38,7 +41,7 @@ class TestCodec < Minitest::Test
|
|
38
41
|
end
|
39
42
|
|
40
43
|
def test_decrypts_with_invalid_password
|
41
|
-
assert_raises
|
44
|
+
assert_raises GLogin::Codec::DecodingError do
|
42
45
|
GLogin::Codec.new('the wrong key').decrypt(
|
43
46
|
GLogin::Codec.new('the right key').encrypt('the text')
|
44
47
|
)
|
@@ -47,13 +50,19 @@ class TestCodec < Minitest::Test
|
|
47
50
|
|
48
51
|
def test_encrypts_into_plain_string
|
49
52
|
text = GLogin::Codec.new('6hFGrte5LLmwi').encrypt("K&j\n\n\tuIpwp00{]=")
|
50
|
-
assert(text =~
|
53
|
+
assert(text =~ /^[a-zA-Z0-9]+$/, text)
|
51
54
|
assert(!text.include?("\n"), text)
|
52
55
|
end
|
53
56
|
|
54
57
|
def test_decrypts_broken_text
|
55
|
-
assert_raises
|
58
|
+
assert_raises GLogin::Codec::DecodingError do
|
56
59
|
GLogin::Codec.new('the key').decrypt('этот текст не был зашифрован')
|
57
60
|
end
|
58
61
|
end
|
62
|
+
|
63
|
+
def test_encrypts_and_decrypts_with_empty_key
|
64
|
+
crypt = GLogin::Codec.new
|
65
|
+
text = 'This is the text, дорогой друг!'
|
66
|
+
assert_equal(text, crypt.decrypt(crypt.encrypt(text)))
|
67
|
+
end
|
59
68
|
end
|
data/test/glogin/test_cookie.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -28,7 +30,8 @@ class TestCookie < Minitest::Test
|
|
28
30
|
user = GLogin::Cookie::Closed.new(
|
29
31
|
GLogin::Cookie::Open.new(
|
30
32
|
JSON.parse(
|
31
|
-
"{\"
|
33
|
+
"{\"id\":\"123\",
|
34
|
+
\"login\":\"yegor256\",
|
32
35
|
\"avatar_url\":\"https://avatars1.githubusercontent.com/u/526301\"}"
|
33
36
|
),
|
34
37
|
secret
|
@@ -44,35 +47,38 @@ class TestCookie < Minitest::Test
|
|
44
47
|
context = '127.0.0.1'
|
45
48
|
user = GLogin::Cookie::Closed.new(
|
46
49
|
GLogin::Cookie::Open.new(
|
47
|
-
JSON.parse('{"login":"jeffrey","avatar_url":"#"}'),
|
50
|
+
JSON.parse('{"id":"123","login":"jeffrey","avatar_url":"#"}'),
|
48
51
|
secret,
|
49
52
|
context
|
50
53
|
).to_s,
|
51
54
|
secret,
|
52
55
|
context
|
53
56
|
).to_user
|
57
|
+
assert_equal(user[:id], '123')
|
54
58
|
assert_equal(user[:login], 'jeffrey')
|
55
59
|
assert_equal(user[:avatar], '#')
|
56
60
|
end
|
57
61
|
|
58
62
|
def test_decrypts_in_test_mode
|
59
63
|
user = GLogin::Cookie::Closed.new(
|
60
|
-
'test|http://example.com', ''
|
64
|
+
'123|test|http://example.com', ''
|
61
65
|
).to_user
|
66
|
+
assert_equal(user[:id], '123')
|
62
67
|
assert_equal(user[:login], 'test')
|
63
68
|
assert_equal(user[:avatar], 'http://example.com')
|
64
69
|
end
|
65
70
|
|
66
71
|
def test_decrypts_in_test_mode_with_context
|
67
72
|
user = GLogin::Cookie::Closed.new(
|
68
|
-
'
|
73
|
+
'123', '', 'some context'
|
69
74
|
).to_user
|
70
|
-
assert_equal('
|
75
|
+
assert_equal('123', user[:id])
|
76
|
+
assert_nil(user[:login])
|
71
77
|
assert_nil(user[:avatar])
|
72
78
|
end
|
73
79
|
|
74
80
|
def test_fails_on_broken_text
|
75
|
-
assert_raises
|
81
|
+
assert_raises GLogin::Codec::DecodingError do
|
76
82
|
GLogin::Cookie::Closed.new(
|
77
83
|
GLogin::Cookie::Open.new(
|
78
84
|
JSON.parse('{"login":"x","avatar_url":"x"}'),
|
@@ -85,7 +91,7 @@ class TestCookie < Minitest::Test
|
|
85
91
|
|
86
92
|
def test_fails_on_wrong_context
|
87
93
|
secret = 'fdjruewoijs789fdsufds89f7ds89fs'
|
88
|
-
assert_raises
|
94
|
+
assert_raises GLogin::Codec::DecodingError do
|
89
95
|
GLogin::Cookie::Closed.new(
|
90
96
|
GLogin::Cookie::Open.new(
|
91
97
|
JSON.parse('{"login":"x","avatar_url":"x"}'),
|
data/test/test__helper.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
data/test/test_glogin.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
|
-
# Copyright (c) 2017-
|
4
|
+
# Copyright (c) 2017-2020 Yegor Bugayenko
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
7
|
# of this software and associated documentation files (the 'Software'), to deal
|
@@ -24,7 +26,7 @@ require_relative '../lib/glogin'
|
|
24
26
|
|
25
27
|
# GLogin main module test.
|
26
28
|
# Author:: Yegor Bugayenko (yegor256@gmail.com)
|
27
|
-
# Copyright:: Copyright (c) 2017-
|
29
|
+
# Copyright:: Copyright (c) 2017-2020 Yegor Bugayenko
|
28
30
|
# License:: MIT
|
29
31
|
class TestGLogin < Minitest::Test
|
30
32
|
def test_basic
|
metadata
CHANGED
@@ -1,127 +1,141 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glogin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yegor Bugayenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: base58
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.3
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: codecov
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- -
|
31
|
+
- - '='
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
33
|
+
version: 0.1.14
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- -
|
38
|
+
- - '='
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
40
|
+
version: 0.1.14
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: minitest
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - '='
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 5.11.3
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - '='
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 5.11.3
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - '='
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 12.3.2
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- -
|
66
|
+
- - '='
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 12.3.2
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: rdoc
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- -
|
73
|
+
- - '='
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
75
|
+
version: 4.3.0
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- -
|
80
|
+
- - '='
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
82
|
+
version: 4.3.0
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec-rails
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- -
|
87
|
+
- - '='
|
74
88
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
89
|
+
version: 3.8.2
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- -
|
94
|
+
- - '='
|
81
95
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
96
|
+
version: 3.8.2
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rubocop
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
|
-
- -
|
101
|
+
- - '='
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: 0.65.0
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
|
-
- -
|
108
|
+
- - '='
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
110
|
+
version: 0.65.0
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: rubocop-rspec
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
100
114
|
requirements:
|
101
|
-
- -
|
115
|
+
- - '='
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
117
|
+
version: 1.32.0
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- -
|
122
|
+
- - '='
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
124
|
+
version: 1.32.0
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: webmock
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
|
-
- -
|
129
|
+
- - '='
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
131
|
+
version: 3.5.1
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
|
-
- -
|
136
|
+
- - '='
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
138
|
+
version: 3.5.1
|
125
139
|
description: Enables login/logout functionality for a Ruby web app
|
126
140
|
email: yegor256@gmail.com
|
127
141
|
executables: []
|
@@ -148,6 +162,7 @@ files:
|
|
148
162
|
- lib/glogin/codec.rb
|
149
163
|
- lib/glogin/cookie.rb
|
150
164
|
- lib/glogin/version.rb
|
165
|
+
- logo.svg
|
151
166
|
- test/glogin/test_auth.rb
|
152
167
|
- test/glogin/test_codec.rb
|
153
168
|
- test/glogin/test_cookie.rb
|
@@ -166,15 +181,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
166
181
|
requirements:
|
167
182
|
- - "~>"
|
168
183
|
- !ruby/object:Gem::Version
|
169
|
-
version: '2.
|
184
|
+
version: '2.3'
|
170
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
186
|
requirements:
|
172
187
|
- - ">="
|
173
188
|
- !ruby/object:Gem::Version
|
174
189
|
version: '0'
|
175
190
|
requirements: []
|
176
|
-
|
177
|
-
rubygems_version: 2.6.8
|
191
|
+
rubygems_version: 3.0.1
|
178
192
|
signing_key:
|
179
193
|
specification_version: 2
|
180
194
|
summary: Login/logout via GitHub OAuth for your web app
|