passage 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Dotan Nahum
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/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = passage
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to passage
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Dotan Nahum. See LICENSE.txt for
18
+ further details.
19
+
data/bin/passage ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ help = <<HELP
5
+ Passage is your personal tweakable OpenID provider.
6
+
7
+ Usage:
8
+ passage [OPTIONS]
9
+
10
+ Options:
11
+ HELP
12
+
13
+ require 'optparse'
14
+ require 'passage'
15
+
16
+ exec = {}
17
+ options = { 'ids_file' => ENV['IDSFILE'] || 'ids.yml' }
18
+
19
+ opts = OptionParser.new do |opts|
20
+ opts.banner = help
21
+
22
+ opts.on("--ids [IDSFILE]", "Configuration file for identities (yaml).") do |c|
23
+ options['ids_file'] = c
24
+ end
25
+
26
+ opts.on("--version", "Display current version.") do
27
+ puts "Passage v" + Passage::VERSION
28
+ exit 0
29
+ end
30
+ end
31
+
32
+ begin
33
+ opts.parse!
34
+ rescue OptionParser::InvalidOption
35
+ puts "passage: #{$!.message}"
36
+ puts "passage: try 'passage --help' for more information"
37
+ exit 1
38
+ end
39
+
40
+ require 'passage/app'
41
+ Passage::App.run!(options)
42
+
data/config.ru ADDED
@@ -0,0 +1,10 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[lib])
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+
6
+ require 'passage'
7
+ require 'passage/app'
8
+
9
+ run Passage::App
10
+
data/ids.yml.example ADDED
@@ -0,0 +1,7 @@
1
+ 'http://localhost:9292/foo':
2
+ email: foo@foo.org
3
+ 'http://77.127.181.233:9292/foo':
4
+ email: foo@foo.org
5
+ 'http://77.124.212.222:4567/pookie':
6
+ email: goo@goo.org
7
+
@@ -0,0 +1,111 @@
1
+ require 'sinatra/reloader'
2
+ require 'openid'
3
+ require 'openid/consumer/discovery'
4
+ require 'openid/extensions/sreg'
5
+ require 'openid/extensions/pape'
6
+ require 'openid/store/filesystem'
7
+ require 'yaml'
8
+
9
+ module Passage
10
+ class App < Sinatra::Base
11
+ include OpenID::Server
12
+
13
+ CHECK_ID_REQ_K = "__passage_ckid"
14
+
15
+ set :logging, true
16
+ configure(:development) do
17
+ register Sinatra::Reloader
18
+ end
19
+
20
+ [:post, :get].each do |meth|
21
+ send meth, '/' do
22
+ oidreq = get_oid_from_params_or_session(params)
23
+ return "This is an OpenID server endpoint." unless oidreq
24
+
25
+ oidresp = nil
26
+ if oidreq.kind_of?(CheckIDRequest)
27
+ use_when_not_authorized(oidreq)
28
+
29
+ identity = oidreq.identity
30
+ must_be_authorized!(identity, oidreq.trust_root)
31
+ oidresp = create_positive_assertion(oidreq, identity)
32
+ else
33
+ oidresp = server.handle_request(oidreq)
34
+ end
35
+
36
+ handle_response(oidresp)
37
+ end
38
+ end
39
+
40
+ get '/:identity' do
41
+ @identity = params[:identity]
42
+ @endpoint = server_url
43
+ erb :identity
44
+ end
45
+
46
+ private
47
+ def must_be_authorized!(id, root)
48
+ true
49
+ end
50
+
51
+ def add_sreg(oidreq, oidresp, identity)
52
+ sregreq = OpenID::SReg::Request.from_openid_request(oidreq)
53
+ return if sregreq.nil?
54
+
55
+ ym = YAML::load_file(settings.ids_file)
56
+ return if ym.nil? || ym[identity].nil?
57
+
58
+ puts "** sending out #{ym[identity]}" # todo: proper log
59
+
60
+ sregresp = OpenID::SReg::Response.extract_response(sregreq, ym[identity])
61
+ oidresp.add_extension(sregresp)
62
+ end
63
+
64
+ def create_positive_assertion(oidreq, identity)
65
+ oidresp = oidreq.answer(true, nil, identity)
66
+ add_sreg(oidreq, oidresp, identity)
67
+ oidresp
68
+ end
69
+
70
+ def get_oid_from_params_or_session(params)
71
+ begin
72
+ oidreq = server.decode_request(params)
73
+ rescue ProtocolError => e
74
+ oidreq = session[CHECK_ID_REQ_K]
75
+ session[CHECK_ID_REQ_K] = nil
76
+ end
77
+ oidreq
78
+ end
79
+
80
+ def use_when_not_authorized(oidreq)
81
+ session[CHECK_ID_REQ_K] = oidreq
82
+ end
83
+
84
+ def handle_response(oidresp)
85
+ if oidresp.needs_signing
86
+ signed_response = server.signatory.sign(oidresp)
87
+ end
88
+ web_response = server.encode_response(oidresp)
89
+
90
+ case web_response.code
91
+ when HTTP_REDIRECT
92
+ redirect web_response.headers['location']
93
+ else
94
+ web_response.body
95
+ end
96
+ end
97
+
98
+ def server
99
+ if @server.nil?
100
+ dir = Pathname.new(".").join('db').join('openid-store')
101
+ store = OpenID::Store::Filesystem.new(dir)
102
+ @server = Server.new(store, server_url)
103
+ end
104
+ return @server
105
+ end
106
+
107
+ def server_url
108
+ "#{request.scheme}://#{request.host}:#{request.port}/"
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,3 @@
1
+ module Passage
2
+ VERSION = '0.1.0'
3
+ end
data/lib/passage.rb ADDED
@@ -0,0 +1 @@
1
+ require 'passage/version'
data/test/helper.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ require 'passage'
15
+
16
+ class Test::Unit::TestCase
17
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestPassage < Test::Unit::TestCase
4
+ def test_something_for_real
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: passage
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Dotan Nahum
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-14 00:00:00 +02:00
19
+ default_executable: passage
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: sinatra
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 3
31
+ segments:
32
+ - 0
33
+ version: "0"
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ type: :runtime
37
+ prerelease: false
38
+ name: ruby-openid
39
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ type: :runtime
51
+ prerelease: false
52
+ name: sinatra-reloader
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ type: :development
65
+ prerelease: false
66
+ name: bundler
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ~>
71
+ - !ruby/object:Gem::Version
72
+ hash: 23
73
+ segments:
74
+ - 1
75
+ - 0
76
+ - 0
77
+ version: 1.0.0
78
+ requirement: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ type: :development
81
+ prerelease: false
82
+ name: jeweler
83
+ version_requirements: &id005 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ hash: 7
89
+ segments:
90
+ - 1
91
+ - 5
92
+ - 2
93
+ version: 1.5.2
94
+ requirement: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ type: :development
97
+ prerelease: false
98
+ name: rcov
99
+ version_requirements: &id006 !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirement: *id006
109
+ description: A simple, tweakable OpenID provider for private use.
110
+ email: jondotan@gmail.com
111
+ executables:
112
+ - passage
113
+ extensions: []
114
+
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.rdoc
118
+ files:
119
+ - config.ru
120
+ - ids.yml.example
121
+ - lib/passage.rb
122
+ - lib/passage/app.rb
123
+ - lib/passage/version.rb
124
+ - LICENSE.txt
125
+ - README.rdoc
126
+ - test/helper.rb
127
+ - test/test_passage.rb
128
+ - bin/passage
129
+ has_rdoc: true
130
+ homepage: http://github.com/jondot/passage
131
+ licenses:
132
+ - MIT
133
+ post_install_message:
134
+ rdoc_options: []
135
+
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ none: false
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ hash: 3
153
+ segments:
154
+ - 0
155
+ version: "0"
156
+ requirements: []
157
+
158
+ rubyforge_project:
159
+ rubygems_version: 1.3.7
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: Your personal tweakable OpenID server.
163
+ test_files:
164
+ - test/helper.rb
165
+ - test/test_passage.rb