api_keys 0.8.1 → 0.9.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: dca5913a99885ff5a5560a108e15d1ed8c81ef82347f6bdc3606559cf5a47ef2
4
- data.tar.gz: 574b8fa3df8e307bbe24c03292acb754ef44f8453dbda17719b3e3b36eae74a5
3
+ metadata.gz: e5e832f996edf9ca24dad2920383f19b80aaebb5c56c9243154048fc5f5621b5
4
+ data.tar.gz: d1c674160db7740b3791792e79e00c3d3f940c2c89aa9cc4eb8993977775d384
5
5
  SHA512:
6
- metadata.gz: ab7dcee45ad1c6efae2156ee2c3e1e10745ad09f4a2d4b4eed1e2d120bf78e91fe9bfdb9919aeba87b91c2ad13720bf93f9e98802053fd73f3032c1033c4f945
7
- data.tar.gz: 45672849171455b8bdb2c4af0df5413fe0f693d36556e35a053cb64c184e239ee646d11776ac9d9f169b82891839ff5ab30a867ca20d5eb3037a740c8baec826
6
+ metadata.gz: 81a6c5e402cce5cc57d3bee554c057389081fbfb95e60aec758138f2288cbbc3c9c297631f9fb24ad7363857d27c42bd7ea36831752a5adc15c74ccb0574a9e1
7
+ data.tar.gz: eebf27adfe99ab49b6c48ff9fe8f3685ea24d50d6b67b93074adf4ec6108d04b2cfc0dddbcf32377e0ed69f6a5276a4f6129cfe9fc163d7a5a7db2913943d852
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.9.0] - 2026-11-09
2
+
3
+ ### Added
4
+
5
+ - `config.current_creator_method`. The dashboard records the signed-in person it names (e.g. `:current_user`) as each new key's `created_by`. Before, the dashboard never set `created_by`, so in an app where organizations own keys, nobody could tell who minted a key, and a `config.trusted_key_check` that reads `created_by` refused every dashboard-created key. Default nil records nobody, as before. Set but missing on the host controller, key creation fails instead of minting an unattributed key. Needs the created_by columns (0.7.0).
6
+
1
7
  ## [0.8.1] - 2026-10-26
2
8
 
3
9
  Two fixes found when an app on the fleet upgraded from 0.5 to 0.8.0. The second one now covers every upgrade generator.
data/README.md CHANGED
@@ -151,9 +151,14 @@ ApiKeys.configure do |config|
151
151
 
152
152
  # Tell the dashboard how to ensure the owner is authenticated
153
153
  config.authenticate_owner_method = :authenticate_organization!
154
+
155
+ # Record who minted each key (needs the created_by columns, 0.7.0+)
156
+ config.current_creator_method = :current_user
154
157
  end
155
158
  ```
156
159
 
160
+ With `current_creator_method` set, every key the dashboard creates stores the signed-in person as `created_by`, so an organization can see who made each key, and `config.trusted_key_check` can judge dashboard-created keys. Left unset, the dashboard records nobody, as before 0.9.0.
161
+
157
162
  These methods must exist in your `ApplicationController` (or wherever the engine is mounted). For example:
158
163
 
159
164
  ```ruby
@@ -186,6 +191,7 @@ The setting accepts a controller class or a valid constant-name string and defau
186
191
  # When organizations own keys but users manage them
187
192
  config.current_owner_method = :current_organization
188
193
  config.authenticate_owner_method = :require_organization_member!
194
+ config.current_creator_method = :current_user
189
195
  ```
190
196
 
191
197
  **Multi-tenant applications:**
@@ -118,6 +118,22 @@ module ApiKeys
118
118
  end
119
119
  end
120
120
 
121
+ # The signed-in person, recorded as a new key's created_by
122
+ # (config.current_creator_method). nil when unconfigured. Configured but
123
+ # missing on the host controller fails loudly: a key minted without its
124
+ # creator could later fail config.trusted_key_check for everyone.
125
+ def current_api_keys_creator
126
+ creator_method = ApiKeys.configuration.current_creator_method
127
+ return nil unless creator_method
128
+
129
+ unless respond_to?(creator_method, true)
130
+ raise NoMethodError, "config.current_creator_method is #{creator_method.inspect}, " \
131
+ "but #{self.class.name} does not respond to it"
132
+ end
133
+
134
+ send(creator_method)
135
+ end
136
+
121
137
  # Expose current_api_keys_owner as a helper method for views
122
138
  helper_method :current_api_keys_owner
123
139
 
@@ -93,8 +93,8 @@ module ApiKeys
93
93
  key_type: submitted_params[:key_type].presence,
94
94
  # The model normalizes these raw strings; no parser needed here.
95
95
  allowed_origins: submitted_params[:allowed_origins],
96
- allowed_ips: submitted_params[:allowed_ips]
97
- # Metadata could be added here if needed
96
+ allowed_ips: submitted_params[:allowed_ips],
97
+ created_by: current_api_keys_creator
98
98
  )
99
99
 
100
100
  # Store the plaintext token in session to display on the show page
@@ -38,6 +38,20 @@ module ApiKeys
38
38
  # Owner Context Configuration
39
39
  attr_reader :current_owner_method, :authenticate_owner_method
40
40
 
41
+ # The person behind a dashboard-created key
42
+ #
43
+ # @!attribute [rw] current_creator_method
44
+ # @return [Symbol, String, nil] Controller method that returns the signed-in
45
+ # person (e.g. :current_user). When set, the dashboard records it as the
46
+ # new key's `created_by`, so an organization-owned key says who minted it
47
+ # and `config.trusted_key_check` can judge dashboard-created keys. Needs
48
+ # the created_by columns (`rails g api_keys:add_created_by`). nil (the
49
+ # default) records nobody, as before.
50
+ # @example Organization-owned keys
51
+ # config.current_owner_method = :current_organization
52
+ # config.current_creator_method = :current_user
53
+ attr_reader :current_creator_method
54
+
41
55
  # Optional Behaviors
42
56
  attr_reader :default_max_keys_per_owner, :require_key_name
43
57
  attr_reader :expire_after, :default_scopes, :track_requests_count
@@ -354,6 +368,10 @@ module ApiKeys
354
368
  @authenticate_owner_method = validate_method_name!(value, :authenticate_owner_method)
355
369
  end
356
370
 
371
+ def current_creator_method=(value)
372
+ @current_creator_method = validate_method_name!(value, :current_creator_method)
373
+ end
374
+
357
375
  def current_environment=(value)
358
376
  unless value.nil? || value.respond_to?(:call) || valid_config_name?(value)
359
377
  raise ArgumentError, "current_environment must be callable, a safe String/Symbol, or nil"
@@ -660,6 +678,7 @@ module ApiKeys
660
678
  # Owner Context Configuration
661
679
  @current_owner_method = :current_user # Default to current_user for backward compatibility
662
680
  @authenticate_owner_method = :authenticate_user! # Default to authenticate_user! for Devise compatibility
681
+ @current_creator_method = nil
663
682
 
664
683
  # Optional Behaviors
665
684
  @default_max_keys_per_owner = nil # No global key limit per owner
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiKeys
4
- VERSION = "0.8.1"
4
+ VERSION = "0.9.0"
5
5
  end
@@ -48,6 +48,15 @@ ApiKeys.configure do |config|
48
48
  # Example for Organization-owned keys:
49
49
  # config.authenticate_owner_method = :authenticate_organization!
50
50
 
51
+ # The method that returns the signed-in person, recorded as a new key's
52
+ # created_by when the dashboard mints it. Set it when keys belong to an
53
+ # organization, so each key says who created it. Needs the created_by
54
+ # columns (rails g api_keys:add_created_by).
55
+ # Default: nil (records nobody)
56
+ #
57
+ # Example for Organization-owned keys:
58
+ # config.current_creator_method = :current_user
59
+
51
60
  # Dashboard environment filtering (only applies when key_types is configured).
52
61
  # When false (default), dashboard only shows keys matching current_environment.
53
62
  # When true, dashboard shows keys from all environments.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_keys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rameerez
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2026-11-09 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rails
@@ -167,7 +167,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
169
  requirements: []
170
- rubygems_version: 3.6.9
170
+ rubygems_version: 3.6.2
171
171
  specification_version: 4
172
172
  summary: Gate your Rails API with secure, self-serve API keys in minutes
173
173
  test_files: []