glogin 0.16.5 → 0.17.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7ee2b3588faa0297950d9a0c6d7b6df1671fd05220fdcda8118480a4a117d46
4
- data.tar.gz: 9deff64ac0bea305d078259160bfeac8aaff6b7ab09a2a8695843122b10a10c9
3
+ metadata.gz: 70ae5615b657f9b0317275a3b7d5fe65eccdbbb1031d2f09d60b37715ebb232e
4
+ data.tar.gz: 8c3867ec9311912f049694be981dfa7141971539e652e0f24c02377d0d3ce8df
5
5
  SHA512:
6
- metadata.gz: 9bd7e92b91df017728c8a35d7aada795206090e69aa0547ab0f7f59e54ba189da7797c827a111c8f64a1274744bfff4a8bbd4d0371f6fa93096ea61925ad9d3f
7
- data.tar.gz: 0c8b5c829294f6ac683c660bd54fbe2a485bffbb76daf70096d4c3772c5c380161e3da9a011a403aa7f3a1348b3d9c3b17fa88149e114f8a276bbdfa8fb208e6
6
+ metadata.gz: 9c631be9cc3d9f1e8ded85802aec693a2ce22fd1a920d049b40c413714ab51a9c327daab6c1404e06242b7df5df47faee8845688e33b387c9d803436a7ef60bd
7
+ data.tar.gz: f43009a609ca1eecfffe0842cfe68f395bcae50549ecab083a05e4933fb1c0e9620498b999e3169ecec637dbe4e908d6afc6303cf515968b549c4103d52c8161
data/Gemfile CHANGED
@@ -1,36 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2025 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
24
6
  source 'https://rubygems.org'
25
7
  gemspec
26
8
 
27
- gem 'minitest', '5.25.2', require: false
28
- gem 'rake', '13.2.1', require: false
29
- gem 'rdoc', '6.11.0', require: false
30
- gem 'rspec-rails', '7.1.0', require: false
31
- gem 'rubocop', '1.71.0', require: false
32
- gem 'rubocop-minitest', '0.36.0', require: false
33
- gem 'rubocop-performance', '1.23.1', require: false
34
- gem 'rubocop-rspec', '3.4.0', require: false
35
- gem 'simplecov', '0.22.0', require: false
36
- gem 'webmock', '3.24.0', require: false
9
+ gem 'minitest', '~>6.0', require: false
10
+ gem 'minitest-reporters', '~>1.7', require: false
11
+ gem 'rake', '~>13.2', require: false
12
+ gem 'rdoc', '~>7.0', require: false
13
+ gem 'rubocop', '~>1.71', require: false
14
+ gem 'rubocop-minitest', '~>0.38', require: false
15
+ gem 'rubocop-performance', '~>1.25', require: false
16
+ gem 'rubocop-rake', '~>0.7', require: false
17
+ gem 'simplecov', '~>0.22', require: false
18
+ gem 'simplecov-cobertura', '~>3.0', require: false
19
+ gem 'webmock', '~>3.24', require: false
20
+ gem 'yard', '~>0.9', require: false
data/Gemfile.lock ADDED
@@ -0,0 +1,125 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ glogin (0.0.0)
5
+ base58 (>= 0.2)
6
+ base64 (>= 0.2)
7
+ openssl (>= 2.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.8.8)
13
+ public_suffix (>= 2.0.2, < 8.0)
14
+ ansi (1.5.0)
15
+ ast (2.4.3)
16
+ base58 (0.2.3)
17
+ base64 (0.3.0)
18
+ bigdecimal (4.0.1)
19
+ builder (3.3.0)
20
+ crack (1.0.1)
21
+ bigdecimal
22
+ rexml
23
+ date (3.5.1)
24
+ docile (1.4.1)
25
+ erb (6.0.1)
26
+ hashdiff (1.2.1)
27
+ json (2.18.0)
28
+ language_server-protocol (3.17.0.5)
29
+ lint_roller (1.1.0)
30
+ minitest (6.0.0)
31
+ prism (~> 1.5)
32
+ minitest-reporters (1.7.1)
33
+ ansi
34
+ builder
35
+ minitest (>= 5.0)
36
+ ruby-progressbar
37
+ openssl (4.0.0)
38
+ parallel (1.27.0)
39
+ parser (3.3.10.0)
40
+ ast (~> 2.4.1)
41
+ racc
42
+ prism (1.7.0)
43
+ psych (5.3.1)
44
+ date
45
+ stringio
46
+ public_suffix (7.0.0)
47
+ racc (1.8.1)
48
+ rainbow (3.1.1)
49
+ rake (13.3.1)
50
+ rdoc (7.0.1)
51
+ erb
52
+ psych (>= 4.0.0)
53
+ tsort
54
+ regexp_parser (2.11.3)
55
+ rexml (3.4.4)
56
+ rubocop (1.82.0)
57
+ json (~> 2.3)
58
+ language_server-protocol (~> 3.17.0.2)
59
+ lint_roller (~> 1.1.0)
60
+ parallel (~> 1.10)
61
+ parser (>= 3.3.0.2)
62
+ rainbow (>= 2.2.2, < 4.0)
63
+ regexp_parser (>= 2.9.3, < 3.0)
64
+ rubocop-ast (>= 1.48.0, < 2.0)
65
+ ruby-progressbar (~> 1.7)
66
+ unicode-display_width (>= 2.4.0, < 4.0)
67
+ rubocop-ast (1.48.0)
68
+ parser (>= 3.3.7.2)
69
+ prism (~> 1.4)
70
+ rubocop-minitest (0.38.2)
71
+ lint_roller (~> 1.1)
72
+ rubocop (>= 1.75.0, < 2.0)
73
+ rubocop-ast (>= 1.38.0, < 2.0)
74
+ rubocop-performance (1.26.1)
75
+ lint_roller (~> 1.1)
76
+ rubocop (>= 1.75.0, < 2.0)
77
+ rubocop-ast (>= 1.47.1, < 2.0)
78
+ rubocop-rake (0.7.1)
79
+ lint_roller (~> 1.1)
80
+ rubocop (>= 1.72.1)
81
+ ruby-progressbar (1.13.0)
82
+ simplecov (0.22.0)
83
+ docile (~> 1.1)
84
+ simplecov-html (~> 0.11)
85
+ simplecov_json_formatter (~> 0.1)
86
+ simplecov-cobertura (3.1.0)
87
+ rexml
88
+ simplecov (~> 0.19)
89
+ simplecov-html (0.13.2)
90
+ simplecov_json_formatter (0.1.4)
91
+ stringio (3.2.0)
92
+ tsort (0.2.0)
93
+ unicode-display_width (3.2.0)
94
+ unicode-emoji (~> 4.1)
95
+ unicode-emoji (4.2.0)
96
+ webmock (3.26.1)
97
+ addressable (>= 2.8.0)
98
+ crack (>= 0.3.2)
99
+ hashdiff (>= 0.4.0, < 2.0.0)
100
+ yard (0.9.38)
101
+
102
+ PLATFORMS
103
+ arm64-darwin-22
104
+ arm64-darwin-23
105
+ arm64-darwin-24
106
+ x64-mingw-ucrt
107
+ x86_64-linux
108
+
109
+ DEPENDENCIES
110
+ glogin!
111
+ minitest (~> 6.0)
112
+ minitest-reporters (~> 1.7)
113
+ rake (~> 13.2)
114
+ rdoc (~> 7.0)
115
+ rubocop (~> 1.71)
116
+ rubocop-minitest (~> 0.38)
117
+ rubocop-performance (~> 1.25)
118
+ rubocop-rake (~> 0.7)
119
+ simplecov (~> 0.22)
120
+ simplecov-cobertura (~> 3.0)
121
+ webmock (~> 3.24)
122
+ yard (~> 0.9)
123
+
124
+ BUNDLED WITH
125
+ 2.5.16
data/LICENSES/MIT.txt ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2017-2025 Yegor Bugayenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,18 +1,18 @@
1
1
  # OAuth Login via GitHub Made Simple
2
2
 
3
- [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/glogin)](http://www.rultor.com/p/yegor256/glogin)
3
+ [![DevOps By Rultor.com](https://www.rultor.com/b/yegor256/glogin)](https://www.rultor.com/p/yegor256/glogin)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
5
5
 
6
6
  [![rake](https://github.com/yegor256/glogin/actions/workflows/rake.yml/badge.svg)](https://github.com/yegor256/glogin/actions/workflows/rake.yml)
7
- [![PDD status](http://www.0pdd.com/svg?name=yegor256/glogin)](http://www.0pdd.com/p?name=yegor256/glogin)
8
- [![Gem Version](https://badge.fury.io/rb/glogin.svg)](http://badge.fury.io/rb/glogin)
7
+ [![PDD status](https://www.0pdd.com/svg?name=yegor256/glogin)](https://www.0pdd.com/p?name=yegor256/glogin)
8
+ [![Gem Version](https://badge.fury.io/rb/glogin.svg)](https://badge.fury.io/rb/glogin)
9
9
  [![Maintainability](https://api.codeclimate.com/v1/badges/155f86b639d155259219/maintainability)](https://codeclimate.com/github/yegor256/glogin/maintainability)
10
10
  [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/glogin.svg)](https://codecov.io/github/yegor256/glogin?branch=master)
11
- [![Yard Docs](http://img.shields.io/badge/yard-docs-blue.svg)](http://rubydoc.info/github/yegor256/glogin/master/frames)
11
+ [![Yard Docs](https://img.shields.io/badge/yard-docs-blue.svg)](https://rubydoc.info/github/yegor256/glogin/master/frames)
12
12
  [![Hits-of-Code](https://hitsofcode.com/github/yegor256/glogin)](https://hitsofcode.com/view/github/yegor256/glogin)
13
13
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/glogin/blob/master/LICENSE.txt)
14
14
 
15
- This simple gem will help you enable login/logout through
15
+ This simple gem helps you enable login/logout through
16
16
  [GitHub OAuth][doc]
17
17
  for your web application. This is how it works with
18
18
  [Sinatra](http://www.sinatrarb.com/),
@@ -27,7 +27,7 @@ First, somewhere in the global space, before the app starts:
27
27
  require 'glogin'
28
28
  configure do
29
29
  set :glogin, GLogin::Auth.new(
30
- # Make sure their values are coming from a secure
30
+ # Make sure these values are coming from a secure
31
31
  # place and are not visible in the source code:
32
32
  client_id, client_secret,
33
33
  # This is what you will register in GitHub as an
@@ -59,14 +59,14 @@ before '/*' do
59
59
  end
60
60
  ```
61
61
 
62
- If the `glogin` cookie is coming in and contains a valid data,
63
- a local variable `@user` will be set to something like this:
62
+ If the `glogin` cookie is coming in and contains valid data,
63
+ a local variable `@user` is set to something like this:
64
64
 
65
65
  ```ruby
66
- { login: 'yegor256', avatar: 'http://...' }
66
+ { 'id' => '526301', 'login' => 'yegor256', 'avatar' => 'http://...' }
67
67
  ```
68
68
 
69
- If the `secret` is an empty string, the encryption will be disabled.
69
+ If the `secret` is an empty string, the encryption is disabled.
70
70
 
71
71
  Next, we need a URL for GitHub OAuth callback:
72
72
 
@@ -94,20 +94,20 @@ It is recommended to provide the third "context" parameter to
94
94
  `GLogin::Cookie::Closed` and `GLogin::Cookie::Open` constructors, in order
95
95
  to enforce stronger security. The context may include the `User-Agent`
96
96
  HTTP header of the user, their IP address, and so on. When anything
97
- changes on the user side, they will be forced to re-login.
97
+ changes on the user side, they are forced to re-login.
98
98
 
99
- One more thing is the login URL you will need for your front page. Here
100
- it is:
99
+ One more thing is the login URL you need for your front page.
100
+ Here it is:
101
101
 
102
102
  ```ruby
103
103
  settings.glogin.login_uri
104
104
  ```
105
105
 
106
- For unit testing you can just provide an empty string as a `secret` for
106
+ For unit testing, you can just provide an empty string as a `secret` for
107
107
  `GLogin::Cookie::Open` and `GLogin::Cookie::Closed`
108
- and the encryption will be disabled:
109
- whatever will be coming from the cookie will be trusted. For testing
110
- it will be convenient to provide a user name in a query string, like:
108
+ and the encryption is disabled: whatever comes from the cookie is trusted.
109
+ For testing it is convenient to provide a user name in a query string,
110
+ like:
111
111
 
112
112
  ```text
113
113
  http://localhost:9292/?glogin=tester
@@ -134,7 +134,7 @@ Also, you can use `GLogin::Codec` just to encrypt/decrypt a piece of text:
134
134
 
135
135
  ```ruby
136
136
  require 'glogin/codec'
137
- codec = GLogin:Codec.new('the secret')
137
+ codec = GLogin::Codec.new('the secret')
138
138
  encrypted = codec.encrypt('Hello, world!')
139
139
  decrypted = codec.decrypt(encrypted)
140
140
  ```
@@ -143,8 +143,8 @@ decrypted = codec.decrypt(encrypted)
143
143
 
144
144
  Read
145
145
  [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
146
- Make sure you build is green before you contribute
147
- your pull request. You will need to have
146
+ Make sure your build is green before you contribute
147
+ your pull request. You need to have
148
148
  [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
149
149
  [Bundler](https://bundler.io/) installed. Then:
150
150
 
data/REUSE.toml ADDED
@@ -0,0 +1,36 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2025 Yegor Bugayenko
2
+ # SPDX-License-Identifier: MIT
3
+
4
+ version = 1
5
+ [[annotations]]
6
+ path = [
7
+ ".DS_Store",
8
+ ".gitattributes",
9
+ ".gitignore",
10
+ ".pdd",
11
+ "**.json",
12
+ "**.md",
13
+ "**.png",
14
+ "**.svg",
15
+ "**.txt",
16
+ "**/.DS_Store",
17
+ "**/.gitignore",
18
+ "**/.pdd",
19
+ "**/*.csv",
20
+ "**/*.jpg",
21
+ "**/*.json",
22
+ "**/*.md",
23
+ "**/*.pdf",
24
+ "**/*.png",
25
+ "**/*.svg",
26
+ "**/*.txt",
27
+ "**/*.vm",
28
+ "**/CNAME",
29
+ "**/Gemfile.lock",
30
+ "Gemfile.lock",
31
+ "README.md",
32
+ "renovate.json",
33
+ ]
34
+ precedence = "override"
35
+ SPDX-FileCopyrightText = "Copyright (c) 2025 Yegor Bugayenko"
36
+ SPDX-License-Identifier = "MIT"
data/Rakefile CHANGED
@@ -1,29 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2025 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
4
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
5
+ # SPDX-License-Identifier: MIT
23
6
 
24
7
  require 'rubygems'
25
8
  require 'rake'
26
- require 'rdoc'
27
9
  require 'rake/clean'
28
10
 
29
11
  def name
@@ -34,7 +16,7 @@ def version
34
16
  Gem::Specification.load(Dir['*.gemspec'].first).version
35
17
  end
36
18
 
37
- task default: %i[clean test rubocop copyright]
19
+ task default: %i[clean test rubocop yard]
38
20
 
39
21
  require 'rake/testtask'
40
22
  desc 'Run all unit tests'
@@ -46,26 +28,15 @@ Rake::TestTask.new(:test) do |test|
46
28
  test.verbose = false
47
29
  end
48
30
 
49
- require 'rdoc/task'
50
- desc 'Build RDoc documentation'
51
- Rake::RDocTask.new do |rdoc|
52
- rdoc.rdoc_dir = 'rdoc'
53
- rdoc.title = "#{name} #{version}"
54
- rdoc.rdoc_files.include('README*')
55
- rdoc.rdoc_files.include('lib/**/*.rb')
31
+ require 'yard'
32
+ desc 'Build Yard documentation'
33
+ YARD::Rake::YardocTask.new do |t|
34
+ t.files = ['lib/**/*.rb']
35
+ t.options = ['--fail-on-warning']
56
36
  end
57
37
 
58
38
  require 'rubocop/rake_task'
59
39
  desc 'Run RuboCop on all directories'
60
40
  RuboCop::RakeTask.new(:rubocop) do |task|
61
41
  task.fail_on_error = true
62
- task.requires << 'rubocop-rspec'
63
- end
64
-
65
- task :copyright do
66
- sh "grep -q -r '2017-#{Date.today.strftime('%Y')}' \
67
- --include '*.rb' \
68
- --include '*.txt' \
69
- --include 'Rakefile' \
70
- ."
71
42
  end
data/glogin.gemspec CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2017-2025 Yegor Bugayenko
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the 'Software'), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in all
13
- # copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
22
5
 
23
6
  require 'English'
24
7
 
@@ -36,12 +19,13 @@ Gem::Specification.new do |s|
36
19
  s.description = 'Enables login/logout functionality for a Ruby web app'
37
20
  s.authors = ['Yegor Bugayenko']
38
21
  s.email = 'yegor256@gmail.com'
39
- s.homepage = 'http://github.com/yegor256/glogin'
40
- s.files = `git ls-files`.split($RS)
22
+ s.homepage = 'https://github.com/yegor256/glogin'
23
+ s.files = `git ls-files | grep -v -E '^(test/|\\.|renovate)'`.split($RS)
41
24
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
42
25
  s.rdoc_options = ['--charset=UTF-8']
43
26
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
44
27
  s.add_dependency 'base58', '>= 0.2'
28
+ s.add_dependency 'base64', '>= 0.2'
45
29
  s.add_dependency 'openssl', '>= 2.0'
46
30
  s.metadata['rubygems_mfa_required'] = 'true'
47
31
  end
data/lib/glogin/auth.rb CHANGED
@@ -1,40 +1,51 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- #
4
- # Copyright (c) 2017-2025 Yegor Bugayenko
5
- #
6
- # Permission is hereby granted, free of charge, to any person obtaining a copy
7
- # of this software and associated documentation files (the 'Software'), to deal
8
- # in the Software without restriction, including without limitation the rights
9
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- # copies of the Software, and to permit persons to whom the Software is
11
- # furnished to do so, subject to the following conditions:
12
- #
13
- # The above copyright notice and this permission notice shall be included in all
14
- # copies or substantial portions of the Software.
15
- #
16
- # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- # SOFTWARE.
3
+ # SPDX-FileCopyrightText: Copyright (c) 2017-2025 Yegor Bugayenko
4
+ # SPDX-License-Identifier: MIT
23
5
 
6
+ require 'cgi'
7
+ require 'json'
24
8
  require 'net/http'
25
9
  require 'uri'
26
- require 'json'
27
- require 'cgi'
28
10
 
29
11
  # GLogin main module.
30
12
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
13
  # Copyright:: Copyright (c) 2017-2025 Yegor Bugayenko
32
14
  # License:: MIT
33
15
  module GLogin
16
+ # GitHub authentication mechanism.
17
+ #
18
+ # This class handles the OAuth flow with GitHub, including generating
19
+ # authorization URLs and exchanging authorization codes for access tokens
20
+ # to retrieve user information.
34
21
  #
35
- # GitHub auth mechanism
22
+ # @example Creating an Auth instance
23
+ # auth = GLogin::Auth.new(
24
+ # 'your-github-client-id',
25
+ # 'your-github-client-secret',
26
+ # 'https://yourapp.com/callback'
27
+ # )
36
28
  #
29
+ # @example Getting the GitHub login URL
30
+ # login_url = auth.login_uri
31
+ # # => "https://github.com/login/oauth/authorize?client_id=...&redirect_uri=..."
32
+ #
33
+ # @example Retrieving user information after callback
34
+ # user_info = auth.user(params[:code])
35
+ # # => {"id"=>"123456", "login"=>"username", "avatar_url"=>"https://..."}
37
36
  class Auth
37
+ # Creates a new GitHub authentication handler.
38
+ #
39
+ # @param id [String] GitHub OAuth application client ID
40
+ # @param secret [String] GitHub OAuth application client secret
41
+ # @param redirect [String] The callback URL where GitHub will redirect after authentication
42
+ # @raise [RuntimeError] if any parameter is nil or redirect is empty
43
+ # @example
44
+ # auth = GLogin::Auth.new(
45
+ # ENV['GITHUB_CLIENT_ID'],
46
+ # ENV['GITHUB_CLIENT_SECRET'],
47
+ # 'https://myapp.com/auth/callback'
48
+ # )
38
49
  def initialize(id, secret, redirect)
39
50
  raise "GitHub client ID can't be nil" if id.nil?
40
51
  @id = id
@@ -45,20 +56,45 @@ module GLogin
45
56
  @redirect = redirect
46
57
  end
47
58
 
59
+ # Generates the GitHub OAuth authorization URL.
60
+ #
61
+ # Users should be redirected to this URL to begin the authentication process.
62
+ # GitHub will ask them to authorize your application, then redirect them back
63
+ # to your specified redirect URL with an authorization code.
64
+ #
65
+ # @return [String] The GitHub OAuth authorization URL
66
+ # @example Redirect users to GitHub for authentication
67
+ # auth = GLogin::Auth.new(id, secret, redirect_url)
68
+ # redirect auth.login_uri
48
69
  def login_uri
49
70
  "https://github.com/login/oauth/authorize?client_id=#{CGI.escape(@id)}&redirect_uri=#{CGI.escape(@redirect)}"
50
71
  end
51
72
 
52
- # Returns a hash with information about Github user,
73
+ # Returns a hash with information about GitHub user
53
74
  # who just logged in with the authentication code.
54
75
  #
55
- # API: https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-the-authenticated-user
76
+ # This method exchanges the temporary authorization code (received from GitHub
77
+ # callback) for an access token, then uses that token to fetch the user's
78
+ # profile information.
79
+ #
80
+ # @param code [String] The authorization code received from GitHub callback
81
+ # @return [Hash] User information including 'id', 'login', and 'avatar_url'
82
+ # @raise [RuntimeError] if the code is nil, empty, or if the API request fails
83
+ # @example Handling the GitHub callback
84
+ # get '/auth/callback' do
85
+ # code = params[:code]
86
+ # user = auth.user(code)
87
+ # # user => {"id"=>"123456", "login"=>"octocat", "avatar_url"=>"https://..."}
88
+ # session[:user_id] = user['id']
89
+ # end
90
+ # @note When secret is empty (test mode), returns a mock user object
91
+ # @see https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-the-authenticated-user
56
92
  def user(code)
57
93
  if @secret.empty?
58
94
  return {
59
- 'id' => 526_301,
60
- 'login' => 'yegor256',
61
- 'avatar_url' => 'https://github.com/yegor256.png'
95
+ 'id' => 1_024_025,
96
+ 'login' => 'torvalds',
97
+ 'avatar_url' => 'https://github.com/torvalds.png'
62
98
  }
63
99
  end
64
100
  raise 'Code can\'t be nil' if code.nil?