README.md in fernet-0.0.1 vs README.md in fernet-0.0.2

- old
+ new

@@ -22,13 +22,37 @@ $ gem install fernet ## Usage -For now, see [spec/fernet_spec.rb](https://github.com/hgimenez/fernet/blob/master/spec/fernet_spec.rb). +Both server and client must share a secret. -I'll flesh this out further soon. Sorry. +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. +```ruby +token = Fernet.generate(secret) do |generator| + generator.data = { email: 'harold@heroku.com' } +end +``` + +On the server side, the receiver can use this token to verify wether it's legit: + +```ruby +verified = Fernet.verify(secret, token) do |verifier| + verifier.data['email'] == 'harold@heroku.com' +end +``` + +The `verified` variable will be true if: + +* The email encoded in the token data is `harold@heroku.com` +* The token was generated in the last 60 seconds +* The secret used to generate the token matches + +Otherwise, `verified` will be false, and you should deny the request with an HTTP 401, for example. + +The specs ([spec/fernet_spec.rb](https://github.com/hgimenez/fernet/blob/master/spec/fernet_spec.rb)) have more usage examples. + ## License -Valcro is copyright (c) Harold Giménez and is released under the terms of the +Fernet is copyright (c) Harold Giménez and is released under the terms of the MIT License found in the LICENSE file.