intercom-rails 1.0.5 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8672ce0798e1f6ed14669e026fb048640c70592e27a3d34e217a6bddb0cbf097
4
- data.tar.gz: e62b7cb80da4e200b47b4454b67e87c5a229702a6f626b471c117de433e28794
3
+ metadata.gz: 274c2855076beb153ba6dcf5ecdc639bcac1a2515bfe74a7042b84df61eab363
4
+ data.tar.gz: 59e0d09f3dca2b46db7e6e3829d39a89f75eef845c1608f690e87bad41505f0f
5
5
  SHA512:
6
- metadata.gz: f5ee15eb8b021131a761f45ac8a749a7c2ecec50813c7d0befdb6aa59a9b0f8281e9867a65b09bdbfdf4b5e2894ebebef940d03aae85618b4cb7490308f181b9
7
- data.tar.gz: 6a5b063fde892db61708f02a868af8fe2879a54225b2d471fcdd15fb4af654318b2a26af3d0e8f1eba9a99fc01ee2424af3a1b95e6cb849e26dbd61ea51b3527
6
+ metadata.gz: eebe74df506580a99a1fbe68857ab6c86c140e1db905c4cc96307aa0baa984b2d5efcf852eff43baaf7e6edb4b0937c2340a26b56f602339014478bf92e5c4bd
7
+ data.tar.gz: f3d98e2f4fa9083ba632faa4852028656e20c4b4c14c931dc3caa6dea429957efd9f0402b84be390dd2a97ee9bf0d002622206f455835277844d13f69e5b8aff
data/README.md CHANGED
@@ -69,6 +69,53 @@ It is possible to enable Identity Verification for the Intercom Messenger and yo
69
69
  ```
70
70
  **Note: This example is just for the sake of simplicity, you should never include this secret in source control. Instead, you should use the Rails [secret config](http://guides.rubyonrails.org/4_1_release_notes.html#config-secrets-yml) feature.**
71
71
 
72
+ ### JWT Authentication
73
+ You can enable JWT authentication for enhanced security with the Intercom Messenger. This feature uses JSON Web Tokens (JWTs) to authenticate users instead of the traditional user_hash method. To enable JWT authentication, add the following to your `config/initializers/intercom.rb`:
74
+
75
+ ```ruby
76
+ config.jwt.enabled = true
77
+ ```
78
+
79
+ #### JWT Expiry
80
+ You can set an expiry time for JWTs. This determines how long the token remains valid:
81
+
82
+ ```ruby
83
+ config.jwt.expiry = 12.hours # Token expires after 12 hours
84
+ ```
85
+
86
+ If no expiry is set, the JWT will not include an expiration claim.
87
+
88
+ #### Signed User Fields
89
+ You can specify which user fields should be included in the JWT payload and removed from the client-side settings for enhanced security:
90
+
91
+ ```ruby
92
+ config.jwt.signed_user_fields = [:email, :name, :plan, :team_id]
93
+ ```
94
+
95
+ With this configuration, these fields will be:
96
+ - Included in the signed JWT payload
97
+ - Removed from the client-side `intercomSettings` object
98
+ - Still available to Intercom through the secure JWT
99
+
100
+ #### Per-Request JWT Configuration
101
+ You can also configure JWT settings on a per-request basis using the `intercom_script_tag` helper:
102
+
103
+ ```erb
104
+ <%= intercom_script_tag({
105
+ :user_id => current_user.id,
106
+ :email => current_user.email
107
+ }, {
108
+ :jwt_enabled => true,
109
+ :jwt_expiry => 1.hour
110
+ }) %>
111
+ ```
112
+
113
+ **Important Notes:**
114
+ - JWT authentication requires an `api_secret` to be configured
115
+ - JWT is only generated when a `user_id` is present
116
+ - When JWT is enabled, the `user_id` is removed from client-side settings and only included in the secure JWT
117
+ - Other configured signed fields are also removed from client-side settings when JWT is used
118
+
72
119
  ### Shutdown
73
120
  We make use of first-party cookies so that we can identify your users the next time they open your messenger. When people share devices with someone else, they might be able to see the most recently logged in user’s conversation history until the cookie expires. Because of this, it’s very important to properly shutdown Intercom when a user’s session on your app ends (either manually or due to an automated logout).
74
121
 
@@ -342,7 +389,7 @@ CSP support for automatic insertion exposes two namespaces that can be defined b
342
389
  - String CoreExtensions::IntercomRails::AutoInclude.csp_nonce_hook(controller)
343
390
  - nil CoreExtensions::IntercomRails::AutoInclude.csp_sha256_hook(controller, SHA-256 whitelist entry)
344
391
 
345
- For instance, a CSP nonce can be inserted using the [Twitter Secure Headers](https://github.com/twitter/secureheaders) gem with the following code:
392
+ For instance, a CSP nonce can be inserted using the [Github Secure Headers](https://github.com/github/secure_headers) gem with the following code:
346
393
  ```ruby
347
394
  module CoreExtensions
348
395
  module IntercomRails
@@ -145,6 +145,7 @@ module IntercomRails
145
145
 
146
146
  config_group :jwt do
147
147
  config_accessor :enabled
148
+ config_accessor :expiry
148
149
  config_accessor :signed_user_fields do |value|
149
150
  unless value.nil? || (value.kind_of?(Array) && value.all? { |v| v.kind_of?(Symbol) || v.kind_of?(String) })
150
151
  raise ArgumentError, "jwt.signed_user_fields must be an array of symbols or strings"
@@ -18,7 +18,7 @@ module IntercomRails
18
18
  include ::ActionView::Helpers::TagHelper
19
19
 
20
20
  attr_reader :user_details, :company_details, :show_everywhere, :session_duration
21
- attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode, :jwt_enabled
21
+ attr_accessor :secret, :widget_options, :controller, :nonce, :encrypted_mode_enabled, :encrypted_mode, :jwt_enabled, :jwt_expiry
22
22
 
23
23
  def initialize(options = {})
24
24
  self.secret = options[:secret] || Config.api_secret
@@ -27,6 +27,7 @@ module IntercomRails
27
27
  @show_everywhere = options[:show_everywhere]
28
28
  @session_duration = session_duration_from_config
29
29
  self.jwt_enabled = options[:jwt_enabled] || Config.jwt.enabled
30
+ self.jwt_expiry = options[:jwt_expiry] || Config.jwt.expiry
30
31
 
31
32
  initial_user_details = if options[:find_current_user_details]
32
33
  find_current_user_details
@@ -124,10 +125,11 @@ module IntercomRails
124
125
  def generate_jwt
125
126
  return nil unless user_details[:user_id].present?
126
127
 
127
- payload = {
128
- user_id: user_details[:user_id].to_s,
129
- exp: 24.hours.from_now.to_i
130
- }
128
+ payload = { user_id: user_details[:user_id].to_s }
129
+
130
+ if jwt_expiry
131
+ payload[:exp] = jwt_expiry.from_now.to_i
132
+ end
131
133
 
132
134
  if Config.jwt.signed_user_fields.present?
133
135
  Config.jwt.signed_user_fields.each do |field|
@@ -1,3 +1,3 @@
1
1
  module IntercomRails
2
- VERSION = "1.0.5"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intercom-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben McRedmond
8
8
  - Ciaran Lee
9
9
  - Darragh Curran
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2024-12-20 00:00:00.000000000 Z
12
+ date: 1980-01-02 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activesupport
@@ -30,14 +29,14 @@ dependencies:
30
29
  name: jwt
31
30
  requirement: !ruby/object:Gem::Requirement
32
31
  requirements:
33
- - - "~>"
32
+ - - ">="
34
33
  - !ruby/object:Gem::Version
35
34
  version: '2.0'
36
35
  type: :runtime
37
36
  prerelease: false
38
37
  version_requirements: !ruby/object:Gem::Requirement
39
38
  requirements:
40
- - - "~>"
39
+ - - ">="
41
40
  - !ruby/object:Gem::Version
42
41
  version: '2.0'
43
42
  - !ruby/object:Gem::Dependency
@@ -187,7 +186,6 @@ homepage: http://www.intercom.io
187
186
  licenses:
188
187
  - MIT
189
188
  metadata: {}
190
- post_install_message:
191
189
  rdoc_options: []
192
190
  require_paths:
193
191
  - lib
@@ -202,8 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
200
  - !ruby/object:Gem::Version
203
201
  version: '0'
204
202
  requirements: []
205
- rubygems_version: 3.5.22
206
- signing_key:
203
+ rubygems_version: 4.0.3
207
204
  specification_version: 4
208
205
  summary: Rails helper for emitting javascript script tags for Intercom
209
206
  test_files: []