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: 1dccb3ffb713201d9f49eff3c27ad657b739b149
4
- data.tar.gz: 2df036761b9f6f6c398d0c7efb562117ace84e26
3
+ metadata.gz: 1d291e8d66fe760d36ba51a38fdc340cf73ba70a
4
+ data.tar.gz: aa7a777c5708e2e427ba135489e1547f065e315d
5
5
  SHA512:
6
- metadata.gz: 5c0fa11f8adf1de64b83232581a3f2e8f11985c73e4b4db47f36b3af9039fd0baf569deb176d40ee9b7c1e3f7a42ad7676ea8cb4e98f61918751940ed5e05e6b
7
- data.tar.gz: 916976afd9cd7f77f5c587889a6ed01515a708216bf2bbc1ae4d01673b468f4cfd0d692d12d42a8d476718f4d621422afb6b1ad4cf88998d6d6771b3986b148c
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"
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
 
@@ -42,6 +42,7 @@ module Keycloak
42
42
  config.skip_paths = {}
43
43
  config.token_expiration_tolerance_in_seconds = 10
44
44
  config.public_key_cache_ttl = 86400
45
+ config.custom_attributes = []
45
46
  end
46
47
  end
47
48
 
@@ -6,6 +6,7 @@ module Keycloak
6
6
  config_accessor :skip_paths
7
7
  config_accessor :token_expiration_tolerance_in_seconds
8
8
  config_accessor :public_key_cache_ttl
9
+ config_accessor :custom_attributes
9
10
  config_accessor :logger
10
11
  end
11
12
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Keycloak
2
- VERSION = "0.8"
2
+ VERSION = "0.10"
3
3
  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.8'
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: 2018-05-25 00:00:00.000000000 Z
11
+ date: 2019-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails