glogin 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7e981c77fb4b32d821a8c6959a2772d37af2f4cf7133aa18374b662040bedcc
4
- data.tar.gz: 4f87e9d5512dc2712ac91d770488a5fe799cdc069dfeeb2d6aecf32b0772af78
3
+ metadata.gz: f95b5783be06871b3fcc570c2c931aa4805df8d9eba5fd3e56efdc324b828947
4
+ data.tar.gz: 59bad949654ddf467ee7c3c7e520cb885682227fd2b19e2f52131a299d69e0ec
5
5
  SHA512:
6
- metadata.gz: b59c8c6f1d5d763a8a9317aab9a27a73fe803406a6a3366efff7fefa9b6a298a079357f55854c08df6e05a2987a2415f2b23c1696a332c86d8f711512d50528e
7
- data.tar.gz: 3a50c24837adee03fcc16ff3f42a216cd74bd16235c268b3b45194f7c2fc9c901c570c7a7323e966733895d908fac77b46f8b4583dc7b52b7f822d34b306eb7a
6
+ metadata.gz: 22863efe1b00bb8fb9da9727d173e2b884986496f50be8d1c4f7fead6f16383ac0be0f2ee5c2acb66834d558e67e290a6855b622e94738f86c729e371abe609d
7
+ data.tar.gz: 822e2f1c55dada3a6cb2dd5cfc15f77ebb6762bab9f7ad23d270612d94e6489c3352f92973c6491e009d02af955a9522a734419dc6dac1d26b7da9edc9e88c2f
data/.0pdd.yml CHANGED
@@ -1,3 +1,23 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+ ---
1
21
  errors:
2
22
  - yegor256@gmail.com
3
23
  # alerts:
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+ ---
21
+ name: actionlint
22
+ 'on':
23
+ push:
24
+ branches:
25
+ - master
26
+ pull_request:
27
+ branches:
28
+ - master
29
+ jobs:
30
+ actionlint:
31
+ runs-on: ubuntu-22.04
32
+ steps:
33
+ - uses: actions/checkout@v4
34
+ - name: Download actionlint
35
+ id: get_actionlint
36
+ # yamllint disable-line rule:line-length
37
+ run: bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
38
+ shell: bash
39
+ - name: Check workflow files
40
+ run: ${{ steps.get_actionlint.outputs.executable }} -color
41
+ shell: bash
@@ -1,3 +1,22 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
1
20
  ---
2
21
  name: codecov
3
22
  on:
@@ -0,0 +1,30 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+ ---
21
+ name: copyrights
22
+ 'on':
23
+ push:
24
+ pull_request:
25
+ jobs:
26
+ copyrights:
27
+ runs-on: ubuntu-22.04
28
+ steps:
29
+ - uses: actions/checkout@v4
30
+ - uses: yegor256/copyrights-action@0.0.4
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+ ---
21
+ name: markdown-lint
22
+ 'on':
23
+ push:
24
+ branches:
25
+ - master
26
+ pull_request:
27
+ branches:
28
+ - master
29
+ paths-ignore: ['paper/**', 'sandbox/**']
30
+ concurrency:
31
+ group: markdown-lint-${{ github.ref }}
32
+ cancel-in-progress: true
33
+ jobs:
34
+ markdown-lint:
35
+ runs-on: ubuntu-22.04
36
+ steps:
37
+ - uses: actions/checkout@v4
38
+ - uses: articulate/actions-markdownlint@v1
@@ -1,3 +1,22 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
1
20
  ---
2
21
  name: pdd
3
22
  on:
@@ -1,3 +1,22 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
1
20
  ---
2
21
  name: rake
3
22
  on:
@@ -1,3 +1,22 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
1
20
  ---
2
21
  name: xcop
3
22
  on:
data/.rubocop.yml CHANGED
@@ -1,3 +1,23 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+ ---
1
21
  AllCops:
2
22
  Exclude:
3
23
  - 'bin/**/*'
data/.rultor.yml CHANGED
@@ -1,3 +1,23 @@
1
+ # Copyright (c) 2017-2024 Yegor Bugayenko
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the 'Software'), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+ ---
1
21
  docker:
2
22
  image: yegor256/rultor-image:1.23.1
3
23
  assets:
data/Gemfile CHANGED
@@ -24,11 +24,11 @@
24
24
  source 'https://rubygems.org'
25
25
  gemspec
26
26
 
27
- gem 'minitest', '5.23.1', require: false
27
+ gem 'minitest', '5.24.1', require: false
28
28
  gem 'rake', '13.2.1', require: false
29
29
  gem 'rdoc', '6.7.0', require: false
30
- gem 'rspec-rails', '6.1.2', require: false
31
- gem 'rubocop', '1.64.0', require: false
32
- gem 'rubocop-rspec', '2.29.2', require: false
30
+ gem 'rspec-rails', '6.1.3', require: false
31
+ gem 'rubocop', '1.65.0', require: false
32
+ gem 'rubocop-rspec', '3.0.2', require: false
33
33
  gem 'simplecov', '0.22.0', require: false
34
34
  gem 'webmock', '3.23.1', require: false
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- <img src="/logo.svg" width="64px" height="64px"/>
1
+ # OAuth Login via GitHub Made Simple
2
2
 
3
3
  [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/glogin)](http://www.rultor.com/p/yegor256/glogin)
4
4
  [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
@@ -13,13 +13,13 @@
13
13
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/yegor256/glogin/blob/master/LICENSE.txt)
14
14
 
15
15
  This simple gem will help you enable login/logout through
16
- [GitHub OAuth](https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/)
16
+ [GitHub OAuth][doc]
17
17
  for your web application. This is how it works with
18
18
  [Sinatra](http://www.sinatrarb.com/),
19
19
  but you can do something similar in any framework.
20
20
 
21
21
  Read this blog post to get the idea:
22
- [_Simplified GitHub Login for a Ruby Web App_](https://www.yegor256.com/2018/06/19/glogin.html)
22
+ [_Simplified GitHub Login for a Ruby Web App_][blog]
23
23
 
24
24
  First, somewhere in the global space, before the app starts:
25
25
 
@@ -104,11 +104,12 @@ settings.glogin.login_uri
104
104
  ```
105
105
 
106
106
  For unit testing you can just provide an empty string as a `secret` for
107
- `GLogin::Cookie::Open` and `GLogin::Cookie::Closed` and the encryption will be disabled:
107
+ `GLogin::Cookie::Open` and `GLogin::Cookie::Closed`
108
+ and the encryption will be disabled:
108
109
  whatever will be coming from the cookie will be trusted. For testing
109
110
  it will be convenient to provide a user name in a query string, like:
110
111
 
111
- ```
112
+ ```text
112
113
  http://localhost:9292/?glogin=tester
113
114
  ```
114
115
 
@@ -140,14 +141,19 @@ decrypted = codec.decrypt(encrypted)
140
141
 
141
142
  ## How to contribute
142
143
 
143
- Read [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
144
+ Read
145
+ [these guidelines](https://www.yegor256.com/2014/04/15/github-guidelines.html).
144
146
  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
147
+ your pull request. You will need to have
148
+ [Ruby](https://www.ruby-lang.org/en/) 2.3+ and
146
149
  [Bundler](https://bundler.io/) installed. Then:
147
150
 
148
- ```
149
- $ bundle update
150
- $ bundle exec rake
151
+ ```bash
152
+ bundle update
153
+ bundle exec rake
151
154
  ```
152
155
 
153
156
  If it's clean and you don't see any error messages, submit your pull request.
157
+
158
+ [blog]: https://www.yegor256.com/2018/06/19/glogin.html
159
+ [doc]: https://developer.github.com/apps/building-integrations/setting-up-and-registering-oauth-apps/
data/glogin.gemspec CHANGED
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
42
42
  s.rdoc_options = ['--charset=UTF-8']
43
43
  s.extra_rdoc_files = ['README.md', 'LICENSE.txt']
44
- s.add_runtime_dependency 'base58', '>= 0.2'
45
- s.add_runtime_dependency 'openssl', '>= 2.0'
44
+ s.add_dependency 'base58', '>= 0.2'
45
+ s.add_dependency 'openssl', '>= 2.0'
46
46
  s.metadata['rubygems_mfa_required'] = 'true'
47
47
  end
data/lib/glogin/auth.rb CHANGED
@@ -41,6 +41,7 @@ module GLogin
41
41
  raise "GitHub client secret can't be nil" if secret.nil?
42
42
  @secret = secret
43
43
  raise "Redirect URL can't be nil" if redirect.nil?
44
+ raise "Redirect URL can't be empty" if redirect.empty?
44
45
  @redirect = redirect
45
46
  end
46
47
 
@@ -61,15 +62,17 @@ module GLogin
61
62
  }
62
63
  end
63
64
  raise 'Code can\'t be nil' if code.nil?
65
+ raise 'Code can\'t be empty' if code.empty?
64
66
  uri = URI.parse('https://api.github.com/user')
65
67
  http = Net::HTTP.new(uri.host, uri.port)
66
68
  http.use_ssl = true
67
69
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
68
70
  req = Net::HTTP::Get.new(uri.request_uri)
69
71
  req['Accept-Header'] = 'application/json'
70
- req['Authorization'] = "token #{access_token(code)}"
72
+ token = access_token(code)
73
+ req['Authorization'] = "token #{token}"
71
74
  res = http.request(req)
72
- raise "Error (#{res.code}): #{res.body}" unless res.code == '200'
75
+ raise "HTTP error ##{res.code} with token #{escape(token)}: #{res.body}" unless res.code == '200'
73
76
  JSON.parse(res.body)
74
77
  end
75
78
 
@@ -77,6 +80,7 @@ module GLogin
77
80
 
78
81
  def access_token(code)
79
82
  raise 'Code can\'t be nil' if code.nil?
83
+ raise 'Code can\'t be empty' if code.empty?
80
84
  uri = URI.parse('https://github.com/login/oauth/access_token')
81
85
  http = Net::HTTP.new(uri.host, uri.port)
82
86
  http.use_ssl = true
@@ -89,8 +93,18 @@ module GLogin
89
93
  )
90
94
  req['Accept'] = 'application/json'
91
95
  res = http.request(req)
92
- raise "Error (#{res.code}): #{res.body}" unless res.code == '200'
96
+ raise "HTTP error ##{res.code} with code #{escape(code)}: #{res.body}" unless res.code == '200'
93
97
  JSON.parse(res.body)['access_token']
94
98
  end
99
+
100
+ def escape(txt)
101
+ prefix = 4
102
+ [
103
+ '"',
104
+ txt[0..prefix],
105
+ '*' * (token.length - prefix),
106
+ '"'
107
+ ].join
108
+ end
95
109
  end
96
110
  end
@@ -26,5 +26,5 @@
26
26
  # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module GLogin
29
- VERSION = '0.15.0'
29
+ VERSION = '0.16.0'
30
30
  end
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.15.0
4
+ version: 0.16.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: 2024-05-28 00:00:00.000000000 Z
11
+ date: 2024-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base58
@@ -48,7 +48,10 @@ extra_rdoc_files:
48
48
  files:
49
49
  - ".0pdd.yml"
50
50
  - ".gitattributes"
51
+ - ".github/workflows/actionlint.yml"
51
52
  - ".github/workflows/codecov.yml"
53
+ - ".github/workflows/copyrights.yml"
54
+ - ".github/workflows/markdown-lint.yml"
52
55
  - ".github/workflows/pdd.yml"
53
56
  - ".github/workflows/rake.yml"
54
57
  - ".github/workflows/xcop.yml"