keycloak-api-rails 0.8 → 0.10
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d291e8d66fe760d36ba51a38fdc340cf73ba70a
|
4
|
+
data.tar.gz: aa7a777c5708e2e427ba135489e1547f065e315d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02ccaced32e6599c226300f48246c97a8ffdfdd3ef2adb85d6cde4862c4f3375e2695636f3fd0a51ca6f437fc4f66f6494a8c2d4bd20a5c1b6fb962dc7591cfc
|
7
|
+
data.tar.gz: 5577788c4255d19f5f62e46f2989ee0b33167cf9af8461dd19b9d29d3c6588eb3766bc8473533a8a1c71792910c0c45fe82908c81c7d822148303fea7a4c47e3
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ This gem aims at validates Keycloak JWT token in Ruby On Rails APIs.
|
|
5
5
|
## Install
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
gem "keycloak-api-rails", "0.
|
8
|
+
gem "keycloak-api-rails", "0.10"
|
9
9
|
```
|
10
10
|
|
11
11
|
## Token validation
|
@@ -41,6 +41,7 @@ All options have a default value. However, all of them can be changed in your in
|
|
41
41
|
| `skip_paths` | `{}`| Hash of methods and paths regexp | Optional | Paths whose the token must not be validatefd | `{ get: [/^\/health\/.+/] }`|
|
42
42
|
| `token_expiration_tolerance_in_seconds` | `10`| Logger | Optional | Number of seconds a token can expire before being rejected by the API. | `15` |
|
43
43
|
| `public_key_cache_ttl` | `86400`| Integer | Optional | Amount of time, in seconds, specifying maximum interval between two requests to {project_name} to retrieve new public keys. It is 86400 seconds (1 day) by default. At least once per this configured interval (1 day by default) will be new public key always downloaded. | `Rails.logger` |
|
44
|
+
| `custom_attributes` | `[]`| Array Of String | Optional | List of token attributes to read from each token and to add to their http request env | `["originalFirstName", "originalLastName"]` |
|
44
45
|
|
45
46
|
## Configure it
|
46
47
|
|
data/lib/keycloak-api-rails.rb
CHANGED
@@ -4,6 +4,7 @@ module Keycloak
|
|
4
4
|
CURRENT_USER_ID_KEY = "keycloak:keycloak_id"
|
5
5
|
CURRENT_USER_EMAIL_KEY = "keycloak:email"
|
6
6
|
CURRENT_USER_LOCALE_KEY = "keycloak:locale"
|
7
|
+
CURRENT_USER_ATTRIBUTES = "keycloak:attributes"
|
7
8
|
ROLES_KEY = "keycloak:roles"
|
8
9
|
QUERY_STRING_TOKEN_KEY = "authorizationToken"
|
9
10
|
|
@@ -39,6 +40,18 @@ module Keycloak
|
|
39
40
|
env[ROLES_KEY] = token.dig("realm_access", "roles")
|
40
41
|
end
|
41
42
|
|
43
|
+
def self.assign_current_user_custom_attributes(env, token, attribute_names)
|
44
|
+
env[CURRENT_USER_ATTRIBUTES] = token.select { |key,value| attribute_names.include?(key) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.current_user_custom_attributes(env)
|
48
|
+
env[CURRENT_USER_ATTRIBUTES]
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.current_user_roles(env)
|
52
|
+
env[ROLES_KEY]
|
53
|
+
end
|
54
|
+
|
42
55
|
def self.read_token_from_query_string(uri)
|
43
56
|
parsed_uri = URI.parse(uri)
|
44
57
|
query = URI.decode_www_form(parsed_uri.query || "")
|
@@ -32,6 +32,7 @@ module Keycloak
|
|
32
32
|
Helper.assign_current_user_id(env, decoded_token)
|
33
33
|
Helper.assign_current_user_email(env, decoded_token)
|
34
34
|
Helper.assign_current_user_locale(env, decoded_token)
|
35
|
+
Helper.assign_current_user_custom_attributes(env, decoded_token, config.custom_attributes)
|
35
36
|
Helper.assign_realm_roles(env, decoded_token)
|
36
37
|
@app.call(env)
|
37
38
|
end
|
@@ -43,5 +44,9 @@ module Keycloak
|
|
43
44
|
def logger
|
44
45
|
Keycloak.logger
|
45
46
|
end
|
47
|
+
|
48
|
+
def config
|
49
|
+
Keycloak.config
|
50
|
+
end
|
46
51
|
end
|
47
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keycloak-api-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.10'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lorent Lempereur
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|