singularity 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +82 -0
- data/LICENSE +7 -0
- data/Rakefile +36 -0
- data/lib/assets/javascripts/singularity.js.erb +46 -0
- data/lib/global_user.rb +30 -0
- data/lib/singularity/engine.rb +5 -0
- data/lib/singularity/version.rb +3 -0
- data/lib/singularity.rb +89 -0
- data/singularity.gemspec +24 -0
- metadata +114 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
singularity (0.0.2)
|
5
|
+
jquery-rails (~> 1.0)
|
6
|
+
railties (~> 3.1)
|
7
|
+
redis-native_hash
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionpack (3.1.3)
|
13
|
+
activemodel (= 3.1.3)
|
14
|
+
activesupport (= 3.1.3)
|
15
|
+
builder (~> 3.0.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
i18n (~> 0.6)
|
18
|
+
rack (~> 1.3.5)
|
19
|
+
rack-cache (~> 1.1)
|
20
|
+
rack-mount (~> 0.8.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.0.3)
|
23
|
+
activemodel (3.1.3)
|
24
|
+
activesupport (= 3.1.3)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
i18n (~> 0.6)
|
27
|
+
activesupport (3.1.3)
|
28
|
+
multi_json (~> 1.0)
|
29
|
+
builder (3.0.0)
|
30
|
+
diff-lcs (1.1.3)
|
31
|
+
erubis (2.7.0)
|
32
|
+
hike (1.2.1)
|
33
|
+
i18n (0.6.0)
|
34
|
+
jquery-rails (1.0.19)
|
35
|
+
railties (~> 3.0)
|
36
|
+
thor (~> 0.14)
|
37
|
+
json (1.6.3)
|
38
|
+
multi_json (1.0.4)
|
39
|
+
rack (1.3.5)
|
40
|
+
rack-cache (1.1)
|
41
|
+
rack (>= 0.4)
|
42
|
+
rack-mount (0.8.3)
|
43
|
+
rack (>= 1.0.0)
|
44
|
+
rack-ssl (1.3.2)
|
45
|
+
rack
|
46
|
+
rack-test (0.6.1)
|
47
|
+
rack (>= 1.0)
|
48
|
+
railties (3.1.3)
|
49
|
+
actionpack (= 3.1.3)
|
50
|
+
activesupport (= 3.1.3)
|
51
|
+
rack-ssl (~> 1.3.2)
|
52
|
+
rake (>= 0.8.7)
|
53
|
+
rdoc (~> 3.4)
|
54
|
+
thor (~> 0.14.6)
|
55
|
+
rake (0.9.2.2)
|
56
|
+
rdoc (3.11)
|
57
|
+
json (~> 1.4)
|
58
|
+
redis (2.2.2)
|
59
|
+
redis-native_hash (0.1.0)
|
60
|
+
redis (>= 2.0.0)
|
61
|
+
rspec (2.3.0)
|
62
|
+
rspec-core (~> 2.3.0)
|
63
|
+
rspec-expectations (~> 2.3.0)
|
64
|
+
rspec-mocks (~> 2.3.0)
|
65
|
+
rspec-core (2.3.1)
|
66
|
+
rspec-expectations (2.3.0)
|
67
|
+
diff-lcs (~> 1.1.2)
|
68
|
+
rspec-mocks (2.3.0)
|
69
|
+
sprockets (2.0.3)
|
70
|
+
hike (~> 1.2)
|
71
|
+
rack (~> 1.0)
|
72
|
+
tilt (!= 1.3.0, ~> 1.1)
|
73
|
+
thor (0.14.6)
|
74
|
+
tilt (1.3.3)
|
75
|
+
|
76
|
+
PLATFORMS
|
77
|
+
ruby
|
78
|
+
|
79
|
+
DEPENDENCIES
|
80
|
+
bundler (~> 1.0.0)
|
81
|
+
rspec (~> 2.3.0)
|
82
|
+
singularity!
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2011 Lyconic, LLC
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'rspec/core'
|
15
|
+
require 'rspec/core/rake_task'
|
16
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
17
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
21
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
22
|
+
spec.rcov = true
|
23
|
+
end
|
24
|
+
|
25
|
+
task :default => :spec
|
26
|
+
|
27
|
+
require 'rake/rdoctask'
|
28
|
+
Rake::RDocTask.new do |rdoc|
|
29
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
30
|
+
|
31
|
+
rdoc.rdoc_dir = 'rdoc'
|
32
|
+
rdoc.title = "singularity #{version}"
|
33
|
+
rdoc.rdoc_files.include('README*')
|
34
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
var Singularity = (function () {
|
2
|
+
|
3
|
+
this.master_auth = "<%= Singularity.auth_path %>";
|
4
|
+
this.logged_in = false;
|
5
|
+
this.session_token = '';
|
6
|
+
|
7
|
+
this.extend = function ( options ) {
|
8
|
+
jQuery.extend( true, this, options );
|
9
|
+
}
|
10
|
+
|
11
|
+
this.init = function () {
|
12
|
+
this.logged_in ? this.registerMasterAuth() : this.checkMasterAuth();
|
13
|
+
}
|
14
|
+
|
15
|
+
function login ( result ) {
|
16
|
+
if ( result['logged_in'] )
|
17
|
+
$(Singularity).trigger('login.success');
|
18
|
+
else
|
19
|
+
$(Singularity).trigger('login.failure');
|
20
|
+
}
|
21
|
+
|
22
|
+
function register ( result ) {
|
23
|
+
if ( result['logged_in'] )
|
24
|
+
$(Singularity).trigger('register.success');
|
25
|
+
else
|
26
|
+
$(Singularity).trigger('register.failure');
|
27
|
+
}
|
28
|
+
|
29
|
+
this.checkMasterAuth = function () {
|
30
|
+
var url = this.master_auth + '?session_token=' + this.session_token + '&callback=?';
|
31
|
+
$.getJSON( url, login );
|
32
|
+
}
|
33
|
+
|
34
|
+
this.registerMasterAuth = function () {
|
35
|
+
var url = this.master_auth + '?register_token=' + this.session_token + '&callback=?';
|
36
|
+
$.getJSON( url, register );
|
37
|
+
}
|
38
|
+
|
39
|
+
$(this).bind('login.success', function () {
|
40
|
+
setTimeout(function () { window.location.reload(true); }, 2000);
|
41
|
+
});
|
42
|
+
|
43
|
+
return this;
|
44
|
+
|
45
|
+
}).apply({});
|
46
|
+
|
data/lib/global_user.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'digest/sha2'
|
2
|
+
|
3
|
+
class GlobalUser < Redis::NativeHash
|
4
|
+
attr_persist :login, :password_hash
|
5
|
+
|
6
|
+
def initialize(data = {})
|
7
|
+
super(namespace)
|
8
|
+
update(data)
|
9
|
+
end
|
10
|
+
|
11
|
+
def namespace; :global_user; end
|
12
|
+
|
13
|
+
def password=(value)
|
14
|
+
self.password_hash = generate_password_hash(value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def password?(value)
|
18
|
+
generate_password_hash(value) == self.password_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
def save
|
22
|
+
self.key = login unless login.nil?
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate_password_hash(value)
|
27
|
+
tokens = [ value, 'salt-goes-here', login ]
|
28
|
+
::Digest::SHA256.hexdigest('--' << tokens.flatten.join('--') << '--')
|
29
|
+
end
|
30
|
+
end
|
data/lib/singularity.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'redis_hash'
|
3
|
+
|
4
|
+
require_relative 'global_user'
|
5
|
+
|
6
|
+
module Singularity
|
7
|
+
def self.cattr_accessor(attribute, default = nil)
|
8
|
+
class_variable_set("@@#{attribute}", default)
|
9
|
+
class_eval <<-EOS
|
10
|
+
def self.#{attribute}=(value)
|
11
|
+
@@#{attribute} = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.#{attribute}
|
15
|
+
@@#{attribute}
|
16
|
+
end
|
17
|
+
EOS
|
18
|
+
end
|
19
|
+
|
20
|
+
#cattr_accessor :user_class, IG::User::GlobalUser
|
21
|
+
cattr_accessor :auth_path, "http://authmaster.local:9292/api"
|
22
|
+
cattr_accessor :master, false
|
23
|
+
cattr_accessor :session_prefix, "rack_session"
|
24
|
+
cattr_accessor :token_prefix, "singularity_session_token"
|
25
|
+
cattr_accessor :warden_user_key, "warden.user.default.key"
|
26
|
+
|
27
|
+
class << self
|
28
|
+
|
29
|
+
def generate_token(length)
|
30
|
+
chars = ['a'..'z','A'..'Z',0..9].map(&:to_a).flatten
|
31
|
+
token = ''
|
32
|
+
length.times { token << chars.sample.to_s }
|
33
|
+
token
|
34
|
+
end
|
35
|
+
|
36
|
+
def generate_session_token(session_id, session)
|
37
|
+
if session.key?("_token_expires") && session["_token_expires"].to_i > Time.now.to_i
|
38
|
+
unless session.nil? || session["_session_id"] != session_id
|
39
|
+
return session["_token"]
|
40
|
+
else
|
41
|
+
redis.del token_key(session['_token'])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
session_token = generate_token(32)
|
45
|
+
token_expiration = 1800 # 30 minutes # JUNK
|
46
|
+
redis.setex token_key(session_token), token_expiration, session_id
|
47
|
+
session["_session_id"] = session_id
|
48
|
+
session["_token"] = session_token
|
49
|
+
session["_token_expires"] = Time.now.to_i + token_expiration
|
50
|
+
session_token
|
51
|
+
end
|
52
|
+
|
53
|
+
def session_key(id)
|
54
|
+
Singularity.session_prefix.nil? ? id : "#{Singularity.session_prefix}:#{id}"
|
55
|
+
end
|
56
|
+
|
57
|
+
def token_key(token)
|
58
|
+
"#{Singularity.token_prefix}:#{token}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_session_id_by_token(session_token)
|
62
|
+
session_id = redis.get token_key(session_token)
|
63
|
+
return nil if session_id.nil?
|
64
|
+
redis.exists(session_key(session_id)) ? session_id : nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def fetch_key_from_session(session_id, key)
|
68
|
+
redis.hget session_key(session_id), key
|
69
|
+
end
|
70
|
+
|
71
|
+
def store_key_in_session(session_id, key, value)
|
72
|
+
redis.hset session_key(session_id), key, value
|
73
|
+
end
|
74
|
+
|
75
|
+
def destroy_session(*ids)
|
76
|
+
redis.del( *ids.map{ |id| session_key(id) } )
|
77
|
+
end
|
78
|
+
|
79
|
+
def destroy_token(*tokens)
|
80
|
+
redis.del( *tokens.map{ |t| token_key(t) } )
|
81
|
+
end
|
82
|
+
|
83
|
+
def redis
|
84
|
+
@@redis ||= Redis::NativeHash.redis # JUNK
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
require 'singularity/engine' if defined?(Rails)
|
data/singularity.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/singularity/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "singularity"
|
6
|
+
s.homepage = "https://github.com/lyconic/singularity"
|
7
|
+
s.version = Singularity::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Carl Zulauf", "Adam Lassek"]
|
10
|
+
s.email = ["czulauf@lyconic.com", "alassek@lyconic.com"]
|
11
|
+
s.summary = "multi-domain single sign on"
|
12
|
+
s.description = "Singularity helps you keep users logged in across many domains"
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.licenses = ["MIT"]
|
15
|
+
s.require_path = "lib"
|
16
|
+
|
17
|
+
s.add_dependency "redis-native_hash", ">= 0"
|
18
|
+
s.add_dependency "railties", "~> 3.1"
|
19
|
+
s.add_dependency "jquery-rails", "~> 1.0"
|
20
|
+
|
21
|
+
s.add_development_dependency "bundler", "~> 1.0.0"
|
22
|
+
s.add_development_dependency "rspec", "~> 2.3.0"
|
23
|
+
end
|
24
|
+
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: singularity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Carl Zulauf
|
9
|
+
- Adam Lassek
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2011-12-16 00:00:00.000000000Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: redis-native_hash
|
17
|
+
requirement: &70186632820140 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70186632820140
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: railties
|
28
|
+
requirement: &70186632819640 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70186632819640
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: jquery-rails
|
39
|
+
requirement: &70186632819180 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '1.0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70186632819180
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &70186632818720 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70186632818720
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: rspec
|
61
|
+
requirement: &70186632818260 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.3.0
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70186632818260
|
70
|
+
description: Singularity helps you keep users logged in across many domains
|
71
|
+
email:
|
72
|
+
- czulauf@lyconic.com
|
73
|
+
- alassek@lyconic.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE
|
82
|
+
- Rakefile
|
83
|
+
- lib/assets/javascripts/singularity.js.erb
|
84
|
+
- lib/global_user.rb
|
85
|
+
- lib/singularity.rb
|
86
|
+
- lib/singularity/engine.rb
|
87
|
+
- lib/singularity/version.rb
|
88
|
+
- singularity.gemspec
|
89
|
+
homepage: https://github.com/lyconic/singularity
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 1.8.8
|
111
|
+
signing_key:
|
112
|
+
specification_version: 3
|
113
|
+
summary: multi-domain single sign on
|
114
|
+
test_files: []
|