oa-core 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +0 -0
- data/LICENSE.rdoc +0 -0
- data/README.rdoc +0 -0
- data/lib/omniauth/builder.rb +23 -0
- data/lib/omniauth/core.rb +74 -0
- data/lib/omniauth/password.rb +2 -0
- data/lib/omniauth/strategies/password.rb +44 -0
- data/lib/omniauth/strategy.rb +80 -0
- metadata +130 -0
data/CHANGELOG.rdoc
ADDED
File without changes
|
data/LICENSE.rdoc
ADDED
File without changes
|
data/README.rdoc
ADDED
File without changes
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
class Builder < Rack::Builder
|
3
|
+
def initialize(app, &block)
|
4
|
+
@app = app
|
5
|
+
super(&block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def provider(klass, *args, &block)
|
9
|
+
if klass.is_a?(Class)
|
10
|
+
middleware = klass
|
11
|
+
else
|
12
|
+
middleware = OmniAuth::Strategies.const_get("#{OmniAuth::Utils.camelize(klass.to_s)}")
|
13
|
+
end
|
14
|
+
|
15
|
+
use middleware, *args, &block
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(env)
|
19
|
+
@ins << @app unless @ins.include?(@app)
|
20
|
+
to_app.call(env)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
class Configuration
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@path_prefix = '/auth'
|
10
|
+
@on_failure = Proc.new do |env, message_key|
|
11
|
+
new_path = "#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
|
12
|
+
[302, {'Location' => "#{new_path}"}, []]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_failure(&block)
|
17
|
+
if block_given?
|
18
|
+
@on_failure = block
|
19
|
+
else
|
20
|
+
@on_failure
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_accessor :path_prefix
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.config
|
28
|
+
Configuration.instance
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.configure
|
32
|
+
yield config
|
33
|
+
end
|
34
|
+
|
35
|
+
module Utils
|
36
|
+
extend self
|
37
|
+
|
38
|
+
def deep_merge(hash, other_hash)
|
39
|
+
target = hash.dup
|
40
|
+
|
41
|
+
other_hash.keys.each do |key|
|
42
|
+
if other_hash[key].is_a? ::Hash and hash[key].is_a? ::Hash
|
43
|
+
target[key] = deep_merge(target[key],other_hash[key])
|
44
|
+
next
|
45
|
+
end
|
46
|
+
|
47
|
+
target[key] = other_hash[key]
|
48
|
+
end
|
49
|
+
|
50
|
+
target
|
51
|
+
end
|
52
|
+
|
53
|
+
CAMELIZE_SPECIAL = {
|
54
|
+
'oauth' => 'OAuth',
|
55
|
+
'oauth2' => 'OAuth2',
|
56
|
+
'openid' => 'OpenID',
|
57
|
+
'open_id' => 'OpenID',
|
58
|
+
'github' => 'GitHub'
|
59
|
+
}
|
60
|
+
|
61
|
+
def camelize(word, first_letter_in_uppercase = true)
|
62
|
+
return CAMELIZE_SPECIAL[word.to_s] if CAMELIZE_SPECIAL[word.to_s]
|
63
|
+
|
64
|
+
if first_letter_in_uppercase
|
65
|
+
word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
66
|
+
else
|
67
|
+
word.first + camelize(word)[1..-1]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
require 'omniauth/builder'
|
74
|
+
require 'omniauth/strategy'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
module OmniAuth
|
3
|
+
module Strategies
|
4
|
+
class Password
|
5
|
+
include OmniAuth::Strategy
|
6
|
+
|
7
|
+
def initialize(app, secret = 'changethisappsecret', options = {})
|
8
|
+
@options = options
|
9
|
+
@options[:identifier_key] ||= 'nickname'
|
10
|
+
@secret = secret
|
11
|
+
super(app, :password)
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :secret
|
15
|
+
|
16
|
+
def request_phase
|
17
|
+
return fail!(:missing_information) unless request[:identifier] && request[:password]
|
18
|
+
return fail!(:password_mismatch) if request[:password_confirmation] && request[:password_confirmation] != '' && request[:password] != request[:password_confirmation]
|
19
|
+
|
20
|
+
env['REQUEST_METHOD'] = 'GET'
|
21
|
+
env['PATH_INFO'] = request.path + '/callback'
|
22
|
+
request['auth'] = auth_hash(encrypt(request[:identifier], request[:password]))
|
23
|
+
@app.call(env)
|
24
|
+
end
|
25
|
+
|
26
|
+
def auth_hash(crypted_password)
|
27
|
+
OmniAuth::Utils.deep_merge(super(), {
|
28
|
+
'uid' => crypted_password,
|
29
|
+
'user_info' => {
|
30
|
+
@options[:identifier_key] => request[:identifier]
|
31
|
+
}
|
32
|
+
})
|
33
|
+
end
|
34
|
+
|
35
|
+
def callback_phase
|
36
|
+
@app.call(env)
|
37
|
+
end
|
38
|
+
|
39
|
+
def encrypt(identifier, password)
|
40
|
+
Digest::SHA1.hexdigest([identifier, password, secret].join('::'))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
module Strategy
|
3
|
+
def self.included(base)
|
4
|
+
base.class_eval do
|
5
|
+
attr_reader :app, :name, :env
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(app, name, *args)
|
10
|
+
@app = app
|
11
|
+
@name = name.to_sym
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
dup.call!(env)
|
16
|
+
end
|
17
|
+
|
18
|
+
def call!(env)
|
19
|
+
@env = env
|
20
|
+
if request.path == "#{OmniAuth.config.path_prefix}/#{name}"
|
21
|
+
request_phase
|
22
|
+
elsif request.path == "#{OmniAuth.config.path_prefix}/#{name}/callback"
|
23
|
+
callback_phase
|
24
|
+
else
|
25
|
+
if respond_to?(:other_phase)
|
26
|
+
other_phase
|
27
|
+
else
|
28
|
+
@app.call(env)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def request_phase
|
34
|
+
raise NotImplementedError
|
35
|
+
end
|
36
|
+
|
37
|
+
def callback_phase
|
38
|
+
request['auth'] = auth_hash
|
39
|
+
@app.call(env)
|
40
|
+
end
|
41
|
+
|
42
|
+
def auth_hash
|
43
|
+
{
|
44
|
+
'provider' => name.to_s,
|
45
|
+
'uid' => nil
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def full_host
|
50
|
+
uri = URI.parse(request.url)
|
51
|
+
uri.path = ''
|
52
|
+
uri.query = nil
|
53
|
+
uri.to_s
|
54
|
+
end
|
55
|
+
|
56
|
+
def callback_url
|
57
|
+
full_host + "#{OmniAuth.config.path_prefix}/#{name}/callback"
|
58
|
+
end
|
59
|
+
|
60
|
+
def session
|
61
|
+
@env['rack.session']
|
62
|
+
end
|
63
|
+
|
64
|
+
def request
|
65
|
+
@request ||= Rack::Request.new(@env)
|
66
|
+
end
|
67
|
+
|
68
|
+
def redirect(uri)
|
69
|
+
r = Rack::Response.new("Redirecting to #{uri}...")
|
70
|
+
r.redirect(uri)
|
71
|
+
r.finish
|
72
|
+
end
|
73
|
+
|
74
|
+
def user_info; {} end
|
75
|
+
|
76
|
+
def fail!(message_key)
|
77
|
+
OmniAuth.config.on_failure.call(self.env, message_key.to_sym)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oa-core
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Michael Bleigh
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-29 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rack
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: rspec
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 1
|
41
|
+
- 2
|
42
|
+
- 9
|
43
|
+
version: 1.2.9
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: webmock
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
type: :development
|
57
|
+
version_requirements: *id003
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rack-test
|
60
|
+
prerelease: false
|
61
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id004
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: mg
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id005
|
82
|
+
description: HTTP Basic strategies for OmniAuth.
|
83
|
+
email: michael@intridea.com
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files: []
|
89
|
+
|
90
|
+
files:
|
91
|
+
- lib/omniauth/builder.rb
|
92
|
+
- lib/omniauth/core.rb
|
93
|
+
- lib/omniauth/password.rb
|
94
|
+
- lib/omniauth/strategies/password.rb
|
95
|
+
- lib/omniauth/strategy.rb
|
96
|
+
- README.rdoc
|
97
|
+
- LICENSE.rdoc
|
98
|
+
- CHANGELOG.rdoc
|
99
|
+
has_rdoc: true
|
100
|
+
homepage: http://github.com/intridea/omniauth
|
101
|
+
licenses: []
|
102
|
+
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
segments:
|
120
|
+
- 0
|
121
|
+
version: "0"
|
122
|
+
requirements: []
|
123
|
+
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 1.3.6
|
126
|
+
signing_key:
|
127
|
+
specification_version: 3
|
128
|
+
summary: HTTP Basic strategies for OmniAuth.
|
129
|
+
test_files: []
|
130
|
+
|