fernet 0.0.2 → 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Fernet
2
2
 
3
- Fernet allows you to easily generate and verify HMAC based authentication tokens for issuing API requests between remote servers.
3
+ Fernet allows you to easily generate and verify HMAC based authentication
4
+ tokens for issuing API requests between remote servers.
4
5
 
5
6
  ![Fernet](http://f.cl.ly/items/2d0P3d26271O3p2v253u/photo.JPG)
6
7
 
7
- Fernet is usually served as a *digestif* after a meal but may also be served with coffee and espresso or mixed into coffee and espresso drinks.
8
+ Fernet is usually served as a *digestif* after a meal but may also be served
9
+ with coffee and espresso or mixed into coffee and espresso drinks.
8
10
 
9
11
  Fernet about it!
10
12
 
@@ -26,15 +28,16 @@ Or install it yourself as:
26
28
 
27
29
  Both server and client must share a secret.
28
30
 
29
- You want to encode some data in the token as well, for example, an email address can be used to verify it on the other end.
31
+ You want to encode some data in the token as well, for example, an email
32
+ address can be used to verify it on the other end.
30
33
 
31
34
  ```ruby
32
35
  token = Fernet.generate(secret) do |generator|
33
36
  generator.data = { email: 'harold@heroku.com' }
34
37
  end
35
38
  ```
36
-
37
- On the server side, the receiver can use this token to verify wether it's legit:
39
+ On the server side, the receiver can use this token to verify whether it's
40
+ legit:
38
41
 
39
42
  ```ruby
40
43
  verified = Fernet.verify(secret, token) do |verifier|
@@ -48,9 +51,20 @@ The `verified` variable will be true if:
48
51
  * The token was generated in the last 60 seconds
49
52
  * The secret used to generate the token matches
50
53
 
51
- Otherwise, `verified` will be false, and you should deny the request with an HTTP 401, for example.
54
+ Otherwise, `verified` will be false, and you should deny the request with an
55
+ HTTP 401, for example.
56
+
57
+ The specs
58
+ ([spec/fernet_spec.rb](https://github.com/hgimenez/fernet/blob/master/spec/fernet_spec.rb))
59
+ have more usage examples.
60
+
61
+ ### Attribution
52
62
 
53
- The specs ([spec/fernet_spec.rb](https://github.com/hgimenez/fernet/blob/master/spec/fernet_spec.rb)) have more usage examples.
63
+ This library was largely made possible by [Mr. Tom
64
+ Maher](http://twitter.com/#tmaher), who clearly articulated the mechanics
65
+ behind this process, and further found ways to make it
66
+ [more](https://github.com/hgimenez/fernet/commit/2bf0b4a66b49ef3fc92ef50708a2c8b401950fc2)
67
+ [secure](https://github.com/hgimenez/fernet/commit/051161d0afb0b41480734d84bc824bdbc7f9c563).
54
68
 
55
69
  ## License
56
70
 
@@ -4,7 +4,7 @@ require File.expand_path('../lib/fernet/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Harold Giménez"]
6
6
  gem.email = ["harold.gimenez@gmail.com"]
7
- gem.description = %q{Delicious HMAC Digest[if] authentication}
7
+ gem.description = %q{Delicious HMAC Digest(if) authentication}
8
8
  gem.summary = %q{Easily generate and verify HMAC based authentication tokens}
9
9
  gem.homepage = ""
10
10
 
@@ -12,7 +12,7 @@ module Fernet
12
12
  end
13
13
 
14
14
  def generate
15
- yield self
15
+ yield self if block_given?
16
16
  data.merge!(issued_at: DateTime.now)
17
17
 
18
18
  mac = OpenSSL::HMAC.hexdigest('sha256', JSON.dump(data), secret)
@@ -24,6 +24,10 @@ module Fernet
24
24
  end
25
25
  alias to_s inspect
26
26
 
27
+ def data
28
+ @data ||= {}
29
+ end
30
+
27
31
  private
28
32
  attr_reader :secret
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module Fernet
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1"
3
3
  end
@@ -55,4 +55,10 @@ describe Fernet do
55
55
 
56
56
  Fernet.verify(secret, token).should be_true
57
57
  end
58
+
59
+ it 'generates without custom data' do
60
+ token = Fernet.generate(secret)
61
+
62
+ Fernet.verify(secret, token).should be_true
63
+ end
58
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fernet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: '0.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-20 00:00:00.000000000 Z
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70169850711960 !ruby/object:Gem::Requirement
16
+ requirement: &70098514672160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,8 +21,8 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70169850711960
25
- description: Delicious HMAC Digest[if] authentication
24
+ version_requirements: *70098514672160
25
+ description: Delicious HMAC Digest(if) authentication
26
26
  email:
27
27
  - harold.gimenez@gmail.com
28
28
  executables: []