omnigollum-bibanon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) Arran Cudbard-Bell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the 'Software'), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # omnigollum - omniauth meets gollum
2
+
3
+ ## Installation
4
+
5
+ ### Rubygem
6
+
7
+ A [rubygem](https://rubygems.org/gems/omniauth-bibanon) using prepatched dependencies has been made available by the Bibliotheca Anonoma for your convenience. Click the link for more info.
8
+
9
+ ### Manual
10
+
11
+ Clone into your ruby library path.
12
+
13
+ git clone git://github.com/arr2036/omnigollum.git
14
+
15
+ ## Configuration
16
+
17
+ Omnigollum executes an OmniAuth::Builder proc/block to figure out which providers you've configured,
18
+ then passes it on to omniauth to create the actual omniauth configuration.
19
+
20
+ To configure both omniauth and omnigollum you should add the following to your config.ru file.
21
+
22
+ ### Load omnigollum library
23
+ ```ruby
24
+ require 'omnigollum'
25
+ ```
26
+
27
+ ### Load individual provider libraries
28
+ ```ruby
29
+ require 'omniauth/strategies/twitter'
30
+ require 'omniauth/strategies/open_id'
31
+ ```
32
+
33
+ ### Set configuration
34
+ ```ruby
35
+ options = {
36
+ # OmniAuth::Builder block is passed as a proc
37
+ :providers => Proc.new do
38
+ provider :twitter, 'CONSUMER_KEY', 'CONSUMER_SECRET'
39
+ provider :open_id, OpenID::Store::Filesystem.new('/tmp')
40
+ end,
41
+ :dummy_auth => false
42
+ }
43
+
44
+ # :omnigollum options *must* be set before the Omnigollum extension is registered
45
+ Precious::App.set(:omnigollum, options)
46
+ ```
47
+
48
+ ### Register omnigollum extension with sinatra
49
+ ```ruby
50
+ Precious::App.register Omnigollum::Sinatra
51
+ ```
52
+
53
+ ## Required patches
54
+
55
+ ### mustache
56
+
57
+ Must be at v0.99.5 (currently unreleased), replace the gem version with 6c4e12d58844d99909df or
58
+ the current HEAD.
59
+
60
+
61
+
62
+ ### gollum
63
+
64
+ Merge the commits from [here](https://github.com/github/gollum/pull/181)
65
+
66
+
67
+
68
+
@@ -0,0 +1,242 @@
1
+ require 'cgi'
2
+ require 'omniauth'
3
+ require 'mustache/sinatra'
4
+ require 'sinatra/base'
5
+
6
+ module Omnigollum
7
+ module Views; class Layout < Mustache; end; end
8
+ module Models
9
+ class OmniauthUserInitError < StandardError; end
10
+
11
+ class User
12
+ attr_reader :uid, :name, :email, :provider
13
+ end
14
+
15
+ class OmniauthUser < User
16
+ def initialize (hash)
17
+ # Validity checks, don't trust providers
18
+ @uid = hash['uid']
19
+ raise OmniauthUserInitError, "Invalid data from provider, 'uid' must not be empty or whitespace" if @uid.to_s.strip.empty?
20
+
21
+ @name = hash['info']['name'].to_s.strip
22
+ raise OmniauthUserInitError, "Invalid data from provider, 'info => name' must not be empty or whitespace" if @name.empty?
23
+
24
+ @email = hash['info']['email'].to_s.strip if hash['info'].has_key?('email')
25
+ @provider = hash['provider']
26
+ self
27
+ end
28
+ end
29
+ end
30
+
31
+ module Helpers
32
+ def user_authed?
33
+ session.has_key? :auth_user
34
+ end
35
+
36
+ def user_auth
37
+ @title = 'Authentication is required'
38
+ @subtext = 'Please choose a login service'
39
+ show_login
40
+ end
41
+
42
+ def kick_back
43
+ redirect !request.referrer.nil? && request.referrer !~ /#{Regexp.escape(settings.send(:omnigollum)[:route_prefix])}\/.*/ ?
44
+ request.referrer:
45
+ '/'
46
+ halt
47
+ end
48
+
49
+ def get_user
50
+ session[:auth_user]
51
+ end
52
+
53
+ def user_deauth
54
+ session.delete :auth_user
55
+ end
56
+
57
+ def auth_config
58
+ options = settings.send(:omnigollum)
59
+
60
+ @auth = {
61
+ :route_prefix => options[:route_prefix],
62
+ :providers => options[:provider_names],
63
+ :path_images => options[:path_images],
64
+ :logo_suffix => options[:logo_suffix],
65
+ :logo_missing => options[:logo_missing]
66
+ }
67
+ end
68
+
69
+ def show_login
70
+ auth_config
71
+ require settings.send(:omnigollum)[:path_views] + '/login'
72
+ halt mustache Omnigollum::Views::Login
73
+ end
74
+
75
+ def commit_message
76
+ if user_authed?
77
+ user = get_user
78
+ return { :message => params[:message], :name => user.name, :email => user.email}
79
+ else
80
+ return { :message => params[:message]}
81
+ end
82
+ end
83
+ end
84
+
85
+ # Config class provides default values for omnigollum configuration, and an array
86
+ # of all providers which have been enabled if a omniauth config block is passed to
87
+ # eval_omniauth_config.
88
+ class Config
89
+ attr_accessor :default_options
90
+ class << self; attr_accessor :default_options; end
91
+
92
+ @default_options = {
93
+ :protected_routes => [
94
+ '/revert/*',
95
+ '/revert',
96
+ '/create/*',
97
+ '/create',
98
+ '/edit/*',
99
+ '/edit'],
100
+
101
+ :route_prefix => '/__omnigollum__',
102
+ :dummy_auth => true,
103
+ :providers => Proc.new { provider :github, '', '' },
104
+ :path_base => dir = File.expand_path(File.dirname(__FILE__) + '/..'),
105
+ :logo_suffix => "_logo.png",
106
+ :logo_missing => "omniauth", # Set to false to disable missing logos
107
+ :path_images => "#{dir}/public/images",
108
+ :path_views => "#{dir}/views",
109
+ :path_templates => "#{dir}/templates",
110
+ :provider_names => []
111
+ }
112
+
113
+ def initialize
114
+ @default_options = self.class.default_options
115
+ end
116
+
117
+ # Register provider name
118
+ #
119
+ # name - Provider symbol
120
+ # args - Arbitrary arguments
121
+ def provider(name, *args)
122
+ @default_options[:provider_names].push name
123
+ end
124
+
125
+ # Evaluate procedure calls in an omniauth config block/proc in the context
126
+ # of this class.
127
+ #
128
+ # This allows us to learn about omniauth config items that would otherwise be inaccessible.
129
+ #
130
+ # block - Omniauth proc or block
131
+ def eval_omniauth_config(&block)
132
+ self.instance_eval(&block)
133
+ end
134
+
135
+ # Catches missing methods we haven't implemented, but which omniauth accepts
136
+ # in its config block.
137
+ #
138
+ # args - Arbitrary list of arguments
139
+ def method_missing(*args); end
140
+ end
141
+
142
+ module Sinatra
143
+ def self.registered(app)
144
+ # As options determine which routes are created, they must be set before registering omniauth
145
+ config = Omnigollum::Config.new
146
+
147
+ options = app.settings.respond_to?(:omnigollum) ?
148
+ config.default_options.merge(app.settings.send(:omnigollum)) :
149
+ config.default_options
150
+
151
+ # Set omniauth path prefix based on options
152
+ OmniAuth.config.path_prefix = options[:route_prefix] + OmniAuth.config.path_prefix
153
+
154
+ # Setup test_mode options
155
+ if options[:dummy_auth]
156
+ OmniAuth.config.test_mode = true
157
+ OmniAuth.config.mock_auth[:default] = {
158
+ 'uid' => '12345',
159
+ "info" => {
160
+ "email" => "user@example.com",
161
+ "name" => "example user"
162
+ },
163
+ 'provider' => 'local'
164
+ }
165
+ end
166
+ # Register helpers
167
+ app.helpers Helpers
168
+
169
+ # Enable sinatra session support
170
+ app.set :sessions, true
171
+
172
+ # Setup omniauth providers
173
+ if !options[:providers].nil?
174
+ app.use OmniAuth::Builder, &options[:providers]
175
+
176
+ # You told omniauth, now tell us!
177
+ config.eval_omniauth_config &options[:providers] if options[:provider_names].count == 0
178
+ end
179
+
180
+ # Pre-empt protected routes
181
+ options[:protected_routes].each { |route| app.before(route) { user_auth unless user_authed? }}
182
+
183
+ # Populates instance variables used to display currently logged in user
184
+ app.before '/*' do
185
+ @user_authed = user_authed?
186
+ @user = get_user
187
+ end
188
+
189
+ # Explicit login (user followed login link) clears previous redirect info
190
+ app.before options[:route_prefix] + '/login' do
191
+ kick_back if user_authed?
192
+ @auth_params = "?origin=#{CGI.escape(request.referrer)}" if !request.referrer.nil?
193
+ user_auth
194
+ end
195
+
196
+ app.before options[:route_prefix] + '/logout' do
197
+ user_deauth
198
+ kick_back
199
+ end
200
+
201
+ app.before options[:route_prefix] + '/auth/failure' do
202
+ user_deauth
203
+ @title = 'Authentication failed'
204
+ @subtext = 'Provider did not validate your credentials (#{param[:message]}) - please retry or choose another login service'
205
+ @auth_params = "?origin=#{CGI.escape(request.env['omniauth.origin'])}" if !request.env['omniauth.origin'].nil?
206
+ show_login
207
+ end
208
+
209
+ app.before options[:route_prefix] + '/auth/:name/callback' do
210
+ begin
211
+ if !request.env['omniauth.auth'].nil?
212
+ session[:auth_user] = Omnigollum::Models::OmniauthUser.new(request.env['omniauth.auth'])
213
+ redirect request.env['omniauth.origin']
214
+ elsif !user_authed?
215
+ @title = 'Authentication failed'
216
+ @subtext = "Omniauth experienced an error processing your request"
217
+ @auth_params = "?origin=#{CGI.escape(request.env['omniauth.origin'])}" if !request.env['omniauth.origin'].nil?
218
+ show_login
219
+ end
220
+ rescue Omnigollum::Models::OmniauthUserInitError => fail_reason
221
+ @title = 'Authentication failed'
222
+ @subtext = fail_reason
223
+ @auth_params = "?origin=#{CGI.escape(request.env['omniauth.origin'])}" if !request.env['omniauth.origin'].nil?
224
+ show_login
225
+ end
226
+ end
227
+
228
+ app.before options[:route_prefix] + '/images/:image.png' do
229
+ content_type :png
230
+ send_file options[:path_images] + '/' + params[:image] + '.png'
231
+ end
232
+
233
+ # Stop sinatra processing and hand off to omniauth
234
+ app.before options[:route_prefix] + '/auth/:provider' do
235
+ halt 404
236
+ end
237
+
238
+ # Write the actual config back to the app instance
239
+ app.set(:omnigollum, options)
240
+ end
241
+ end
242
+ end
@@ -0,0 +1,20 @@
1
+ <div id="wiki-wrapper" class="edit">
2
+ <div id="head">
3
+ <h1>{{title}}</h1>
4
+ </div>
5
+ <div id="login" class="login_form">
6
+ <h2>{{subtext}}</h2>
7
+ <ul class="actions">
8
+ {{#providers_active}}
9
+ <li class="minibutton">
10
+ <a style="height:auto" href="{{{provider_url}}}">
11
+ {{#image}}
12
+ <img src="{{{image}}}" alt="{{image_alt}}" title="{{image_title}}"/>
13
+ {{/image}}
14
+ <div style="text-align: center">{{{name}}}</div>
15
+ </a>
16
+ </li>
17
+ {{/providers_active}}
18
+ </ul>
19
+ </div>
20
+ </div>
@@ -0,0 +1,42 @@
1
+ module Omnigollum
2
+ module Views
3
+ class Login < Mustache
4
+ self.template_path = File.expand_path("../../templates", __FILE__)
5
+ self.template_name = 'Login'
6
+
7
+ def title
8
+ @title
9
+ end
10
+
11
+ def subtext
12
+ @subtext
13
+ end
14
+
15
+ def providers_active
16
+ providers = []
17
+ @auth[:providers].each do |name|
18
+ provider_attr = {
19
+ :name => OmniAuth::Utils.camelize(name),
20
+ :provider_url => @auth[:route_prefix] + "/auth/#{name}" + (defined?(@auth_params) ? @auth_params : '')
21
+ }
22
+ name = name.to_s
23
+ if has_logo?(logo_name = name) || (logo_name = @auth[:logo_missing])
24
+ provider_attr[:image] = get_logo logo_name
25
+ provider_attr[:image_alt] = "#{provider_attr[:name]} logo"
26
+ provider_attr[:image_title] = "Connect with #{provider_attr[:name]}"
27
+ end
28
+ providers.push provider_attr
29
+ end
30
+ providers
31
+ end
32
+
33
+ def has_logo?(name)
34
+ File.exists?(@auth[:path_images] + '/' + name + @auth[:logo_suffix])
35
+ end
36
+
37
+ def get_logo(name)
38
+ @auth[:route_prefix] + "/images/#{name}" + @auth[:logo_suffix]
39
+ end
40
+ end
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omnigollum-bibanon
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Arran Cudbard-Bell
14
+ - Tenshi Hinanawi
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-02-05 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: gollum-bibanon
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: omniauth
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: mustache-bibanon
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description: |
64
+ Omnigollum adds support for OmniAuth in Gollum. It executes an OmniAuth::Builder proc/block to figure out which providers you've configured, then passes it on to omniauth to create the actual omniauth configuration.
65
+
66
+ See https://github.com/treeofsephiroth/omnigollum-bibanon for usage instructions.
67
+
68
+ Some of Omnigollum's dependencies had to be patched before use. These patches have already been made into dependent gems for your convenience.
69
+
70
+ email: cockmomgler@gmail.com
71
+ executables: []
72
+
73
+ extensions: []
74
+
75
+ extra_rdoc_files:
76
+ - Readme.md
77
+ - LICENSE
78
+ files:
79
+ - Readme.md
80
+ - LICENSE
81
+ - lib/omnigollum.rb
82
+ - public/images/facebook_logo.png
83
+ - public/images/omniauth_logo.png
84
+ - public/images/twitter_logo.png
85
+ - public/images/blogger_logo.png
86
+ - public/images/google_logo.png
87
+ - public/images/youtube_logo.png
88
+ - public/images/bitly_logo.png
89
+ - public/images/github_logo.png
90
+ - templates/Login.mustache
91
+ - views/login.rb
92
+ homepage: https://github.com/treeofsephiroth/omnigollum-bibanon
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.11
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Omnigollum makes it easy to use OmniAuth with Gollum
125
+ test_files: []
126
+