hydra-keycloak-client 0.1.6 → 0.1.9

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: 18c487395b0610c378e53e63bd831b32c74f599f4fcd7fad8827698bd645dcfc
4
- data.tar.gz: 0b31711516d5f351b1c82bca9164462f124595eb40d7dc790316e6d43c7c08b0
3
+ metadata.gz: 84abeff9bb6fc129c0f1735211b5b519ca9d5570bad6d240c196a7eab5187e17
4
+ data.tar.gz: 39ba322f013e055547490e6661d6b3f37fb658eaa2a7a582c0c17e42f028afc5
5
5
  SHA512:
6
- metadata.gz: 0ed1cb5e7793a4ab45473551345d1ee6eca95d8ad349e3fd9023cd5f7282edf4cdcc87598bb9bc86de2797cc3ff0198d6f458817f0ded485745ef4d4dc3229da
7
- data.tar.gz: 925857eea90aa7a6008f66febe1dadfa02820f72c0ca5ae2ec7cd24c20890c417a5268f2ad033084782d141706d47449f27d6c0797ef6b77e6899922f2ccc1d3
6
+ metadata.gz: 4b26d5274c9b28d2a8d8b93fbdb0d0277ddfd783f613228963277f8b562bcbe751156aa0fbf2599853266f28724a0d2230345311814f839b2a64200bce1c9a86
7
+ data.tar.gz: 352f55a4a3a39886aa9446a56edfa63c618760b2d34c0da43f470ad2eb59356e84c4ed027a6d74d917c7aa610c08ce6a1cba4fffddc6b8fc03fdda9aa6676cc0
@@ -0,0 +1,19 @@
1
+ name: CI
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: self-hosted
8
+
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+
12
+ - name: Build image
13
+ run: docker build -f Dockerfile.test -t hkc_test_image .
14
+
15
+ - name: Run rubocop
16
+ run: docker run hkc_test_image rubocop
17
+
18
+ - name: Run tests
19
+ run: docker run hkc_test_image rspec
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5.8
3
+ Exclude:
4
+ - 'spec/**/**/*'
5
+
6
+ Style/Documentation:
7
+ Enabled: false
8
+
9
+ Metrics/AbcSize:
10
+ Max: 50
11
+
12
+ Metrics/MethodLength:
13
+ Max: 30
data/Dockerfile.test ADDED
@@ -0,0 +1,6 @@
1
+ FROM ruby:2.7.4
2
+
3
+ COPY . /app
4
+ WORKDIR /app
5
+
6
+ RUN bundle install
data/Gemfile CHANGED
@@ -1,9 +1,12 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in hydra-keycloak-client.gemspec
4
6
  gemspec
5
7
 
6
- gem "rake", "~> 12.0"
7
- gem "rspec", "~> 3.0"
8
+ gem 'rake', '~> 12.0'
9
+ gem 'rspec', '~> 3.0'
10
+ gem 'rubocop', '~> 1.26'
8
11
 
9
12
  gem 'pry'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hydra-keycloak-client (0.1.5)
4
+ hydra-keycloak-client (0.1.9)
5
5
  dalli
6
6
  dry-auto_inject
7
7
  dry-container
@@ -14,13 +14,14 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
+ ast (2.4.2)
17
18
  coderay (1.1.3)
18
19
  concurrent-ruby (1.1.9)
19
- dalli (3.1.1)
20
+ dalli (3.2.1)
20
21
  diff-lcs (1.4.4)
21
- dry-auto_inject (0.8.0)
22
+ dry-auto_inject (0.9.0)
22
23
  dry-container (>= 0.3.4)
23
- dry-configurable (0.13.0)
24
+ dry-configurable (0.14.0)
24
25
  concurrent-ruby (~> 1.0)
25
26
  dry-core (~> 0.6)
26
27
  dry-container (0.9.0)
@@ -29,14 +30,14 @@ GEM
29
30
  dry-core (0.7.1)
30
31
  concurrent-ruby (~> 1.0)
31
32
  dry-inflector (0.2.1)
32
- dry-initializer (3.0.4)
33
+ dry-initializer (3.1.1)
33
34
  dry-logic (1.2.0)
34
35
  concurrent-ruby (~> 1.0)
35
36
  dry-core (~> 0.5, >= 0.5)
36
37
  dry-monads (1.4.0)
37
38
  concurrent-ruby (~> 1.0)
38
39
  dry-core (~> 0.7)
39
- dry-schema (1.8.0)
40
+ dry-schema (1.9.1)
40
41
  concurrent-ruby (~> 1.0)
41
42
  dry-configurable (~> 0.13, >= 0.13.0)
42
43
  dry-core (~> 0.5, >= 0.5)
@@ -56,11 +57,17 @@ GEM
56
57
  ice_nine (0.11.2)
57
58
  jwt (2.3.0)
58
59
  method_source (1.0.0)
60
+ parallel (1.21.0)
61
+ parser (3.1.1.0)
62
+ ast (~> 2.4.1)
59
63
  pry (0.14.1)
60
64
  coderay (~> 1.1)
61
65
  method_source (~> 1.0)
66
+ rainbow (3.1.1)
62
67
  rake (12.3.3)
63
68
  redis (4.6.0)
69
+ regexp_parser (2.2.1)
70
+ rexml (3.2.5)
64
71
  rspec (3.10.0)
65
72
  rspec-core (~> 3.10.0)
66
73
  rspec-expectations (~> 3.10.0)
@@ -74,6 +81,19 @@ GEM
74
81
  diff-lcs (>= 1.2.0, < 2.0)
75
82
  rspec-support (~> 3.10.0)
76
83
  rspec-support (3.10.3)
84
+ rubocop (1.26.0)
85
+ parallel (~> 1.10)
86
+ parser (>= 3.1.0.0)
87
+ rainbow (>= 2.2.2, < 4.0)
88
+ regexp_parser (>= 1.8, < 3.0)
89
+ rexml
90
+ rubocop-ast (>= 1.16.0, < 2.0)
91
+ ruby-progressbar (~> 1.7)
92
+ unicode-display_width (>= 1.4.0, < 3.0)
93
+ rubocop-ast (1.16.0)
94
+ parser (>= 3.1.1.0)
95
+ ruby-progressbar (1.11.0)
96
+ unicode-display_width (2.1.0)
77
97
 
78
98
  PLATFORMS
79
99
  ruby
@@ -83,6 +103,7 @@ DEPENDENCIES
83
103
  pry
84
104
  rake (~> 12.0)
85
105
  rspec (~> 3.0)
106
+ rubocop (~> 1.26)
86
107
 
87
108
  BUNDLED WITH
88
109
  2.2.25
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "hydra/keycloak/client"
4
+ require 'bundler/setup'
5
+ require 'hydra/keycloak/client'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "hydra/keycloak/client"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start(__FILE__)
@@ -1,38 +1,40 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require './lib/hydra/keycloak/version'
2
4
 
3
5
  Gem::Specification.new do |spec|
4
- spec.require_paths = ["lib"]
5
- spec.name = "hydra-keycloak-client"
6
+ spec.require_paths = ['lib']
7
+ spec.name = 'hydra-keycloak-client'
6
8
  spec.version = Hydra::Keycloak::VERSION
7
- spec.authors = ["Fedor Kosolapov"]
8
- spec.email = ["f.kosolapov@latera.ru"]
9
+ spec.authors = ['Fedor Kosolapov']
10
+ spec.email = ['f.kosolapov@latera.ru']
9
11
 
10
- spec.summary = "Keycloak client for SSO"
11
- spec.description = "Keycloak client for SSO"
12
- spec.homepage = "https://github.com/latera/hydra-keycloak-client"
13
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
12
+ spec.summary = 'Keycloak client for SSO'
13
+ spec.description = 'Keycloak client for SSO'
14
+ spec.homepage = 'https://github.com/latera/hydra-keycloak-client'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.8')
14
16
 
15
- spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
16
18
 
17
- spec.metadata["homepage_uri"] = spec.homepage
18
- spec.metadata["source_code_uri"] = spec.homepage
19
- spec.metadata["changelog_uri"] = spec.homepage
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = spec.homepage
21
+ spec.metadata['changelog_uri'] = spec.homepage
20
22
 
21
23
  # Specify which files should be added to the gem when it is released.
22
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
26
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
27
  end
26
- spec.bindir = "bin"
28
+ spec.bindir = 'bin'
27
29
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
30
 
29
- spec.add_dependency('jwt')
30
31
  spec.add_dependency('dalli')
32
+ spec.add_dependency('jwt')
31
33
  spec.add_dependency('redis')
32
34
 
33
- spec.add_dependency('dry-monads')
34
35
  spec.add_dependency('dry-auto_inject')
35
36
  spec.add_dependency('dry-container')
37
+ spec.add_dependency('dry-monads')
36
38
  spec.add_dependency('dry-schema')
37
39
  spec.add_dependency('dry-struct')
38
40
  end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dry/monads'
3
4
  require 'dry/auto_inject'
4
5
  require 'dry/container'
5
6
  require 'dry/schema'
6
7
 
7
8
  require 'hydra/keycloak/container'
8
- require 'hydra/keycloak/user_data'
9
9
  require 'hydra/keycloak/code_verifier'
10
10
 
11
11
  module Hydra
@@ -15,85 +15,120 @@ module Hydra
15
15
  class ClientCreator
16
16
  extend ::Hydra::Keycloak::Mixin
17
17
 
18
- def self.call(config:)
19
- memcached_schema = Dry::Schema.JSON do
20
- required(:memcached_host).filled(:string)
21
- required(:memcached_port).filled(:string)
22
- required(:memcached_namespace).filled(:string)
18
+ class << self
19
+ def call(config:)
20
+ register_containers(validate_config(config))
23
21
  end
24
22
 
25
- redis_schema = Dry::Schema.JSON do
26
- required(:redis_host).filled(:string)
27
- required(:redis_port).filled(:string)
28
- end
23
+ def validate_config(config)
24
+ validated_config = config_schema.call(config)
29
25
 
30
- config_schema = Dry::Schema.JSON do
31
- required(:auth_server_url).filled(:string)
32
- required(:realm).filled(:string)
33
- required(:client_id).filled(:string)
34
- required(:redirect_uri).filled(:string)
35
- required(:secret).filled(:string)
36
- required(:logout_redirect).filled(:string)
37
- required(:store_client).value(included_in?: ['redis', 'memcached'])
38
- required(:store_client_options).hash(memcached_schema | redis_schema)
26
+ if validated_config.failure?
27
+ raise ConfigurationError, "Wrong configuration params: #{validated_config.errors(full: true).to_h}"
28
+ end
29
+
30
+ validated_config
31
+ end
32
+
33
+ def config_schema
34
+ memcached_schema = ::Hydra::Keycloak::ClientCreator.memcached_schema
35
+ redis_schema = ::Hydra::Keycloak::ClientCreator.redis_schema
36
+ Dry::Schema.JSON do
37
+ required(:auth_server_url).filled(:string)
38
+ required(:realm).filled(:string)
39
+ required(:client_id).filled(:string)
40
+ required(:redirect_uri).filled(:string)
41
+ required(:secret).filled(:string)
42
+ required(:logout_redirect).filled(:string)
43
+ required(:store_client).value(included_in?: %w[redis memcached])
44
+ required(:store_client_options).hash(memcached_schema | redis_schema)
45
+ end
39
46
  end
40
47
 
41
- validated_config = config_schema.call(config)
48
+ def memcached_schema
49
+ Dry::Schema.JSON do
50
+ required(:memcached_host).filled(:string)
51
+ required(:memcached_port).filled(:string)
52
+ required(:memcached_namespace).filled(:string)
53
+ end
54
+ end
42
55
 
43
- if validated_config.failure?
44
- raise ConfigurationError, "Wrong configuration params: #{validated_config.errors(full: true).to_h}"
56
+ def redis_schema
57
+ Dry::Schema.JSON do
58
+ required(:redis_host).filled(:string)
59
+ required(:redis_port).filled(:string)
60
+ end
45
61
  end
46
62
 
47
- container.register :urls do
48
- require 'hydra/keycloak/urls'
63
+ def register_containers(validated_config)
64
+ register_urls(validated_config)
65
+ register_queries
66
+ register_store_client(validated_config)
67
+ register_store
68
+ register_code_verifier
49
69
 
50
- ::Hydra::Keycloak::Urls.new(validated_config)
70
+ ::Hydra::Keycloak::Client.new
51
71
  end
52
72
 
53
- container.register :queries do
54
- require 'hydra/keycloak/queries/gateway'
73
+ def register_urls(config)
74
+ container.register :urls do
75
+ require 'hydra/keycloak/urls'
55
76
 
56
- ::Hydra::Keycloak::Queries::Gateway.new
77
+ ::Hydra::Keycloak::Urls.new(config)
78
+ end
57
79
  end
58
80
 
59
- if validated_config[:store_client] == 'redis'
60
- container.register :redis do
61
- require 'redis'
62
-
63
- ::Redis.new(host: validated_config[:redis_host], port: validated_config[:redis_port])
64
- end
65
-
66
- container.register :store_client do
67
- require 'hydra/keycloak/store/redis_client'
68
-
69
- ::Hydra::Keycloak::Store::RedisClient.new
70
- end
71
- elsif validated_config[:store_client] == 'memcached'
72
- container.register :dalli do
73
- require 'dalli'
74
-
75
- ::Dalli::Client.new(
76
- "#{validated_config[:store_client_options][:memcached_host]}:#{validated_config[:store_client_options][:memcached_port]}",
77
- namespace: validated_config[:store_client_options][:memcached_namespace]
78
- )
79
- end
80
-
81
- container.register :store_client do
82
- require 'hydra/keycloak/store/memcached_client'
83
-
84
- ::Hydra::Keycloak::Store::MemcachedClient.new
81
+ def register_queries
82
+ container.register :queries do
83
+ require 'hydra/keycloak/queries/gateway'
84
+
85
+ ::Hydra::Keycloak::Queries::Gateway.new
85
86
  end
86
- end
87
+ end
88
+
89
+ def register_store_client(config)
90
+ case config[:store_client]
91
+ when 'redis'
92
+ container.register :redis do
93
+ require 'redis'
94
+
95
+ ::Redis.new(host: config[:redis_host], port: config[:redis_port])
96
+ end
97
+
98
+ container.register :store_client do
99
+ require 'hydra/keycloak/store/redis_client'
100
+
101
+ ::Hydra::Keycloak::Store::RedisClient.new
102
+ end
103
+ when 'memcached'
104
+ container.register :dalli do
105
+ require 'dalli'
87
106
 
88
- container.register :store do
89
- require 'hydra/keycloak/store/gateway'
107
+ ::Dalli::Client.new(
108
+ "#{config[:store_client_options][:memcached_host]}:#{config[:store_client_options][:memcached_port]}",
109
+ namespace: config[:store_client_options][:memcached_namespace]
110
+ )
111
+ end
90
112
 
91
- ::Hydra::Keycloak::Store::Gateway.new
113
+ container.register :store_client do
114
+ require 'hydra/keycloak/store/memcached_client'
115
+
116
+ ::Hydra::Keycloak::Store::MemcachedClient.new
117
+ end
118
+ end
92
119
  end
93
120
 
94
- container.register(:code_verifier, ::Hydra::Keycloak::CodeVerifier.new)
121
+ def register_store
122
+ container.register :store do
123
+ require 'hydra/keycloak/store/gateway'
124
+
125
+ ::Hydra::Keycloak::Store::Gateway.new
126
+ end
127
+ end
95
128
 
96
- ::Hydra::Keycloak::Client.new
129
+ def register_code_verifier
130
+ container.register(:code_verifier, ::Hydra::Keycloak::CodeVerifier.new)
131
+ end
97
132
  end
98
133
  end
99
134
 
@@ -108,9 +143,7 @@ module Hydra
108
143
  end
109
144
 
110
145
  def authenticate!(auth_code)
111
- unless auth_code
112
- return Failure(status: 400, code: :auth_code_was_not_received)
113
- end
146
+ return Failure(status: 400, code: :auth_code_was_not_received) unless auth_code
114
147
 
115
148
  queries.get_tokens(auth_code, code_verifier.value).fmap do |tokens|
116
149
  access_token = tokens[:access_token]
@@ -131,34 +164,14 @@ module Hydra
131
164
  fetch_token(session_state, 'access_token').success?
132
165
  end
133
166
 
134
- def user_data(session_state)
135
- unless authenticated?(session_state)
136
- return Failure(status: 400, code: :not_authenticated)
137
- end
138
-
139
- fetch_token(session_state, 'access_token').fmap do |access_token|
140
- UserData.new(
141
- username: access_token[:login],
142
- base_subject_id: access_token[:base_subject_id],
143
- subj_group_id: access_token[:subj_group_id],
144
- firm_id: access_token[:firm_id],
145
- base_subject_first_name: access_token[:base_subject_first_name],
146
- jti: access_token[:jti])
147
- end
148
- end
149
-
150
167
  def access_token(session_state)
151
- unless authenticated?(session_state)
152
- return Failure(status: 400, code: :not_authenticated)
153
- end
168
+ return Failure(status: 400, code: :not_authenticated) unless authenticated?(session_state)
154
169
 
155
170
  fetch_token(session_state, 'access_token')
156
171
  end
157
172
 
158
173
  def authorize!(session_state)
159
- unless authenticated?(session_state)
160
- return Failure(status: 400, code: :not_authenticated)
161
- end
174
+ return Failure(status: 400, code: :not_authenticated) unless authenticated?(session_state)
162
175
 
163
176
  access_token = yield fetch_token(session_state, 'access_token')
164
177
  if token_expired?(access_token)
@@ -171,13 +184,9 @@ module Hydra
171
184
  end
172
185
 
173
186
  def access_token_jti(session_state)
174
- unless authenticated?(session_state)
175
- return Failure(status: 400, code: :not_authenticated)
176
- end
187
+ return Failure(status: 400, code: :not_authenticated) unless authenticated?(session_state)
177
188
 
178
- fetch_token(session_state, 'access_token').fmap do |access_token|
179
- access_token.jti
180
- end
189
+ fetch_token(session_state, 'access_token').fmap(&:jti)
181
190
  end
182
191
 
183
192
  def logout!(session_state)
@@ -188,6 +197,10 @@ module Hydra
188
197
  end
189
198
  end
190
199
 
200
+ def introspect_token(token)
201
+ queries.token_introspect(token)
202
+ end
203
+
191
204
  private
192
205
 
193
206
  def save_token(session_state, token_name, token)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "digest"
4
- require "securerandom"
3
+ require 'digest'
4
+ require 'securerandom'
5
5
 
6
6
  require 'hydra/keycloak/container'
7
7
 
@@ -9,24 +9,24 @@ module Hydra
9
9
  module Keycloak
10
10
  class CodeVerifier
11
11
  attr_reader :value, :code_challenge
12
-
12
+
13
13
  def generate
14
14
  @value = _generate
15
15
  @code_challenge = _generate_pkce(@value)
16
16
  end
17
-
17
+
18
18
  private
19
-
19
+
20
20
  def _generate
21
21
  # https://datatracker.ietf.org/doc/html/rfc7636#section-4.1
22
22
  charset = Array('A'..'Z') + Array('a'..'z') + Array(0..9)
23
- charset.push("-").push(".").push("_").push("~")
23
+ charset.push('-').push('.').push('_').push('~')
24
24
  Array.new(128) { charset.sample }.join
25
25
  end
26
26
 
27
27
  def _generate_pkce(code_verifier)
28
28
  # https://datatracker.ietf.org/doc/html/rfc7636#section-4.6
29
- Digest::SHA256.base64digest(code_verifier).tr("+/", "-_").tr("=", "")
29
+ Digest::SHA256.base64digest(code_verifier).tr('+/', '-_').tr('=', '')
30
30
  end
31
31
  end
32
32
  end
@@ -19,11 +19,11 @@ module Hydra
19
19
 
20
20
  class << self
21
21
  def inject(target)
22
- -> *values { target.send(:include, Import[*values]) }
22
+ ->(*values) { target.send(:include, Import[*values]) }
23
23
  end
24
-
24
+
25
25
  def args_inject(target)
26
- -> *values { target.send(:include, Import.args[*values]) }
26
+ ->(*values) { target.send(:include, Import.args[*values]) }
27
27
  end
28
28
  end
29
29
 
@@ -31,11 +31,11 @@ module Hydra
31
31
  def container
32
32
  ::Hydra::Keycloak::Container
33
33
  end
34
-
34
+
35
35
  def inject
36
36
  ::Hydra::Keycloak.inject(self)
37
37
  end
38
-
38
+
39
39
  def args_inject
40
40
  ::Hydra::Keycloak.args_inject(self)
41
41
  end
@@ -19,8 +19,8 @@ module Hydra
19
19
 
20
20
  result.fmap do |tokens|
21
21
  {
22
- access_token: ::Hydra::Keycloak::Token.new(tokens['access_token']),
23
- id_token: ::Hydra::Keycloak::Token.new(tokens['id_token']),
22
+ access_token: ::Hydra::Keycloak::Token.new(tokens['access_token']),
23
+ id_token: ::Hydra::Keycloak::Token.new(tokens['id_token']),
24
24
  refresh_token: ::Hydra::Keycloak::Token.new(tokens['refresh_token'])
25
25
  }
26
26
  end
@@ -44,10 +44,10 @@ module Hydra
44
44
  Failure(status: 400, code: :token_refreshing_error)
45
45
  else
46
46
  Success({
47
- access_token: ::Hydra::Keycloak::Token.new(result['access_token']),
48
- id_token: ::Hydra::Keycloak::Token.new(result['id_token']),
49
- refresh_token: ::Hydra::Keycloak::Token.new(result['refresh_token'])
50
- })
47
+ access_token: ::Hydra::Keycloak::Token.new(result['access_token']),
48
+ id_token: ::Hydra::Keycloak::Token.new(result['id_token']),
49
+ refresh_token: ::Hydra::Keycloak::Token.new(result['refresh_token'])
50
+ })
51
51
  end
52
52
  end
53
53
  end
@@ -10,14 +10,14 @@ module Hydra
10
10
  class HttpClient
11
11
  include ::Dry::Monads[:result]
12
12
 
13
- NetworkErrors = [Timeout::Error,
14
- Errno::EINVAL,
15
- Errno::ECONNRESET,
16
- EOFError,
17
- Errno::ECONNREFUSED,
18
- Net::HTTPBadResponse,
19
- Net::HTTPHeaderSyntaxError,
20
- Net::ProtocolError]
13
+ NETWORK_ERRORS = [Timeout::Error,
14
+ Errno::EINVAL,
15
+ Errno::ECONNRESET,
16
+ EOFError,
17
+ Errno::ECONNREFUSED,
18
+ Net::HTTPBadResponse,
19
+ Net::HTTPHeaderSyntaxError,
20
+ Net::ProtocolError].freeze
21
21
 
22
22
  def do_post_request(path, body)
23
23
  response = Net::HTTP.post_form(URI(path), **body)
@@ -29,7 +29,7 @@ module Hydra
29
29
  else
30
30
  Failure(status: response.code, code: :bad_keycloak_response)
31
31
  end
32
- rescue *NetworkErrors
32
+ rescue *NETWORK_ERRORS
33
33
  Failure(status: 400, code: :keycloak_unavailable)
34
34
  rescue JSON::ParserError
35
35
  Failure(status: 400, code: :json_parser_error)
@@ -19,14 +19,14 @@ module Hydra
19
19
  @data = ::JWT.decode(source, nil, false).first.transform_keys(&:to_sym)
20
20
  end
21
21
 
22
- %i(exp iat auth_time iss session_state scope jti).each do |field|
22
+ %i[exp iat auth_time iss session_state scope jti].each do |field|
23
23
  define_method(field) do
24
24
  @data.fetch(field)
25
25
  end
26
26
  end
27
27
 
28
28
  def [](key)
29
- @data.fetch(key)
29
+ @data[key]
30
30
  end
31
31
  end
32
32
  end
@@ -16,7 +16,7 @@ module Hydra
16
16
  "nonce=#{@config[:secret]}&" \
17
17
  'scope=openid&' \
18
18
  "code_challenge=#{code_challenge}&" \
19
- "code_challenge_method=S256"
19
+ 'code_challenge_method=S256'
20
20
  end
21
21
 
22
22
  def token_endpoint
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Hydra
4
4
  module Keycloak
5
- VERSION = '0.1.6'
5
+ VERSION = '0.1.9'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-keycloak-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fedor Kosolapov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-16 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: jwt
14
+ name: dalli
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: dalli
28
+ name: jwt
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: dry-monads
56
+ name: dry-auto_inject
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: dry-auto_inject
70
+ name: dry-container
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: dry-container
84
+ name: dry-monads
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -131,6 +131,9 @@ executables:
131
131
  extensions: []
132
132
  extra_rdoc_files: []
133
133
  files:
134
+ - ".github/workflows/main.yml"
135
+ - ".rubocop.yml"
136
+ - Dockerfile.test
134
137
  - Gemfile
135
138
  - Gemfile.lock
136
139
  - README.md
@@ -148,7 +151,6 @@ files:
148
151
  - lib/hydra/keycloak/store/redis_client.rb
149
152
  - lib/hydra/keycloak/token.rb
150
153
  - lib/hydra/keycloak/urls.rb
151
- - lib/hydra/keycloak/user_data.rb
152
154
  - lib/hydra/keycloak/version.rb
153
155
  homepage: https://github.com/latera/hydra-keycloak-client
154
156
  licenses: []
@@ -165,14 +167,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
165
167
  requirements:
166
168
  - - ">="
167
169
  - !ruby/object:Gem::Version
168
- version: 2.3.0
170
+ version: 2.5.8
169
171
  required_rubygems_version: !ruby/object:Gem::Requirement
170
172
  requirements:
171
173
  - - ">="
172
174
  - !ruby/object:Gem::Version
173
175
  version: '0'
174
176
  requirements: []
175
- rubygems_version: 3.1.6
177
+ rubygems_version: 3.2.3
176
178
  signing_key:
177
179
  specification_version: 4
178
180
  summary: Keycloak client for SSO
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'dry/struct'
4
-
5
- module Hydra
6
- module Keycloak
7
- module Types
8
- include Dry.Types()
9
- end
10
-
11
- class UserData < Dry::Struct
12
- attribute :username, Types::String
13
- attribute :base_subject_id, Types::Coercible::Integer
14
- attribute :subj_group_id, Types::Coercible::Integer
15
- attribute :firm_id, Types::Coercible::Integer
16
- attribute :base_subject_first_name, Types::String
17
- attribute :jti, Types::String
18
- end
19
- end
20
- end