token-die 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d6bedabd9fa601945340173e3a016f07c2516b43
4
+ data.tar.gz: 9d6e047c3e79fe966c450dd8391df45a71c05198
5
+ SHA512:
6
+ metadata.gz: 568b805d8e1ec1aa0b3568736208477ab1f171de81c5f5a25a593ee4f89190242dceab374b3c9fde7f696bd5afb19c3e635f1db63535d70c68342945c1b976f9
7
+ data.tar.gz: c39e1c461b51bd8c33614bb8dd2f45c6d2b894374b6ecdf5d1eebe0bf756ccf4c5e9aa6b3b17bd3be8852ea87092f3e5e6932191f5813aa9e330039d5ac7e007
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+
3
+ *.gem
data/.rpsec ADDED
@@ -0,0 +1 @@
1
+ --color --format documentation
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ token-die (0.0.1)
5
+ parsel (~> 0.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.5)
11
+ parsel (0.2.0)
12
+ rake (10.4.2)
13
+ rspec (3.3.0)
14
+ rspec-core (~> 3.3.0)
15
+ rspec-expectations (~> 3.3.0)
16
+ rspec-mocks (~> 3.3.0)
17
+ rspec-core (3.3.2)
18
+ rspec-support (~> 3.3.0)
19
+ rspec-expectations (3.3.1)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.3.0)
22
+ rspec-mocks (3.3.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.3.0)
25
+ rspec-support (3.3.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (>= 1.8)
32
+ rake (>= 10.0)
33
+ rspec (>= 3.3.0)
34
+ token-die!
35
+
36
+ BUNDLED WITH
37
+ 1.10.6
data/LiCENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ he MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Orgânica Digital
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # TokenDie
2
+
3
+ Generate and validate time expiring tokens
4
+
5
+ ## Usage
6
+
7
+ ```ruby
8
+ secret = 'my-secret' #=> Secret token
9
+ ttl = 5 #=> Token TTL, default 300 (5 minutes)
10
+
11
+ token_die = TokenDie.new(secret, ttl = ttl)
12
+
13
+ token = token_die.generate #=> haNSO3ArFzE/2Jm2KQPkyWEaV0wX5dK7HbaYYEmyX/k=
14
+ token_die.valid?(token) #=> true
15
+ token_die.recover(token) #=> {}
16
+
17
+ # Passing Data
18
+ token_with_data = token_die.generate({'foo' => 'bar'}) #=>JzJW02mJsJDNFH+jMGMmhFLigHie+j/gCZh60dI7LBsf3z73kAMh/+ZtQTgWbxE7
19
+ token_die.valid?(token_with_data) #=> true
20
+ token_die.recover(token_with_data) #=> {"foo" => "bar"}
21
+
22
+ sleep(ttl) #=> When TTL expires
23
+
24
+ token_die.valid?(token) #=> false
25
+ token_die.recover(token) #=> nil
26
+ token_die.recover(token_with_data) #=> nil
27
+
28
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ require 'rake/clean'
8
+
9
+ task test: ['spec']
10
+
11
+ task default: :test
data/lib/token-die.rb ADDED
@@ -0,0 +1,49 @@
1
+ require 'parsel'
2
+ class TokenDie
3
+ TIMESTAMP_KEY = '___timestamp____'.freeze
4
+
5
+ # Set the encryption secret
6
+ attr_reader :secret
7
+
8
+ # Set the token TTL
9
+ # Defaults 300 (5 minutes)
10
+ attr_reader :ttl
11
+
12
+ # Set the encryptor strategy.
13
+ # Defaults Parsel::JSON
14
+ attr_reader :encryptor
15
+
16
+ def initialize(secret, ttl = 300, encryptor = Parsel::JSON)
17
+ @secret = secret
18
+ @ttl = ttl
19
+ @encryptor = encryptor
20
+ end
21
+
22
+ def generate(data = {})
23
+ timestamp = Time.now.to_i
24
+ data.merge!(TIMESTAMP_KEY => timestamp)
25
+
26
+ encryptor.encrypt(secret, data)
27
+ end
28
+
29
+ def recover(token)
30
+ data = encryptor.decrypt(secret, token)
31
+ return unless data
32
+ return unless fresh?(data[TIMESTAMP_KEY])
33
+
34
+ data.delete(TIMESTAMP_KEY)
35
+ data
36
+ end
37
+
38
+ def valid?(token)
39
+ !recover(token).nil?
40
+ end
41
+
42
+ def expired?(timestamp)
43
+ timestamp.to_i < (Time.now.to_i - ttl)
44
+ end
45
+
46
+ def fresh?(timestamp)
47
+ !expired?(timestamp)
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ class TokenDie
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/token_die.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ require './lib/token-die/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'token-die'
5
+ s.version = TokenDie::VERSION
6
+ s.authors = ['Orgânica Digital', 'Alessandro Tegner']
7
+ s.email = ['alessandro@organicadigital.com']
8
+ s.summary = 'Generate and validate time expiring tokens'
9
+ s.description = s.summary
10
+ s.homepage = 'http://organicadigital.com'
11
+ s.license = 'MIT'
12
+
13
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
14
+ s.bindir = 'exe'
15
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ s.require_paths = ['lib']
17
+
18
+ s.add_dependency 'parsel', '~> 0.2.0'
19
+ s.add_development_dependency 'bundler', '>= 1.8'
20
+ s.add_development_dependency 'rake', '>= 10.0'
21
+ s.add_development_dependency 'rspec', '>= 3.3.0'
22
+
23
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: token-die
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Orgânica Digital
8
+ - Alessandro Tegner
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2015-08-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: parsel
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.2.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.2.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '1.8'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '1.8'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '10.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '10.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.3.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 3.3.0
70
+ description: Generate and validate time expiring tokens
71
+ email:
72
+ - alessandro@organicadigital.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rpsec"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LiCENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - lib/token-die.rb
85
+ - lib/token-die/version.rb
86
+ - token_die.gemspec
87
+ homepage: http://organicadigital.com
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.8
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Generate and validate time expiring tokens
111
+ test_files: []