hancock-client 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -11
- data/Rakefile +3 -3
- data/lib/hancock-client.rb +18 -5
- data/lib/rack-openid.rb +1 -1
- data/lib/sinatra/hancock/sso.rb +4 -6
- data/spec/hancock_sinatra_spec.rb +4 -0
- data/spec/spec_helper.rb +6 -3
- metadata +4 -5
- data/spec/client.rb +0 -24
data/README.md
CHANGED
@@ -27,24 +27,25 @@ Application
|
|
27
27
|
The goal is to make it simple to write sso enabled apps.
|
28
28
|
|
29
29
|
require 'rubygems'
|
30
|
-
require 'sinatra'
|
31
|
-
require 'sinatra/base'
|
32
30
|
require 'hancock-client'
|
31
|
+
require 'logger'
|
33
32
|
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
# OpenID writes to STDERR by default. This is closed under passenger so
|
34
|
+
# to make this reliable you should have openid write failures somewhere.
|
35
|
+
OpenID::Util.logger = Logger.new(Dir.tmpdir + "/openid.log")
|
37
36
|
|
38
|
-
|
39
|
-
set :
|
40
|
-
set :
|
37
|
+
class HancockClientDemo < Sinatra::Default
|
38
|
+
set :views, File.dirname(__FILE__) + '/views'
|
39
|
+
set :public, File.dirname(__FILE__) + '/public'
|
40
|
+
use Hancock::Client::Default do |sso|
|
41
|
+
sso.sso_url = 'http://hancock.atmos.org/sso'
|
42
|
+
end
|
41
43
|
|
42
44
|
get '/' do
|
43
|
-
|
44
|
-
haml(%Q{%h3= "#{session[:first_name]} #{session[:last_name]} - #{session[:email]}"})
|
45
|
+
haml(%Q{%h3= "#{session[:first_name]} #{session[:last_name]} - #{session[:email]}"})
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
48
|
-
run
|
49
|
+
run HancockClientDemo
|
49
50
|
|
50
51
|
[sinatra]: http://www.sinatrarb.com
|
data/Rakefile
CHANGED
@@ -6,7 +6,7 @@ require 'spec/rake/spectask'
|
|
6
6
|
require 'cucumber/rake/task'
|
7
7
|
|
8
8
|
GEM = "hancock-client"
|
9
|
-
GEM_VERSION = "0.0.
|
9
|
+
GEM_VERSION = "0.0.5"
|
10
10
|
AUTHOR = "Corey Donohoe"
|
11
11
|
EMAIL = ['atmos@atmos.org', 'tim@spork.in']
|
12
12
|
HOMEPAGE = "http://github.com/atmos/hancock-client"
|
@@ -25,8 +25,8 @@ spec = Gem::Specification.new do |s|
|
|
25
25
|
s.homepage = HOMEPAGE
|
26
26
|
|
27
27
|
# Uncomment this to add a dependency
|
28
|
-
s.add_dependency "sinatra", ">=0.9.1.
|
29
|
-
s.add_dependency "ruby-openid", ">=2.1.
|
28
|
+
s.add_dependency "sinatra", ">=0.9.1.3"
|
29
|
+
s.add_dependency "ruby-openid", ">=2.1.6"
|
30
30
|
|
31
31
|
s.require_path = 'lib'
|
32
32
|
s.autorequire = GEM
|
data/lib/hancock-client.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
|
-
gem 'sinatra', '~>0.9.1'
|
1
|
+
gem 'sinatra', '~>0.9.1.3'
|
2
2
|
require 'rack'
|
3
3
|
require 'sinatra/base'
|
4
|
-
gem 'dm-core', '~>0.9.10'
|
5
|
-
require 'dm-core'
|
6
4
|
|
7
|
-
gem 'ruby-openid', '>=2.1.
|
5
|
+
gem 'ruby-openid', '>=2.1.6'
|
8
6
|
require 'openid'
|
9
7
|
|
10
8
|
gem 'haml', '~>2.0.9'
|
@@ -14,11 +12,26 @@ require File.dirname(__FILE__)+'/sinatra/hancock/sso'
|
|
14
12
|
|
15
13
|
module Hancock
|
16
14
|
module Client
|
17
|
-
class Default < ::Sinatra::
|
15
|
+
class Default < ::Sinatra::Base
|
18
16
|
enable :sessions
|
17
|
+
disable :raise_errors
|
18
|
+
|
19
19
|
set :sso_url, nil
|
20
20
|
|
21
|
+
def sso_url=(url)
|
22
|
+
options.sso_url = url
|
23
|
+
end
|
24
|
+
|
21
25
|
register Sinatra::Hancock::SSO
|
26
|
+
|
27
|
+
get '*' do
|
28
|
+
if session[:user_id]
|
29
|
+
forward
|
30
|
+
else
|
31
|
+
session[:return_to] = request.path_info
|
32
|
+
redirect "#{options.sso_url}/login?return_to=#{absolute_url('/sso/login')}"
|
33
|
+
end
|
34
|
+
end
|
22
35
|
end
|
23
36
|
end
|
24
37
|
end
|
data/lib/rack-openid.rb
CHANGED
data/lib/sinatra/hancock/sso.rb
CHANGED
@@ -19,12 +19,11 @@ module Sinatra
|
|
19
19
|
def self.registered(app)
|
20
20
|
app.use(Rack::OpenID)
|
21
21
|
app.helpers Hancock::SSO::Helpers
|
22
|
-
app.enable :sessions
|
23
|
-
app.disable :raise_errors
|
24
22
|
app.before do
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
next if request.path_info == '/sso/login'
|
24
|
+
next if request.path_info == '/sso/logout'
|
25
|
+
next if session[:user_id]
|
26
|
+
throw(:halt, [302, {'Location' => '/sso/login'}, ''])
|
28
27
|
end
|
29
28
|
|
30
29
|
app.get '/sso/login' do
|
@@ -63,5 +62,4 @@ module Sinatra
|
|
63
62
|
end
|
64
63
|
end
|
65
64
|
end
|
66
|
-
register Hancock::SSO
|
67
65
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper'
|
2
2
|
|
3
3
|
describe Sinatra::Hancock::SSO do
|
4
|
+
|
4
5
|
it "should protect the root url" do
|
5
6
|
get '/'
|
6
7
|
last_response.headers['Location'].should eql('/sso/login')
|
8
|
+
get last_response.headers['Location']
|
9
|
+
last_response.headers['Location'].should eql('http://localhost:20000/login?return_to=http://example.org/sso/login')
|
7
10
|
end
|
11
|
+
|
8
12
|
it "should greet the user when authenticated" do
|
9
13
|
pending
|
10
14
|
get '/'
|
data/spec/spec_helper.rb
CHANGED
@@ -15,15 +15,18 @@ require 'rack/test'
|
|
15
15
|
|
16
16
|
require 'hancock-client'
|
17
17
|
|
18
|
-
require File.dirname(__FILE__)+'/client'
|
19
|
-
|
20
18
|
Spec::Runner.configure do |config|
|
21
19
|
config.include(Rack::Test::Methods)
|
22
20
|
config.include(Webrat::Methods)
|
23
21
|
config.include(Webrat::Matchers)
|
24
22
|
def app
|
25
23
|
@app = Rack::Builder.new do
|
26
|
-
|
24
|
+
use Hancock::Client::Default do |sso|
|
25
|
+
sso.sso_url = 'http://localhost:20000'
|
26
|
+
end
|
27
|
+
map '/' do
|
28
|
+
run Proc.new {|env| [200, {'Content-Type' => 'text/html', 'Content-Length' => '5'}, ['HELLO']] }
|
29
|
+
end
|
27
30
|
end
|
28
31
|
end
|
29
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hancock-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corey Donohoe
|
@@ -9,7 +9,7 @@ autorequire: hancock-client
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-04-29 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.9.1.
|
23
|
+
version: 0.9.1.3
|
24
24
|
version:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: ruby-openid
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.1.
|
33
|
+
version: 2.1.6
|
34
34
|
version:
|
35
35
|
description: Hancock SSO rack middleware written in sinatra
|
36
36
|
email:
|
@@ -52,7 +52,6 @@ files:
|
|
52
52
|
- lib/sinatra
|
53
53
|
- lib/sinatra/hancock
|
54
54
|
- lib/sinatra/hancock/sso.rb
|
55
|
-
- spec/client.rb
|
56
55
|
- spec/features
|
57
56
|
- spec/features/signing_up.feature
|
58
57
|
- spec/features/step_definitions
|
data/spec/client.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
|
3
|
-
module Hancock
|
4
|
-
module Spec
|
5
|
-
class Client < ::Hancock::Client::Default
|
6
|
-
set :environment, :development
|
7
|
-
get '/' do
|
8
|
-
haml(<<-HAML
|
9
|
-
%table
|
10
|
-
%thead
|
11
|
-
%tr
|
12
|
-
%td Key
|
13
|
-
%td Value
|
14
|
-
%tbody
|
15
|
-
- session.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |key|
|
16
|
-
%tr
|
17
|
-
%td= key
|
18
|
-
%td= session[key]
|
19
|
-
HAML
|
20
|
-
)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|