hydra-keycloak-client 0.1.4 → 0.1.7

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: 6aeae2261cdd736e31e48d59e3d97f8a26e2e88b4b4793cad7377aed52e8de1c
4
- data.tar.gz: 29e84ab96e9f07e92dcfc150008ea627c843294e298e4f354884336ed903444d
3
+ metadata.gz: 291ce7dea090b7d863e9fd3d29c92bf035c64f940ef1b3c8d0fce955a54bf8fb
4
+ data.tar.gz: 94f719f340181a2cd5c12bd2d5eb070d53c6c1d55dbd1161f49249d6fd66b895
5
5
  SHA512:
6
- metadata.gz: a2fd68301e498dc7f69cc7193d177d3a025f8cf334af3f2b2bcea75f4d0bfa37c87511fc7e3eee5d1c19cc8138ff32bbf00f6f85fa2e94762e8f81d58f4694db
7
- data.tar.gz: 59948ba16738ba3eb18968220d90faa81eeeb3a80bc1aac07fc6f0624cd519af76d198eaa1d160b0693d3bfb39d23789ef0e5c1fc3e3e91789f63f5edf2ad7f2
6
+ metadata.gz: 3198cc3b6df1e02af1686bdbdaa8f12dae01e47da07d20635ba843c5df4ac2de833c56c9c1629c0603856360345439bc2aeb34596f383a2853e1386d29ca672a
7
+ data.tar.gz: b7f96f9134234bd3c337f8727409a9d1a984ab8d375a484b29b7c32e9721e4e6d82509cc0162490e5451599c98a895d84a17d9ab390a83559ec520b3276e74f3
@@ -0,0 +1,16 @@
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 tests
16
+ run: docker run hkc_test_image rspec
data/Dockerfile.test ADDED
@@ -0,0 +1,7 @@
1
+ FROM ruby:2.7.4
2
+
3
+ COPY . /app
4
+ WORKDIR /app
5
+
6
+ RUN bundle install
7
+ CMD bundle exec rspec
data/Gemfile CHANGED
@@ -6,14 +6,4 @@ gemspec
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
8
 
9
- gem 'jwt'
10
- gem 'dalli'
11
- gem 'redis'
12
-
13
- gem 'dry-monads'
14
- gem 'dry-auto_inject'
15
- gem 'dry-container'
16
- gem 'dry-schema'
17
- gem 'dry-struct'
18
-
19
9
  gem 'pry'
data/Gemfile.lock CHANGED
@@ -1,18 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hydra-keycloak-client (0.1.0)
4
+ hydra-keycloak-client (0.1.7)
5
+ dalli
6
+ dry-auto_inject
7
+ dry-container
8
+ dry-monads
9
+ dry-schema
10
+ dry-struct
11
+ jwt
12
+ redis
5
13
 
6
14
  GEM
7
15
  remote: https://rubygems.org/
8
16
  specs:
9
17
  coderay (1.1.3)
10
18
  concurrent-ruby (1.1.9)
11
- dalli (3.1.1)
19
+ dalli (3.2.1)
12
20
  diff-lcs (1.4.4)
13
- dry-auto_inject (0.8.0)
21
+ dry-auto_inject (0.9.0)
14
22
  dry-container (>= 0.3.4)
15
- dry-configurable (0.13.0)
23
+ dry-configurable (0.14.0)
16
24
  concurrent-ruby (~> 1.0)
17
25
  dry-core (~> 0.6)
18
26
  dry-container (0.9.0)
@@ -21,14 +29,14 @@ GEM
21
29
  dry-core (0.7.1)
22
30
  concurrent-ruby (~> 1.0)
23
31
  dry-inflector (0.2.1)
24
- dry-initializer (3.0.4)
32
+ dry-initializer (3.1.1)
25
33
  dry-logic (1.2.0)
26
34
  concurrent-ruby (~> 1.0)
27
35
  dry-core (~> 0.5, >= 0.5)
28
36
  dry-monads (1.4.0)
29
37
  concurrent-ruby (~> 1.0)
30
38
  dry-core (~> 0.7)
31
- dry-schema (1.8.0)
39
+ dry-schema (1.9.1)
32
40
  concurrent-ruby (~> 1.0)
33
41
  dry-configurable (~> 0.13, >= 0.13.0)
34
42
  dry-core (~> 0.5, >= 0.5)
@@ -71,17 +79,9 @@ PLATFORMS
71
79
  ruby
72
80
 
73
81
  DEPENDENCIES
74
- dalli
75
- dry-auto_inject
76
- dry-container
77
- dry-monads
78
- dry-schema
79
- dry-struct
80
82
  hydra-keycloak-client!
81
- jwt
82
83
  pry
83
84
  rake (~> 12.0)
84
- redis
85
85
  rspec (~> 3.0)
86
86
 
87
87
  BUNDLED WITH
data/README.md CHANGED
@@ -25,14 +25,25 @@ Create client instance for usage:
25
25
  ```
26
26
  keycloack_client = Hydra::Keycloak::ClientCreator.call(
27
27
  config: {
28
- auth_server_url: "http://0.0.0.0:8080/auth/",
29
- realm: "hydra",
30
- client_id: "hoper",
31
- redirect_uri: "http://localhost:3000/authenticate_by_keycloak",
32
- secret: "1fad7395-de0e-456a-a559-2896aa82f5e3",
33
- logout_redirect: "http://localhost:3000",
34
- memcached_host: "localhost",
35
- memcached_port: "11211",
36
- memcached_namespace: "hoper",
28
+ auth_server_url: keycloak_config.fetch(:auth_server_url),
29
+ realm: keycloak_config.fetch(:realm),
30
+ client_id: keycloak_config.fetch(:client_id),
31
+ redirect_uri: keycloak_config.fetch(:redirect_uri),
32
+ secret: keycloak_config.fetch(:secret),
33
+ logout_redirect: keycloak_config.fetch(:logout_redirect),
34
+ store_client: 'redis',
35
+ store_client_options: {redis_host: ENV['REDIS_HOST'], redis_port: ENV['REDIS_PORT']}
37
36
  })
38
37
  ```
38
+
39
+ or for memcached:
40
+
41
+ ```
42
+ ...
43
+ store_client: 'redis',
44
+ store_client_options: {
45
+ memcached_host: "localhost",
46
+ memcached_port: "11211",
47
+ memcached_namespace: "hoper",
48
+ }
49
+ ```
@@ -25,4 +25,14 @@ Gem::Specification.new do |spec|
25
25
  end
26
26
  spec.bindir = "bin"
27
27
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+
29
+ spec.add_dependency('jwt')
30
+ spec.add_dependency('dalli')
31
+ spec.add_dependency('redis')
32
+
33
+ spec.add_dependency('dry-monads')
34
+ spec.add_dependency('dry-auto_inject')
35
+ spec.add_dependency('dry-container')
36
+ spec.add_dependency('dry-schema')
37
+ spec.add_dependency('dry-struct')
28
38
  end
@@ -5,7 +5,6 @@ require 'dry/container'
5
5
  require 'dry/schema'
6
6
 
7
7
  require 'hydra/keycloak/container'
8
- require 'hydra/keycloak/user_data'
9
8
  require 'hydra/keycloak/code_verifier'
10
9
 
11
10
  module Hydra
@@ -16,6 +15,17 @@ module Hydra
16
15
  extend ::Hydra::Keycloak::Mixin
17
16
 
18
17
  def self.call(config:)
18
+ memcached_schema = Dry::Schema.JSON do
19
+ required(:memcached_host).filled(:string)
20
+ required(:memcached_port).filled(:string)
21
+ required(:memcached_namespace).filled(:string)
22
+ end
23
+
24
+ redis_schema = Dry::Schema.JSON do
25
+ required(:redis_host).filled(:string)
26
+ required(:redis_port).filled(:string)
27
+ end
28
+
19
29
  config_schema = Dry::Schema.JSON do
20
30
  required(:auth_server_url).filled(:string)
21
31
  required(:realm).filled(:string)
@@ -24,17 +34,7 @@ module Hydra
24
34
  required(:secret).filled(:string)
25
35
  required(:logout_redirect).filled(:string)
26
36
  required(:store_client).value(included_in?: ['redis', 'memcached'])
27
-
28
- optional(:memcached).hash do
29
- required(:memcached_host).filled(:string)
30
- required(:memcached_port).filled(:string)
31
- required(:memcached_namespace).filled(:string)
32
- end
33
-
34
- optional(:redis).hash do
35
- required(:redis_host).filled(:string)
36
- required(:redis_port).filled(:string)
37
- end
37
+ required(:store_client_options).hash(memcached_schema | redis_schema)
38
38
  end
39
39
 
40
40
  validated_config = config_schema.call(config)
@@ -67,13 +67,13 @@ module Hydra
67
67
 
68
68
  ::Hydra::Keycloak::Store::RedisClient.new
69
69
  end
70
- else validated_config[:store_client] == 'memcached'
70
+ elsif validated_config[:store_client] == 'memcached'
71
71
  container.register :dalli do
72
72
  require 'dalli'
73
73
 
74
74
  ::Dalli::Client.new(
75
- "#{validated_config[:memcached_host]}:#{validated_config[:memcached_port]}",
76
- namespace: validated_config[:memcached_namespace]
75
+ "#{validated_config[:store_client_options][:memcached_host]}:#{validated_config[:store_client_options][:memcached_port]}",
76
+ namespace: validated_config[:store_client_options][:memcached_namespace]
77
77
  )
78
78
  end
79
79
 
@@ -130,22 +130,6 @@ module Hydra
130
130
  fetch_token(session_state, 'access_token').success?
131
131
  end
132
132
 
133
- def user_data(session_state)
134
- unless authenticated?(session_state)
135
- return Failure(status: 400, code: :not_authenticated)
136
- end
137
-
138
- fetch_token(session_state, 'access_token').fmap do |access_token|
139
- UserData.new(
140
- username: access_token[:login],
141
- base_subject_id: access_token[:base_subject_id],
142
- subj_group_id: access_token[:subj_group_id],
143
- firm_id: access_token[:firm_id],
144
- base_subject_first_name: access_token[:base_subject_first_name],
145
- jti: access_token[:jti])
146
- end
147
- end
148
-
149
133
  def access_token(session_state)
150
134
  unless authenticated?(session_state)
151
135
  return Failure(status: 400, code: :not_authenticated)
@@ -26,7 +26,7 @@ module Hydra
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Hydra
4
4
  module Keycloak
5
- VERSION = '0.1.4'
5
+ VERSION = '0.1.7'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,15 +1,127 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hydra-keycloak-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.7
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-08 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jwt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dalli
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: redis
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dry-monads
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: dry-auto_inject
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: dry-container
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: dry-schema
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: dry-struct
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
13
125
  description: Keycloak client for SSO
14
126
  email:
15
127
  - f.kosolapov@latera.ru
@@ -19,6 +131,8 @@ executables:
19
131
  extensions: []
20
132
  extra_rdoc_files: []
21
133
  files:
134
+ - ".github/workflows/main.yml"
135
+ - Dockerfile.test
22
136
  - Gemfile
23
137
  - Gemfile.lock
24
138
  - README.md
@@ -36,7 +150,6 @@ files:
36
150
  - lib/hydra/keycloak/store/redis_client.rb
37
151
  - lib/hydra/keycloak/token.rb
38
152
  - lib/hydra/keycloak/urls.rb
39
- - lib/hydra/keycloak/user_data.rb
40
153
  - lib/hydra/keycloak/version.rb
41
154
  homepage: https://github.com/latera/hydra-keycloak-client
42
155
  licenses: []
@@ -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