glogin 0.13.0 → 0.14.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: 676ad5d1a6bca2ec2d76ab9939299b3a561d86151d5fda5cf256db88e0710b61
4
- data.tar.gz: d43e3c48a754d4a1be1d2e22e6665d10fd311afb45b2bc7bdab800b0d65c631f
3
+ metadata.gz: 43ce4ccebe57a06bb860c407b9e96dc939932f952aa2a6c4951a64f79a5f34c7
4
+ data.tar.gz: 65854ae4920a4ff27bd67bcf7cf34d8222be36398639bd82b013fa73b94700a5
5
5
  SHA512:
6
- metadata.gz: 827cee7b4b9e198cd05c46fd91a02db8df3a76121d1f94a5892f4c83fd93c8689366a7e9c36146c7efd7db1bec9321d697893a6cd6497ee386bcfc1c514a9e4c
7
- data.tar.gz: df68d65779e90da7a79dac9f97d101f9d7a1a37c5e3711b1170c94021334c09f873bec55fd3c438e525cfdd575a877d8bbfcf91ffbc12d2bad14c96162e82e6a
6
+ metadata.gz: c36870984ff3f36eb946b5bbb5273bc4f3633332651bd180196d1b172c7782248583285a0e3c9ae499205d45b6a45bb6e19910b7fb6ca8a455b0b2af8934c457
7
+ data.tar.gz: 456ef6a6e5329d490d2195c58d3c8c007e23f6326f4535d362b04898451009926a5226baa384342b8dd889f6e00c17b8ef595d85e7a0e0fd5fa4a06c69324642
@@ -8,13 +8,14 @@ jobs:
8
8
  codecov:
9
9
  runs-on: ubuntu-22.04
10
10
  steps:
11
- - uses: actions/checkout@v3
11
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
12
12
  - uses: ruby/setup-ruby@v1
13
13
  with:
14
14
  ruby-version: 2.7
15
15
  - run: bundle update
16
16
  - run: bundle exec rake
17
- - uses: codecov/codecov-action@v3
17
+ - uses: codecov/codecov-action@v4.0.0-beta.3
18
18
  with:
19
+ token: ${{ secrets.CODECOV_TOKEN }}
19
20
  file: coverage/.resultset.json
20
21
  fail_ci_if_error: true
@@ -2,10 +2,14 @@
2
2
  name: pdd
3
3
  on:
4
4
  push:
5
+ branches:
6
+ - master
5
7
  pull_request:
8
+ branches:
9
+ - master
6
10
  jobs:
7
11
  pdd:
8
12
  runs-on: ubuntu-22.04
9
13
  steps:
10
- - uses: actions/checkout@v3
11
- - uses: g4s8/pdd-action@master
14
+ - uses: actions/checkout@v4
15
+ - uses: volodya-lombrozo/pdd-action@master
@@ -16,7 +16,7 @@ jobs:
16
16
  ruby: [2.7, 3.2]
17
17
  runs-on: ${{ matrix.os }}
18
18
  steps:
19
- - uses: actions/checkout@v3
19
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
20
20
  - uses: ruby/setup-ruby@v1
21
21
  with:
22
22
  ruby-version: ${{ matrix.ruby }}
@@ -7,5 +7,5 @@ jobs:
7
7
  xcop:
8
8
  runs-on: ubuntu-22.04
9
9
  steps:
10
- - uses: actions/checkout@v3
10
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
11
11
  - uses: g4s8/xcop-action@master
data/.rultor.yml CHANGED
@@ -1,11 +1,10 @@
1
1
  docker:
2
- image: yegor256/rultor-image:1.19.0
2
+ image: yegor256/rultor-image:1.22.0
3
3
  assets:
4
4
  rubygems.yml: yegor256/home#assets/rubygems.yml
5
5
  install: |
6
- sudo gem install openssl -- --with-openssl-dir=/usr/local/rvm/rubies/ruby-3.0.1/lib/ruby/3.0.0/openssl
7
6
  pdd -f /dev/null
8
- sudo bundle install --no-color "--gemfile=$(pwd)/Gemfile"
7
+ bundle install --no-color
9
8
  release:
10
9
  pre: false
11
10
  script: |-
data/.simplecov CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -24,11 +24,11 @@
24
24
  source 'https://rubygems.org'
25
25
  gemspec
26
26
 
27
- gem 'minitest', '5.19.0', require: false
28
- gem 'rake', '13.0.6', require: false
29
- gem 'rdoc', '6.5.0', require: false
30
- gem 'rspec-rails', '6.0.3', require: false
31
- gem 'rubocop', '1.56.0', require: false
32
- gem 'rubocop-rspec', '2.23.2', require: false
27
+ gem 'minitest', '5.21.2', require: false
28
+ gem 'rake', '13.1.0', require: false
29
+ gem 'rdoc', '6.6.1', require: false
30
+ gem 'rspec-rails', '6.1.0', require: false
31
+ gem 'rubocop', '1.60.1', require: false
32
+ gem 'rubocop-rspec', '2.26.1', require: false
33
33
  gem 'simplecov', '0.22.0', require: false
34
- gem 'webmock', '3.18.1', require: false
34
+ gem 'webmock', '3.19.1', require: false
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2017-2023 Yegor Bugayenko
3
+ Copyright (c) 2017-2024 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
data/glogin.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright (c) 2017-2023 Yegor Bugayenko
3
+ # Copyright (c) 2017-2024 Yegor Bugayenko
4
4
  #
5
5
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  # of this software and associated documentation files (the 'Software'), to deal
data/lib/glogin/auth.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -28,7 +28,7 @@ require 'cgi'
28
28
 
29
29
  # GLogin main module.
30
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
- # Copyright:: Copyright (c) 2017-2023 Yegor Bugayenko
31
+ # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
32
32
  # License:: MIT
33
33
  module GLogin
34
34
  #
@@ -48,7 +48,19 @@ module GLogin
48
48
  "https://github.com/login/oauth/authorize?client_id=#{CGI.escape(@id)}&redirect_uri=#{CGI.escape(@redirect)}"
49
49
  end
50
50
 
51
+ # Returns a hash with information about Github user,
52
+ # who just logged in with the authentication code.
53
+ #
54
+ # API: https://docs.github.com/en/rest/users/users?apiVersion=2022-11-28#get-the-authenticated-user
51
55
  def user(code)
56
+ if @secret.empty?
57
+ return {
58
+ 'id' => 526_301,
59
+ 'login' => 'yegor256',
60
+ 'avatar_url' => 'https://github.com/yegor256.png',
61
+ 'bearer' => ''
62
+ }
63
+ end
52
64
  raise 'Code can\'t be nil' if code.nil?
53
65
  uri = URI.parse('https://api.github.com/user')
54
66
  http = Net::HTTP.new(uri.host, uri.port)
data/lib/glogin/codec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -29,7 +29,7 @@ require 'base64'
29
29
 
30
30
  # Codec.
31
31
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
32
- # Copyright:: Copyright (c) 2017-2023 Yegor Bugayenko
32
+ # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
33
33
  # License:: MIT
34
34
  module GLogin
35
35
  # The codec
data/lib/glogin/cookie.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -28,7 +28,7 @@ require_relative 'codec'
28
28
 
29
29
  # GLogin main module.
30
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
- # Copyright:: Copyright (c) 2017-2023 Yegor Bugayenko
31
+ # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
32
32
  # License:: MIT
33
33
  module GLogin
34
34
  # Split symbol inside the cookie text
@@ -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 two elements: login and avatar.
52
- # If the secret is empty, the text will be returned, without
53
- # any decryption. If the data is not valid, an exception
54
- # GLogin::Codec::DecodingError will be raised, which you have
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,12 +78,24 @@ module GLogin
68
78
 
69
79
  # Open
70
80
  class Open
71
- # Here comes the JSON you receive from Auth.user()
81
+ # Here comes the JSON you receive from Auth.user().
82
+ #
83
+ # The JSON is a Hash where every key is a string. When the class is instantiated,
84
+ # its methods +id+, +login+, and +avatar_url+ may be used to retrieve
85
+ # the data inside the JSON, but this is not what this class is mainly about.
86
+ #
87
+ # The method +to_s+ returns an encrypted cookie string, that may be
88
+ # sent to the user as a +Set-Cookie+ HTTP header.
72
89
  def initialize(json, secret, context = '')
73
90
  raise 'JSON can\'t be nil' if json.nil?
91
+ raise 'JSON must contain "id" key' if json['id'].nil?
92
+ raise 'JSON must contain "login" key' if json['login'].nil?
93
+ raise 'JSON must contain "avatar_url" key' if json['avatar_url'].nil?
94
+ raise 'JSON must contain "bearer" key' if json['bearer'].nil?
74
95
  @json = json
75
96
  raise 'Secret can\'t be nil' if secret.nil?
76
97
  @secret = secret
98
+ raise 'Context can\'t be nil' if context.nil?
77
99
  @context = context.to_s
78
100
  end
79
101
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -23,8 +23,8 @@
23
23
 
24
24
  # GLogin main module.
25
25
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
26
- # Copyright:: Copyright (c) 2017-2023 Yegor Bugayenko
26
+ # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
27
27
  # License:: MIT
28
28
  module GLogin
29
- VERSION = '0.13.0'
29
+ VERSION = '0.14.1'
30
30
  end
data/lib/glogin.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -28,7 +28,7 @@ require_relative 'glogin/cookie'
28
28
 
29
29
  # GLogin main module.
30
30
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
31
- # Copyright:: Copyright (c) 2017-2023 Yegor Bugayenko
31
+ # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
32
32
  # License:: MIT
33
33
  module GLogin
34
34
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -53,4 +53,9 @@ class TestAuth < Minitest::Test
53
53
  )
54
54
  )
55
55
  end
56
+
57
+ def test_get_fake_user
58
+ auth = GLogin::Auth.new('99999', '', 'http://www.example.com/github-oauth')
59
+ assert_equal('yegor256', auth.user('1234567890')['login'])
60
+ end
56
61
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -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":"999","bearer":""}'),
98
98
  secret,
99
99
  'context-1'
100
100
  ).to_s,
data/test/test__helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
data/test/test_glogin.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #
4
- # Copyright (c) 2017-2023 Yegor Bugayenko
4
+ # Copyright (c) 2017-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -26,7 +26,7 @@ require_relative '../lib/glogin'
26
26
 
27
27
  # GLogin main module test.
28
28
  # Author:: Yegor Bugayenko (yegor256@gmail.com)
29
- # Copyright:: Copyright (c) 2017-2023 Yegor Bugayenko
29
+ # Copyright:: Copyright (c) 2017-2024 Yegor Bugayenko
30
30
  # License:: MIT
31
31
  class TestGLogin < Minitest::Test
32
32
  def test_basic
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.13.0
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-25 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base58
@@ -95,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  requirements: []
98
- rubygems_version: 3.2.15
98
+ rubygems_version: 3.4.10
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: Login/logout via GitHub OAuth for your web app