dsparling-access_token 0.0.4
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.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +28 -0
- data/README.txt +64 -0
- data/Rakefile +4 -0
- data/access_token.gemspec +23 -0
- data/bin/generate_token.rb +14 -0
- data/lib/access_token.rb +60 -0
- data/lib/access_token/version.rb +9 -0
- metadata +64 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 FIXME full name
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.txt
|
6
|
+
Rakefile
|
7
|
+
bin/generate_token.rb
|
8
|
+
config/hoe.rb
|
9
|
+
config/requirements.rb
|
10
|
+
lib/access_token.rb
|
11
|
+
lib/access_token/version.rb
|
12
|
+
script/console
|
13
|
+
script/destroy
|
14
|
+
script/generate
|
15
|
+
script/txt2html
|
16
|
+
setup.rb
|
17
|
+
spec/access_token_spec.rb
|
18
|
+
spec/spec.opts
|
19
|
+
spec/spec_helper.rb
|
20
|
+
tasks/deployment.rake
|
21
|
+
tasks/environment.rake
|
22
|
+
tasks/rspec.rake
|
23
|
+
tasks/website.rake
|
24
|
+
website/index.html
|
25
|
+
website/index.txt
|
26
|
+
website/javascripts/rounded_corners_lite.inc.js
|
27
|
+
website/stylesheets/screen.css
|
28
|
+
website/template.html.erb
|
data/README.txt
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
= access_token
|
2
|
+
|
3
|
+
|
4
|
+
== DESCRIPTION:
|
5
|
+
|
6
|
+
Generate and validate simple time-based access token
|
7
|
+
|
8
|
+
== FEATURES/PROBLEMS:
|
9
|
+
|
10
|
+
TODO: Multiple time formats
|
11
|
+
1/100th seconds
|
12
|
+
Use ARGV for bin script for username and password
|
13
|
+
|
14
|
+
== SYNOPSIS:
|
15
|
+
|
16
|
+
#!/usr/bin/env ruby
|
17
|
+
require 'rubygems'
|
18
|
+
require 'access_token'
|
19
|
+
|
20
|
+
username = 'doug'
|
21
|
+
password = 'secret'
|
22
|
+
|
23
|
+
t = AccessToken::Token.new(username, password)
|
24
|
+
puts t.token
|
25
|
+
|
26
|
+
puts t.validate(t.token, username, password)? 'valid' : 'not valid'
|
27
|
+
puts t.validate(t.token, username, password, 5)? 'valid' : 'not valid'
|
28
|
+
sleep 3
|
29
|
+
puts t.validate(t.token, username, password, 2)? 'valid' : 'not valid'
|
30
|
+
|
31
|
+
|
32
|
+
== REQUIREMENTS:
|
33
|
+
|
34
|
+
|
35
|
+
== INSTALL:
|
36
|
+
|
37
|
+
$ git clone git://github.com/dsparling/access_token.git
|
38
|
+
$ cd access_token
|
39
|
+
$ sudo ruby setup.rb
|
40
|
+
|
41
|
+
== LICENSE:
|
42
|
+
|
43
|
+
(The MIT License)
|
44
|
+
|
45
|
+
Copyright (c) 2008 FIXME full name
|
46
|
+
|
47
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
48
|
+
a copy of this software and associated documentation files (the
|
49
|
+
'Software'), to deal in the Software without restriction, including
|
50
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
51
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
52
|
+
permit persons to whom the Software is furnished to do so, subject to
|
53
|
+
the following conditions:
|
54
|
+
|
55
|
+
The above copyright notice and this permission notice shall be
|
56
|
+
included in all copies or substantial portions of the Software.
|
57
|
+
|
58
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
59
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
60
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
61
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
62
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
63
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
64
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "access_token"
|
3
|
+
s.version = "0.0.4"
|
4
|
+
s.date = "2008-08-24"
|
5
|
+
s.summary = "Generate and validate simple time-based access token"
|
6
|
+
s.email = "scriptrunner.com@gmail.com"
|
7
|
+
s.homepage = "http://github.com/dsparling/access_token"
|
8
|
+
s.description = "Generate and validate simple time-based access token."
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Doug Sparling"]
|
11
|
+
s.files = ["History.txt",
|
12
|
+
"License.txt",
|
13
|
+
"Manifest.txt",
|
14
|
+
"README.txt",
|
15
|
+
"Rakefile",
|
16
|
+
"access_token.gemspec",
|
17
|
+
"lib/access_token.rb",
|
18
|
+
"lib/access_token/version.rb",
|
19
|
+
"bin/generate_token.rb"]
|
20
|
+
s.rdoc_options = ["--main", "README.txt"]
|
21
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
|
22
|
+
#s.add_dependency("mime-types", ["> 0.0.0"])
|
23
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
require 'access_token'
|
4
|
+
|
5
|
+
username = 'doug'
|
6
|
+
password = 'secret'
|
7
|
+
|
8
|
+
t = AccessToken::Token.new(username, password)
|
9
|
+
puts t.token
|
10
|
+
|
11
|
+
puts t.validate(t.token, username, password)? 'valid' : 'not valid'
|
12
|
+
puts t.validate(t.token, username, password, 5)? 'valid' : 'not valid'
|
13
|
+
sleep 3
|
14
|
+
puts t.validate(t.token, username, password, 2)? 'valid' : 'not valid'
|
data/lib/access_token.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'digest/md5'
|
5
|
+
require 'base64'
|
6
|
+
|
7
|
+
module AccessToken
|
8
|
+
|
9
|
+
class Token
|
10
|
+
attr_accessor(:timestamp, :username, :password, :key, :key_md5, :key_base64, :token)
|
11
|
+
|
12
|
+
def initialize(username, password)
|
13
|
+
@username = username
|
14
|
+
@password = password
|
15
|
+
@timestamp = Time.now.to_i
|
16
|
+
@key = generate_key
|
17
|
+
@key_md5 = generate_key_md5
|
18
|
+
@key_base64 = generate_key_base64
|
19
|
+
@token = generate_token
|
20
|
+
end
|
21
|
+
|
22
|
+
def generate_token
|
23
|
+
@token = @timestamp.to_s + ':' + @key_base64
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate(token, username, password, secs=nil)
|
27
|
+
token_timestamp = token.split(':')[0]
|
28
|
+
unless secs.nil?
|
29
|
+
return false if Time.now.to_i - token_timestamp.to_i > secs
|
30
|
+
end
|
31
|
+
token_key = generate_key(token_timestamp, username, password)
|
32
|
+
token_digest = generate_key_md5(token_key)
|
33
|
+
token_enc = generate_key_base64(token_digest)
|
34
|
+
token_enc.chomp!
|
35
|
+
token2 = token_timestamp + ":" + token_enc
|
36
|
+
token == token2 ? true : false
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def generate_keyy
|
42
|
+
@timestamp.to_s + @username + @password
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate_key(timestamp=@timestamp.to_s, username=@username, password=@password)
|
46
|
+
timestamp + username + password
|
47
|
+
end
|
48
|
+
|
49
|
+
def generate_key_md5(key=@key)
|
50
|
+
Digest::MD5.hexdigest(key)
|
51
|
+
end
|
52
|
+
|
53
|
+
def generate_key_base64(key_md5=@key_md5)
|
54
|
+
@key_base64 = Base64.encode64(key_md5)
|
55
|
+
@key_base64.chomp!
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dsparling-access_token
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Doug Sparling
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-08-24 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Generate and validate simple time-based access token.
|
17
|
+
email: scriptrunner.com@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- History.txt
|
24
|
+
- Manifest.txt
|
25
|
+
- README.txt
|
26
|
+
files:
|
27
|
+
- History.txt
|
28
|
+
- License.txt
|
29
|
+
- Manifest.txt
|
30
|
+
- README.txt
|
31
|
+
- Rakefile
|
32
|
+
- access_token.gemspec
|
33
|
+
- lib/access_token.rb
|
34
|
+
- lib/access_token/version.rb
|
35
|
+
- bin/generate_token.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: http://github.com/dsparling/access_token
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --main
|
41
|
+
- README.txt
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.2.0
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: Generate and validate simple time-based access token
|
63
|
+
test_files: []
|
64
|
+
|