authrocket 3.3.0 → 3.4.0

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
  SHA256:
3
- metadata.gz: 496c2639a6c1ce3fbee2aa2630cad8fda1d9e2d4b6dc599b1e67cbaa3aa9e73b
4
- data.tar.gz: 4b60926eeb42fe5c1a7676a40b144f097fd117dc6db5083e5c0990347d9e09cd
3
+ metadata.gz: 1081c944badcc582e41e1b6a2c490b7b36797072ce37c4c0d4ff95cff70c9a37
4
+ data.tar.gz: c3fb78aa005891773187d5dd3494b51746566b180c99358d41ec48fa9e46a6ee
5
5
  SHA512:
6
- metadata.gz: '08b37f9964636332dd7154a03a5d37074cf7e766dfc48f9add8e96e114ec8a518b9a1324e74a1063931d2e40b4fd07e146675e0f03f28ac5914bf48372b5efd5'
7
- data.tar.gz: 4269068e638a0451ca3af856101adf6d90660c0a68a8772e5b5625f3ebf1ec50b56fa8c2e2d69917086cc85f115bfc0f7afce708f580f547aaf837009862f348
6
+ metadata.gz: 71ae02ef915333191bc493a141c6ef9fa452184028cfb528ade5b264aa7323adb1a3d13d457566766b628246b892e19a2fa7587edefe57938f884f0da972ed15
7
+ data.tar.gz: 86634dae4a53d8dca492b409782c45a096db901adeee0ef5012ea7405782cf0ab6d9258a99c4ec6ba0514c405a8500b31991a9666e9e3a7aef55959982cfd4d3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ #### 3.4.0
2
+
3
+ - Document how to change locales
4
+ - Self-configure rescue_responses when using Rails
5
+ - Add request caching
6
+
1
7
  #### 3.3.0
2
8
 
3
9
  - Update Invitation, Hook, Realm, User
data/README.md CHANGED
@@ -159,7 +159,7 @@ This default path may be changed using an initializer. Create/edit `config/initi
159
159
 
160
160
  ##### /logout route
161
161
 
162
- The default route for logout is `/logout`. To overrideis, add an initializer for AuthRocket (eg: `config/initializers/authrocket.rb`) and add:
162
+ The default route for logout is `/logout`. To override it, add an initializer for AuthRocket (eg: `config/initializers/authrocket.rb`) and add:
163
163
 
164
164
  AuthRocket::Api.use_default_routes = false
165
165
 
@@ -206,11 +206,13 @@ AuthRocket's login tokens use the JWT standard and are cryptographically signed.
206
206
  AuthRocket also supports Managed Sessions, which enables you to enforce logouts, even across apps (single sign-out!). In this instance, the session is regularly verified using the AuthRocket API.
207
207
 
208
208
  def current_user
209
- @_current_user ||= AuthRocket::Session.retrieve(session[:ar_token])&.user
209
+ @_current_user ||= AuthRocket::Session.retrieve(session[:ar_token], cache: {expires_in: 15.minutes})&.user
210
210
  end
211
211
 
212
212
  For better performance (and to avoid API rate limits), you will want to cache the results of the API call for 3-15 minutes.
213
213
 
214
+ If not using Rails/ActiveSupport, use seconds: `cache: {expires_in: 15*60}` and also configure the cache store, as explained in Caching below. If using Rails, make sure Rails.cache is configured.
215
+
214
216
 
215
217
  #### Initial login
216
218
 
@@ -229,6 +231,66 @@ Each of the above are designed for ongoing use. The initial login isn't going to
229
231
 
230
232
 
231
233
 
234
+ ## Changing locales
235
+
236
+ The AuthRocket Core API supports multi-locale access. See the AuthRocket docs for the currently supported locales.
237
+
238
+ If you are using the streamlined Rails integration alongside LoginRocket, it may not be necessary to set the locale for API access. The locale is primarily used for generating localized error messages. This is only useful for API operations that might generate errors. When handling logins and signups via LoginRocket, LoginRocket will handle all of this for you.
239
+
240
+ When the Accept-Language header is not sent, the AuthRocket Core API uses English.
241
+
242
+
243
+ #### Global locale
244
+
245
+ To set a global locale for your app, add this to your AuthRocket initializer:
246
+
247
+ AuthRocket::Api.default_headers.merge!(
248
+ accept_language: 'en'
249
+ )
250
+
251
+
252
+ #### Per-request locale
253
+
254
+ If your app supports multiple locales, then you'll likely want to set the locale on a per-request basis. Add a `headers: {accept_language: 'en'}` param to relevant API calls:
255
+
256
+ AuthRocket::User.create(
257
+ email: 'jdoe@example.com',
258
+ password: 'secret!',
259
+ headers: {accept_language: 'en'}
260
+ )
261
+
262
+
263
+
264
+ ## Caching
265
+
266
+ The AuthRocket gem is capable of caching the results of GET requests. Since authentication and user data generally needs to be timely, this is opt-in on a per-request basis. The most common use is when validating sessions via the API.
267
+
268
+ To enable caching, a cache store must be configured. On Rails, `authrocket` automatically uses Rails.cache, so simply ensure that's setup appropriately.
269
+
270
+ If not using Rails (or if you with to use a different cache store even when using Rails), add this to your AuthRocket initializer:
271
+
272
+ cache_options = {} # app specific
273
+ AuthRocket::Api.cache_store = RedisCacheStore.new(cache_options)
274
+
275
+ Any Rails-compatible cache store should work.
276
+
277
+ Next, enable the cache for specific API calls:
278
+
279
+ # To avoid caching for too long, it's recommended to set a specific expiration time.
280
+ AuthRocket::Session.retrieve(token, cache: {expires_in: 5.minutes})
281
+
282
+ # However, it's possible to leave out :expires_in and use the cache store's default.
283
+ # Warning: Ensure the cache store has a default expiration, otherwise cache entries
284
+ # will last forever!
285
+ AuthRocket::Session.retrieve(token, cache: {}) # These are identical
286
+ AuthRocket::Session.retrieve(token, cache: true)
287
+
288
+ # All options in cache: {...} are passed directly to the cache store, so anything
289
+ # supported by your cache store is valid.
290
+ AuthRocket::Session.retrieve(token, cache: {expires_in: 15.minutes, force: true})
291
+
292
+
293
+
232
294
  ## Reference
233
295
 
234
296
  For full details on the AuthRocket API, including examples for Ruby, see our [documentation](https://authrocket.com/docs).
data/authrocket.gemspec CHANGED
@@ -24,6 +24,6 @@ Gem::Specification.new do |gem|
24
24
  gem.add_dependency 'ncore', '~> 3.0'
25
25
  gem.add_dependency 'jwt', '~> 2.1'
26
26
 
27
- gem.add_development_dependency "bundler", "~> 1.3"
27
+ gem.add_development_dependency "bundler"
28
28
  gem.add_development_dependency "rake"
29
29
  end
@@ -1,6 +1,15 @@
1
1
  module AuthRocket
2
2
  class Railtie < Rails::Railtie
3
3
 
4
+ config.action_dispatch.rescue_responses.merge!(
5
+ 'AuthRocket::RecordInvalid' => :unprocessable_entity, # 422
6
+ 'AuthRocket::RecordNotFound' => :not_found, # 404
7
+ )
8
+
9
+ initializer "authrocket.cache_store" do |app|
10
+ AuthRocket::Api.cache_store = Rails.cache
11
+ end
12
+
4
13
  initializer "authrocket.log_runtime" do |app|
5
14
  require 'authrocket/api/log_subscriber'
6
15
  ActiveSupport.on_load(:action_controller) do
@@ -1,3 +1,3 @@
1
1
  module AuthRocket
2
- VERSION = '3.3.0'
2
+ VERSION = '3.4.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authrocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AuthRocket Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-15 00:00:00.000000000 Z
11
+ date: 2021-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.3'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '1.3'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -145,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  requirements: []
148
- rubygems_version: 3.0.9
148
+ rubygems_version: 3.2.22
149
149
  signing_key:
150
150
  specification_version: 4
151
151
  summary: AuthRocket client for Ruby