globalid 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of globalid might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16fab50b5f1ed999f159d4e28507577d1e240e2a
4
- data.tar.gz: 00c55d5c1b1b3b09178e3c1e75dc343389acb92f
3
+ metadata.gz: 833f7e0950a55c0aa3a0e62176de2d163a395c05
4
+ data.tar.gz: 86b23bf6f2710971970c3a25a1301028184887f6
5
5
  SHA512:
6
- metadata.gz: ee2a00103d0a6890701acd2674a7817335391f54e67d44746c1883711329e5707d3c26089f5fe9823322fe044d52e9b7167ae8f0b7d86af1c88ff379d269f6e1
7
- data.tar.gz: 5da58eabadc4ddc3af4231520db1c3b09bc780ac8b842e4a93f70a6ab1523a81c7112d5377569b2643b755e4c06cb9e764b75e9b1078fa41b48f909f02ed25d3
6
+ metadata.gz: 497931559ea0b7aa8d21b9ea2dfb4ae219739a8449763e2dad590c5b30f1cb4675b66841837f3f43c7480698dbbd478e4677c6ce43c01cff50a9f1e46e6af864
7
+ data.tar.gz: b96a45a0e29e90e417b8282cef8bc8b6b23b079c6f25decff10ec9ad8ae5b0d08255820936460f8a58944b3a9847d4f7bb3c7ce59bf963c54319ddb6af01bc43
data/README.md CHANGED
@@ -43,10 +43,10 @@ For added security GlobalIDs can also be signed to ensure that the data hasn't b
43
43
 
44
44
  ```ruby
45
45
  >> person_sgid = Person.find(1).to_signed_global_id
46
- => #<SignedGlobalID:0x007fea1944b410
46
+ => #<SignedGlobalID:0x007fea1944b410>
47
47
 
48
48
  >> person_sgid = Person.find(1).to_sgid
49
- => #<SignedGlobalID:0x007fea1944b410
49
+ => #<SignedGlobalID:0x007fea1944b410>
50
50
 
51
51
  >> person_sgid.to_s
52
52
  => "BAhJIh5naWQ6Ly9pZGluYWlkaS9Vc2VyLzM5NTk5BjoGRVQ=--81d7358dd5ee2ca33189bb404592df5e8d11420e"
@@ -66,12 +66,12 @@ In this way evildoers can't reuse a sign-up form's SGID on the login page. For e
66
66
  => #<Person:0x007fae94bf6298 @id="1">
67
67
  ```
68
68
 
69
- You can also have SGIDs that expire some time in the future. This is useful if there's a resource,
69
+ You can also have SGIDs that expire some time in the future. Useful if there's a resource,
70
70
  people shouldn't have indefinite access to, like a share link.
71
71
 
72
72
  ```ruby
73
73
  >> expiring_sgid = Document.find(5).to_sgid(expires_in: 2.hours, for: 'sharing')
74
- => #<SignedGlobalID:0x008fde45df8937
74
+ => #<SignedGlobalID:0x008fde45df8937 ...>
75
75
 
76
76
  # Within 2 hours...
77
77
  >> GlobalID::Locator.locate_signed(expiring_sgid.to_s, for: 'sharing')
@@ -82,11 +82,37 @@ people shouldn't have indefinite access to, like a share link.
82
82
  => nil
83
83
 
84
84
  >> explicit_expiring_sgid = SecretAgentMessage.find(5).to_sgid(expires_at: Time.now.advance(hours: 1))
85
- => #<SignedGlobalID:0x008fde45df8937
85
+ => #<SignedGlobalID:0x008fde45df8937 ...>
86
86
 
87
87
  # 1 hour later...
88
88
  >> GlobalID::Locator.locate_signed explicit_expiring_sgid.to_s
89
89
  => nil
90
+
91
+ # Passing a false value to either expiry option turns off expiration entirely.
92
+ >> never_expiring_sgid = Document.find(5).to_sgid(expires_in: nil)
93
+ => #<SignedGlobalID:0x008fde45df8937 ...>
94
+
95
+ # Any time later...
96
+ >> GlobalID::Locator.locate_signed never_expiring_sgid
97
+ => #<Document:0x007fae94bf6298 @id="5">
98
+ ```
99
+
100
+ Note that an explicit `:expires_at` takes precedence over a relative `:expires_in`.
101
+
102
+ You can assign a default SGID lifetime like so:
103
+
104
+ ```ruby
105
+ SignedGlobalID.expires_in = 1.month
106
+ ```
107
+
108
+ This way any generated SGID will use that relative expiry.
109
+
110
+ In Rails, an auto-expiry of 1 month is set by default. You can alter that deal
111
+ in an initializer with:
112
+
113
+ ```ruby
114
+ # config/initializers/global_id.rb
115
+ Rails.application.config.global_id.expires_in = 3.months
90
116
  ```
91
117
 
92
118
  ### Custom App Locator
@@ -5,4 +5,5 @@ autoload :SignedGlobalID, 'global_id/signed_global_id'
5
5
  class GlobalID
6
6
  autoload :Locator, 'global_id/locator'
7
7
  autoload :Identification, 'global_id/identification'
8
+ autoload :Verifier, 'global_id/verifier'
8
9
  end
@@ -22,7 +22,7 @@ class GlobalID
22
22
 
23
23
  config.after_initialize do
24
24
  app.config.global_id.verifier ||= begin
25
- app.message_verifier(:signed_global_ids)
25
+ GlobalID::Verifier.new(app.key_generator.generate_key('signed_global_ids'))
26
26
  rescue ArgumentError
27
27
  nil
28
28
  end
@@ -0,0 +1,15 @@
1
+ require 'active_support'
2
+ require 'active_support/message_verifier'
3
+
4
+ class GlobalID
5
+ class Verifier < ActiveSupport::MessageVerifier
6
+ private
7
+ def encode(data)
8
+ ::Base64.urlsafe_encode64(data)
9
+ end
10
+
11
+ def decode(data)
12
+ ::Base64.urlsafe_decode64(data)
13
+ end
14
+ end
15
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: globalid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-26 00:00:00.000000000 Z
11
+ date: 2017-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: 4.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.0
26
+ version: 4.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -53,6 +53,7 @@ files:
53
53
  - lib/global_id/railtie.rb
54
54
  - lib/global_id/signed_global_id.rb
55
55
  - lib/global_id/uri/gid.rb
56
+ - lib/global_id/verifier.rb
56
57
  - lib/globalid.rb
57
58
  homepage: http://www.rubyonrails.org
58
59
  licenses:
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  version: '0'
75
76
  requirements: []
76
77
  rubyforge_project:
77
- rubygems_version: 2.4.5.1
78
+ rubygems_version: 2.6.11
78
79
  signing_key:
79
80
  specification_version: 4
80
81
  summary: 'Refer to any model with a URI: gid://app/class/id'