hydra-keycloak-client 0.1.2 → 0.1.6

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: 93ed59551d635025a4a76ab967423d7e843d55b0bbf610031f9052beb2665025
4
- data.tar.gz: 145a8edd04df4e4b82390b416a95fc03b927912f7bf0d08c56277272d94c83c2
3
+ metadata.gz: 18c487395b0610c378e53e63bd831b32c74f599f4fcd7fad8827698bd645dcfc
4
+ data.tar.gz: 0b31711516d5f351b1c82bca9164462f124595eb40d7dc790316e6d43c7c08b0
5
5
  SHA512:
6
- metadata.gz: 4697202b19f50c961d01af3e366400c1380d57012e978a183cd87b016d7b8e058450a0f557575077d83b63aeb29373e4475799f0c44bfa86b207fc9b94858fe4
7
- data.tar.gz: e6b43f7dcf759ec91c780cf92ba5ed682a6fcf2e3a7eb7fb0cf8b1fdcb35d82c7eb50e23d32aff2966c33c1af0c8751f462df3376d88d022fbb6b23724880276
6
+ metadata.gz: 0ed1cb5e7793a4ab45473551345d1ee6eca95d8ad349e3fd9023cd5f7282edf4cdcc87598bb9bc86de2797cc3ff0198d6f458817f0ded485745ef4d4dc3229da
7
+ data.tar.gz: 925857eea90aa7a6008f66febe1dadfa02820f72c0ca5ae2ec7cd24c20890c417a5268f2ad033084782d141706d47449f27d6c0797ef6b77e6899922f2ccc1d3
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,7 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hydra-keycloak-client (0.1.0)
4
+ hydra-keycloak-client (0.1.5)
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/
@@ -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
@@ -16,6 +16,17 @@ module Hydra
16
16
  extend ::Hydra::Keycloak::Mixin
17
17
 
18
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)
23
+ end
24
+
25
+ redis_schema = Dry::Schema.JSON do
26
+ required(:redis_host).filled(:string)
27
+ required(:redis_port).filled(:string)
28
+ end
29
+
19
30
  config_schema = Dry::Schema.JSON do
20
31
  required(:auth_server_url).filled(:string)
21
32
  required(:realm).filled(:string)
@@ -24,17 +35,7 @@ module Hydra
24
35
  required(:secret).filled(:string)
25
36
  required(:logout_redirect).filled(:string)
26
37
  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
38
+ required(:store_client_options).hash(memcached_schema | redis_schema)
38
39
  end
39
40
 
40
41
  validated_config = config_schema.call(config)
@@ -55,7 +56,7 @@ module Hydra
55
56
  ::Hydra::Keycloak::Queries::Gateway.new
56
57
  end
57
58
 
58
- if validated_config[:store_client] == :redis
59
+ if validated_config[:store_client] == 'redis'
59
60
  container.register :redis do
60
61
  require 'redis'
61
62
 
@@ -67,13 +68,13 @@ module Hydra
67
68
 
68
69
  ::Hydra::Keycloak::Store::RedisClient.new
69
70
  end
70
- else validated_config[:store_client] == :memcached
71
+ elsif validated_config[:store_client] == 'memcached'
71
72
  container.register :dalli do
72
73
  require 'dalli'
73
74
 
74
75
  ::Dalli::Client.new(
75
- "#{validated_config[:memcached_host]}:#{validated_config[:memcached_port]}",
76
- namespace: validated_config[:memcached_namespace]
76
+ "#{validated_config[:store_client_options][:memcached_host]}:#{validated_config[:store_client_options][:memcached_port]}",
77
+ namespace: validated_config[:store_client_options][:memcached_namespace]
77
78
  )
78
79
  end
79
80
 
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'redis'
4
+ require 'dry/monads'
5
+ require 'dry/auto_inject'
6
+
7
+ module Hydra
8
+ module Keycloak
9
+ module Store
10
+ class RedisClient
11
+ extend ::Hydra::Keycloak::Mixin
12
+ include ::Dry::Monads[:result]
13
+ inject['redis']
14
+
15
+ def set(key, value)
16
+ redis.set(key, value)
17
+
18
+ Success(:ok)
19
+ rescue Redis::BaseError
20
+ Failure(status: 400, code: :redis_unavailable)
21
+ end
22
+
23
+ def get(key)
24
+ Success(redis.get(key))
25
+ rescue Redis::BaseError
26
+ Failure(status: 400, code: :redis_unavailable)
27
+ end
28
+
29
+ def delete(key)
30
+ redis.del(key)
31
+
32
+ Success(:ok)
33
+ rescue Redis::BaseError
34
+ Failure(status: 400, code: :redis_unavailable)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Hydra
4
4
  module Keycloak
5
- VERSION = '0.1.2'
5
+ VERSION = '0.1.6'
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.2
4
+ version: 0.1.6
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-02-16 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
@@ -33,6 +145,7 @@ files:
33
145
  - lib/hydra/keycloak/queries/http_client.rb
34
146
  - lib/hydra/keycloak/store/gateway.rb
35
147
  - lib/hydra/keycloak/store/memcached_client.rb
148
+ - lib/hydra/keycloak/store/redis_client.rb
36
149
  - lib/hydra/keycloak/token.rb
37
150
  - lib/hydra/keycloak/urls.rb
38
151
  - lib/hydra/keycloak/user_data.rb