keycloak_ruby 0.1.1 → 0.1.2
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 +4 -4
- data/.ruby-version +1 -0
- data/README.md +33 -7
- data/lib/keycloak_ruby/authentication.rb +1 -0
- data/lib/keycloak_ruby/token_refresher.rb +1 -1
- data/lib/keycloak_ruby/version.rb +33 -39
- data/lib/keycloak_ruby.rb +9 -14
- metadata +33 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe23b854fa6a62cf06242aab5d164dbcc9174e14c925dc296f9ebd1537bd1403
|
4
|
+
data.tar.gz: 4ce5b1e227d240df6a9322346fccca4404f9f3519accd04989da8fde6c2ad6e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfb814621225d471d3121cd7a0f1e4543dea709f1e8251d58550bf6789e0f2a71d7d1882b2b1d90cfc2ec62730615f1a3c40e8cfb6839d54d9ae81385eea0108
|
7
|
+
data.tar.gz: ecf788e5417fc9f1f22f175fbc454a936552bf64776930cbc32076863db3b08031180b62f75168f5ebc7274fe6810a0bff5c30d51beda0764e51cafba5fc2f93
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.4.1
|
data/README.md
CHANGED
@@ -7,6 +7,9 @@ This library is designed to use Keycloak identification in Rails application
|
|
7
7
|
Add to Gemfile
|
8
8
|
|
9
9
|
```bash
|
10
|
+
# stable version
|
11
|
+
gem "keycloak_ruby"
|
12
|
+
# latest master
|
10
13
|
gem "keycloak_ruby", git: "https://github.com/sergey-arkhipov/keycloak_ruby.git"
|
11
14
|
|
12
15
|
```
|
@@ -17,7 +20,12 @@ Create initializer for omniauth manually or use generator (config/initializers/o
|
|
17
20
|
rails generate keycloak_ruby:install
|
18
21
|
```
|
19
22
|
|
20
|
-
Now under active development, so you need create manually:
|
23
|
+
Now under active development, so you need create controller and routes manually:
|
24
|
+
|
25
|
+
- include `KeycloakRuby::Authentication` in ApplicationController
|
26
|
+
- create `SeesionController`
|
27
|
+
- add routes to `routes.rb
|
28
|
+
`
|
21
29
|
|
22
30
|
```ruby
|
23
31
|
# ApplicationController
|
@@ -54,7 +62,29 @@ delete '/logout', to: 'sessions#destroy', as: :logout
|
|
54
62
|
|
55
63
|
```
|
56
64
|
|
57
|
-
It is assumed that you have a User model in Rails app
|
65
|
+
It is assumed that you have a `User` model in Rails app
|
66
|
+
|
67
|
+
### Configuration Warning
|
68
|
+
|
69
|
+
When using `ENV[...]` or `ENV.fetch(...)` inside your `config/keycloak.yml`, make sure the referenced environment variables are actually defined.
|
70
|
+
|
71
|
+
If any variable is missing, the application may crash at boot time with one of the following exceptions:
|
72
|
+
|
73
|
+
- `KeyError` - when using `ENV.fetch(...)` without a fallback default;
|
74
|
+
- `KeycloakRuby::Errors::ConfigurationError` - when a required value is `nil` or blank after config evaluation.
|
75
|
+
|
76
|
+
This issue can happen when building Docker images. To avoid this, **use safe defaults** via `ENV.fetch('VAR', 'fallback')`:
|
77
|
+
|
78
|
+
```yaml
|
79
|
+
production:
|
80
|
+
keycloak_url: <%= ENV.fetch('KEYCLOAK_URL', 'https://keycloak.example.com') %>
|
81
|
+
app_host: <%= ENV.fetch('DEFAULT_APP_HOST', 'https://app.example.com') %>
|
82
|
+
realm: <%= ENV.fetch('KEYCLOAK_REALM', 'my-realm') %>
|
83
|
+
admin_client_id: <%= ENV.fetch('KEYCLOAK_ADMIN_CLIENT_ID', 'admin-cli') %>
|
84
|
+
admin_client_secret: <%= ENV.fetch('KEYCLOAK_ADMIN_CLIENT_SECRET', 'changeme') %>
|
85
|
+
oauth_client_id: <%= ENV.fetch('KEYCLOAK_OAUTH_CLIENT_ID', 'my-client') %>
|
86
|
+
oauth_client_secret: <%= ENV.fetch('KEYCLOAK_OAUTH_CLIENT_SECRET', 'secret') %>
|
87
|
+
```
|
58
88
|
|
59
89
|
## Architecture Overview
|
60
90
|
|
@@ -145,13 +175,9 @@ sequenceDiagram
|
|
145
175
|
|
146
176
|
```
|
147
177
|
|
148
|
-
##
|
178
|
+
## Testing in application
|
149
179
|
|
150
180
|
For test purpose there mock helper sign_in(user)
|
151
181
|
|
152
182
|
- add `require "keycloak_ruby/testing/keycloak_helpers"` to keycloak_helper.rb
|
153
183
|
- add sign_in in tests `config.include KeycloakRuby::Testing::KeycloakHelpers`
|
154
|
-
|
155
|
-
```
|
156
|
-
|
157
|
-
```
|
@@ -1,62 +1,56 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# lib/keycloak_ruby/version.rb
|
4
|
-
# Module for interacting with Keycloak
|
5
4
|
module KeycloakRuby
|
6
|
-
#
|
7
|
-
#
|
5
|
+
# The current version of the KeycloakRuby gem as a string.
|
6
|
+
# Follows Semantic Versioning 2.0 (https://semver.org)
|
7
|
+
# @example
|
8
|
+
# KeycloakRuby::VERSION # => "0.1.2"
|
9
|
+
VERSION = "0.1.2"
|
10
|
+
|
11
|
+
# Provides version information and comparison methods for the KeycloakRuby gem.
|
12
|
+
# This module follows Semantic Versioning 2.0 guidelines.
|
8
13
|
#
|
9
14
|
# @example Getting version information
|
10
|
-
# KeycloakRuby::Version
|
11
|
-
# KeycloakRuby::Version.
|
12
|
-
# KeycloakRuby::Version.
|
13
|
-
# KeycloakRuby.version # => "0.1.0"
|
15
|
+
# KeycloakRuby::Version.to_a # => [0, 1, 1]
|
16
|
+
# KeycloakRuby::Version.to_h # => { major: 0, minor: 1, patch: 1 }
|
17
|
+
# KeycloakRuby::Version.to_s # => "0.1.1"
|
14
18
|
#
|
15
|
-
# @example
|
16
|
-
# KeycloakRuby::Version >= '0.1.0'
|
17
|
-
#
|
19
|
+
# @example Version comparison
|
20
|
+
# KeycloakRuby::Version >= '0.1.0' # => true
|
21
|
+
# KeycloakRuby::Version >= '1.0.0' # => false
|
18
22
|
module Version
|
19
|
-
#
|
20
|
-
|
21
|
-
#
|
22
|
-
|
23
|
-
# Patch version number (backwards-compatible bug fixes)
|
24
|
-
PATCH = 1
|
25
|
-
# Pre-release version (nil for stable releases)
|
26
|
-
PRE = nil
|
27
|
-
|
28
|
-
# Full version string
|
29
|
-
VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join(".").freeze
|
30
|
-
|
31
|
-
# Returns version components as an array
|
32
|
-
# @return [Array<Integer, Integer, Integer, String|nil>]
|
23
|
+
# Returns the version components as an array of integers
|
24
|
+
# @return [Array<Integer>] the version components [major, minor, patch]
|
25
|
+
# @example
|
26
|
+
# KeycloakRuby::Version.to_a # => [0, 1, 1]
|
33
27
|
def self.to_a
|
34
|
-
|
28
|
+
VERSION.split(".").map(&:to_i)
|
35
29
|
end
|
36
30
|
|
37
|
-
# Returns version components as a hash
|
38
|
-
# @return [Hash<Symbol, Integer
|
31
|
+
# Returns the version components as a hash with symbols
|
32
|
+
# @return [Hash<Symbol, Integer>] the version components {major:, minor:, patch:}
|
33
|
+
# @example
|
34
|
+
# KeycloakRuby::Version.to_h # => { major: 0, minor: 1, patch: 1 }
|
39
35
|
def self.to_h
|
40
|
-
{ major:
|
36
|
+
{ major: to_a[0], minor: to_a[1], patch: to_a[2] }
|
41
37
|
end
|
42
38
|
|
43
|
-
# Compares version with another version string
|
44
|
-
# @param version_string [String] version to compare with (e.g
|
45
|
-
# @return [Boolean]
|
39
|
+
# Compares the current version with another version string
|
40
|
+
# @param version_string [String] the version to compare with (e.g. "1.2.3")
|
41
|
+
# @return [Boolean] true if current version is greater or equal
|
42
|
+
# @example
|
43
|
+
# KeycloakRuby::Version >= '0.1.0' # => true
|
46
44
|
def self.>=(version_string)
|
47
45
|
Gem::Version.new(VERSION) >= Gem::Version.new(version_string)
|
48
46
|
end
|
49
47
|
|
50
|
-
# Returns the
|
51
|
-
# @return [String]
|
48
|
+
# Returns the version string
|
49
|
+
# @return [String] the version string
|
50
|
+
# @example
|
51
|
+
# KeycloakRuby::Version.to_s # => "0.1.1"
|
52
52
|
def self.to_s
|
53
53
|
VERSION
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
57
|
-
# Returns the current gem version
|
58
|
-
# @return [String]
|
59
|
-
def self.version
|
60
|
-
Version::VERSION
|
61
|
-
end
|
62
56
|
end
|
data/lib/keycloak_ruby.rb
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# lib/keycloak_ruby.rb
|
3
4
|
require "omniauth"
|
4
5
|
require "omniauth_openid_connect"
|
5
6
|
require "httparty"
|
6
7
|
require "jwt"
|
8
|
+
require "zeitwerk"
|
9
|
+
|
10
|
+
loader = Zeitwerk::Loader.for_gem
|
11
|
+
loader.ignore(
|
12
|
+
"#{__dir__}/generators",
|
13
|
+
"#{__dir__}/templates"
|
14
|
+
)
|
15
|
+
loader.setup
|
7
16
|
|
8
|
-
# lib/keycloak_ruby.rb
|
9
17
|
require "generators/keycloak_ruby/install_generator" if defined?(Rails)
|
10
|
-
require "keycloak_ruby/authentication"
|
11
|
-
require "keycloak_ruby/client"
|
12
|
-
require "keycloak_ruby/config"
|
13
|
-
require "keycloak_ruby/errors"
|
14
|
-
require "keycloak_ruby/request_params"
|
15
|
-
require "keycloak_ruby/request_performer"
|
16
|
-
require "keycloak_ruby/response_validator"
|
17
|
-
require "keycloak_ruby/token_refresher"
|
18
|
-
require "keycloak_ruby/token_service"
|
19
|
-
require "keycloak_ruby/user"
|
20
|
-
require "keycloak_ruby/version"
|
21
18
|
|
22
19
|
# Module for interacting with Keycloak
|
23
20
|
module KeycloakRuby
|
@@ -56,8 +53,6 @@ module KeycloakRuby
|
|
56
53
|
config.validate!
|
57
54
|
end
|
58
55
|
end
|
59
|
-
VERSION = Version::VERSION
|
60
|
-
# Only load test helpers when in test environment
|
61
56
|
# Load test helpers only in test environment
|
62
57
|
if ENV["RACK_ENV"] == "test" || ENV["RAILS_ENV"] == "test" || defined?(RSpec) || defined?(Minitest)
|
63
58
|
require "keycloak_ruby/testing"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keycloak_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Arkhipov
|
8
8
|
- Georgy Shcherbakov
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '8.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '8.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: httparty
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +80,20 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: zeitwerk
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.7'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.7'
|
69
97
|
description: Library for using keycloak authentication with Rails
|
70
98
|
email:
|
71
99
|
- sergey-arkhipov@ya.ru
|
@@ -76,6 +104,7 @@ extra_rdoc_files: []
|
|
76
104
|
files:
|
77
105
|
- ".rspec_status"
|
78
106
|
- ".rubocop.yml"
|
107
|
+
- ".ruby-version"
|
79
108
|
- CHANGELOG.md
|
80
109
|
- CODE_OF_CONDUCT.md
|
81
110
|
- LICENSE
|
@@ -105,7 +134,7 @@ licenses:
|
|
105
134
|
metadata:
|
106
135
|
homepage_uri: https://github.com/sergey-arkhipov/keycloak_ruby
|
107
136
|
documentation_uri: https://github.com/sergey-arkhipov/keycloak_ruby/blob/master/README.md
|
108
|
-
changelog_uri: https://github.com/
|
137
|
+
changelog_uri: https://github.com/sergey-arkhipov/keycloak_ruby/blob/main/CHANGELOG.md
|
109
138
|
source_code_uri: https://github.com/sergey-arkhipov/keycloak_ruby
|
110
139
|
bug_tracker_uri: https://github.com/sergey-arkhipov/keycloak_ruby/issues
|
111
140
|
rubygems_mfa_required: 'true'
|
@@ -116,7 +145,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
116
145
|
requirements:
|
117
146
|
- - ">="
|
118
147
|
- !ruby/object:Gem::Version
|
119
|
-
version: '3.
|
148
|
+
version: '3.3'
|
120
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
150
|
requirements:
|
122
151
|
- - ">="
|