opensesame 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +36 -0
  4. data/app/assets/images/open_sesame/github_64.png +0 -0
  5. data/app/assets/javascripts/open_sesame/application.js +15 -0
  6. data/app/assets/stylesheets/open_sesame/application.css +14 -0
  7. data/app/assets/stylesheets/open_sesame/opensesame_bootstrap.css.scss +8 -0
  8. data/app/assets/stylesheets/open_sesame/welcome.css.scss +52 -0
  9. data/app/controllers/open_sesame/application_controller.rb +6 -0
  10. data/app/controllers/open_sesame/sessions_controller.rb +27 -0
  11. data/app/helpers/open_sesame/application_helper.rb +11 -0
  12. data/app/helpers/open_sesame/sessions_helper.rb +4 -0
  13. data/app/views/layouts/open_sesame/application.html.erb +23 -0
  14. data/app/views/open_sesame/sessions/new.html.erb +7 -0
  15. data/config/routes.rb +8 -0
  16. data/lib/open_sesame/configuration.rb +59 -0
  17. data/lib/open_sesame/controller_helper.rb +18 -0
  18. data/lib/open_sesame/engine.rb +33 -0
  19. data/lib/open_sesame/version.rb +3 -0
  20. data/lib/open_sesame/view_helper.rb +15 -0
  21. data/lib/open_sesame.rb +19 -0
  22. data/lib/opensesame.rb +1 -0
  23. data/lib/tasks/opensesame_tasks.rake +4 -0
  24. data/spec/dummy/README.rdoc +261 -0
  25. data/spec/dummy/Rakefile +7 -0
  26. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  27. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  30. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/spec/dummy/config/application.rb +62 -0
  32. data/spec/dummy/config/boot.rb +10 -0
  33. data/spec/dummy/config/database.yml +25 -0
  34. data/spec/dummy/config/environment.rb +5 -0
  35. data/spec/dummy/config/environments/development.rb +37 -0
  36. data/spec/dummy/config/environments/production.rb +67 -0
  37. data/spec/dummy/config/environments/test.rb +37 -0
  38. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy/config/initializers/inflections.rb +15 -0
  40. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  41. data/spec/dummy/config/initializers/opensesame.rb +5 -0
  42. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  43. data/spec/dummy/config/initializers/session_store.rb +8 -0
  44. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  45. data/spec/dummy/config/locales/en.yml +5 -0
  46. data/spec/dummy/config/routes.rb +4 -0
  47. data/spec/dummy/config.ru +4 -0
  48. data/spec/dummy/db/test.sqlite3 +0 -0
  49. data/spec/dummy/log/test.log +150 -0
  50. data/spec/dummy/public/404.html +26 -0
  51. data/spec/dummy/public/422.html +26 -0
  52. data/spec/dummy/public/500.html +25 -0
  53. data/spec/dummy/public/favicon.ico +0 -0
  54. data/spec/dummy/script/rails +6 -0
  55. data/spec/lib/open_sesame/configuration_spec.rb +58 -0
  56. data/spec/lib/open_sesame_spec.rb +10 -0
  57. data/spec/spec_helper.rb +17 -0
  58. metadata +199 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
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,3 @@
1
+ = OpenSesame
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'OpenSesame'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+ APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
24
+ load 'rails/tasks/engine.rake'
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rspec/core/rake_task'
29
+
30
+ RSpec::Core::RakeTask.new do |t|
31
+ # t.pattern = "./spec/**/*_spec.rb" # default
32
+ # Put spec opts in a file named .rspec in root
33
+ end
34
+
35
+ desc "Run the specs"
36
+ task :default => ["spec"]
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,14 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require ./opensesame_bootstrap
13
+ *= require ./welcome
14
+ */
@@ -0,0 +1,8 @@
1
+ @import "bootstrap";
2
+
3
+ .content-header {
4
+ border-bottom: 1px solid #ccc;
5
+ margin-bottom: 1em;
6
+
7
+ h1 { font-size: 24px; }
8
+ }
@@ -0,0 +1,52 @@
1
+ body { font: 14px/1.333 sans-serif; color: #444; background: #eee; }
2
+
3
+ a { color: #980905; }
4
+ a:hover, a:focus, a:active { text-decoration: none; }
5
+
6
+ h1 { margin: 0 0 0.2em; font-size: 36px; }
7
+ h2 { margin: 0 0 0.75em; font-size: 21px; }
8
+ h3 { margin: 0 0 0.333em; font-size: 16px; font-weight: normal; }
9
+ p { margin: 0 0 1.333em; }
10
+ em { font-style: italic; }
11
+ table { border-collapse: separate; border-spacing: 0; margin: 0; vertical-align: middle; }
12
+ th { font-weight: bold; }
13
+ th, td { padding: 5px 8px 5px 5px; text-align: left; vertical-align: middle; }
14
+ pre, code { font-family: monospace, sans-serif; font-size: 1em; color:#080; }
15
+
16
+ .inner-container { position:relative; overflow:hidden; width: 780px; padding: 40px 60px; border: 1px solid #ccc; margin: 40px auto 20px; background: #fff; -webkit-box-shadow: 0 0 15px rgba(0,0,0,0.1); -moz-box-shadow: 0 0 15px rgba(0,0,0,0.1); box-shadow: 0 0 15px rgba(0,0,0,0.1); }
17
+
18
+ .inner-container pre,
19
+ .inner-container .prettyprint { padding: 0; border: 0; margin: 0 0 20px; font-size: 13px; background: #fff; }
20
+
21
+ .ribbon { position: absolute; top: -1px; right: -1px; opacity: 0.9; }
22
+ .ribbon:hover, .ribbon:focus, .ribbon:active { opacity: 1; }
23
+ .ribbon img { display: block; border: 0; }
24
+
25
+ .header { padding-right:80px; }
26
+ .header, .navigation { border-bottom: 1px solid #ccc; }
27
+ .navigation { padding: 10px; margin: 0px; background-color: #EEE }
28
+
29
+ .section { margin: 40px 0 20px; }
30
+
31
+ .example { padding: 20px; border: 1px solid #ccc; margin: 10px -20px 20px; }
32
+
33
+ .footer { margin: 20px 0 50px; font-size: 11px; color: #666; text-align: center; }
34
+ .footer a { color: #666; }
35
+
36
+ .field, .actions { margin: 0 0 1.333em; }
37
+ .field_show { margin: 0 0 0.666em; }
38
+
39
+ .admin_notice { color: green }
40
+ .details { color: #CCC; padding: 5px 0 }
41
+
42
+ .header_buttons { margin: -8px 0px 20px 0px }
43
+ .footer_buttons { margin: 1em 0 0 0 }
44
+
45
+ .flash_notice { margin: 0 0 1em 0; color: green; font-weight: bold }
46
+ .flash_alert { margin: 0 0 1em 0; color: #980905; font-weight: bold }
47
+
48
+ .field input { width: 300px; height: 25px; font: 14px/1.333 sans-serif; padding-left: 4px; }
49
+ .field input { border: 1px solid #CCC; }
50
+
51
+ #grant, #deny { padding: 5px 0px }
52
+ .green { color: green }
@@ -0,0 +1,6 @@
1
+ module OpenSesame
2
+ class ApplicationController < ActionController::Base
3
+ unloadable
4
+ include OpenSesame::ControllerHelper
5
+ end
6
+ end
@@ -0,0 +1,27 @@
1
+ module OpenSesame
2
+ class SessionsController < ApplicationController
3
+ unloadable
4
+
5
+ skip_before_filter :authenticate_opensesame!
6
+
7
+ def new
8
+ end
9
+
10
+ def create
11
+ warden.authenticate!(:scope => :opensesame)
12
+ flash[:success] = "Welcome!"
13
+ redirect_to main_app.root_url
14
+ end
15
+
16
+ def destroy
17
+ warden.logout(:opensesame)
18
+ flash[:notice] = "Logged out!"
19
+ redirect_to main_app.root_url
20
+ end
21
+
22
+ def failure
23
+ raise params.inspect
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module OpenSesame
2
+ module ApplicationHelper
3
+ include OpenSesame::ViewHelper
4
+
5
+ def page_header(text)
6
+ content_tag(:header, class: "content-header") do
7
+ content_tag(:h1, text)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module OpenSesame
2
+ module SessionsHelper
3
+ end
4
+ end
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>OpenSesame</title>
5
+ <%= stylesheet_link_tag "open_sesame/application", :media => "all" %>
6
+ <%= javascript_include_tag "open_sesame/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <div class="container">
12
+ <div class="inner-container">
13
+ <% flash.each do |type, message| %>
14
+ <div class="alert alert-<%= type %> <%= type %>" data-role="flash-<%= type %>">
15
+ <%= message %>
16
+ </div>
17
+ <% end %>
18
+ <%= yield %>
19
+ </div>
20
+ </div>
21
+
22
+ </body>
23
+ </html>
@@ -0,0 +1,7 @@
1
+ <%= page_header 'Login' %>
2
+ <p>Welcome! You have arrived at a <%= OpenSesame.organization_name.titleize %> application requiring additional credentials. To continue, please log in via:</p>
3
+ <div class="table">
4
+ <div class="table-cell align-middle">
5
+ <%= login_image_link_to('github') %>
6
+ </div>
7
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,8 @@
1
+ OpenSesame::Engine.routes.draw do
2
+ root :to => "sessions#new"
3
+
4
+ match '/auth/:provider/callback', :to => 'sessions#create'
5
+ match '/auth/failure', :to => 'sessions#failure'
6
+ match '/login', :to => 'sessions#new', :as => :sign_in
7
+ match '/logout', :to => 'sessions#destroy', :as => :sign_out
8
+ end
@@ -0,0 +1,59 @@
1
+ module OpenSesame
2
+ class ConfigurationError < RuntimeError; end
3
+
4
+ class Configuration
5
+ CONFIGURABLE_ATTRIBUTES = [:organization_name, :mount_prefix, :github_client]
6
+ attr_accessor *CONFIGURABLE_ATTRIBUTES
7
+
8
+ def mounted_at(mount_prefix)
9
+ self.mount_prefix = mount_prefix
10
+ end
11
+
12
+ def github(client_id, client_secret)
13
+ self.github_client = { :id => client_id, :secret => client_secret }
14
+ end
15
+
16
+ def organization(organization_name)
17
+ self.organization_name = organization_name
18
+ end
19
+
20
+ def configure
21
+ yield self
22
+ end
23
+
24
+ def valid?
25
+ self.organization_name && self.organization_name.is_a?(String) &&
26
+ self.mount_prefix && self.mount_prefix.is_a?(String) &&
27
+ self.github_client.is_a?(Hash) &&
28
+ [:id, :secret].all? { |key| self.github_client.keys.include?(key) }
29
+ end
30
+
31
+ def validate!
32
+ return true if valid?
33
+ message = <<-MESSAGE
34
+
35
+
36
+ Update your OpenSesame configuration. Example:
37
+
38
+ # config/initializers/open_sesame.rb
39
+ OpenSesame.configure do |config|
40
+ config.organization 'challengepost'
41
+ config.mounted_at '/welcome'
42
+ config.github ENV['CAPITAN_GITHUB_KEY'], ENV['CAPITAN_GITHUB_SECRET']
43
+ end
44
+
45
+ When you register the app, make sure to point the callback url to
46
+ the engine mountpoint + /auth/github/callback. For example, if your
47
+ development app is on http://localhost:3000 and you're mounting
48
+ the OpenSesame::Engine at '/welcome', your github
49
+ callback url should be:
50
+
51
+ http://localhost:3000/auth/github/callback
52
+
53
+ MESSAGE
54
+
55
+ raise ConfigurationError.new(message)
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,18 @@
1
+ module OpenSesame
2
+ module ControllerHelper
3
+ extend ActiveSupport::Concern
4
+
5
+ def warden
6
+ env['warden']
7
+ end
8
+
9
+ def authenticate_opensesame!
10
+ warden.authenticate!(:scope => :opensesame)
11
+ end
12
+
13
+ def current_opensesame_user
14
+ warden.user(:scope => :opensesame)
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ require 'opensesame-github'
2
+
3
+ module OpenSesame
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace OpenSesame
6
+
7
+ config.generators do |g|
8
+ g.test_framework :rspec, :view_specs => false
9
+ end
10
+
11
+ ActiveSupport.on_load(:action_controller) do
12
+ include OpenSesame::ControllerHelper
13
+ end
14
+
15
+ ActiveSupport.on_load(:action_view) do
16
+ include OpenSesame::ViewHelper
17
+ end
18
+
19
+ initializer "gardenwall.middleware", :after => :load_config_initializers do |app|
20
+ OpenSesame.configuration.validate!
21
+
22
+ OpenSesame::Github.organization_name = OpenSesame.organization_name
23
+
24
+ middleware.use OmniAuth::Strategies::GitHub, OpenSesame.github_client[:id], OpenSesame.github_client[:secret]
25
+
26
+ app.config.middleware.use Warden::Manager do |manager|
27
+ manager.scope_defaults :opensesame, :strategies => [:opensesame_github]
28
+ manager.failure_app = lambda { |env| OpenSesame::SessionsController.action(:new).call(env) }
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module OpenSesame
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,15 @@
1
+ module OpenSesame
2
+ module ViewHelper
3
+
4
+ def login_image_link_to(provider)
5
+ link_to identity_request_path(provider), class: "btn btn-large" do
6
+ image_tag("open_sesame/#{provider}_64.png") + "<br/><span>#{provider}</span>".html_safe
7
+ end
8
+ end
9
+
10
+ def identity_request_path(provider)
11
+ [OpenSesame.mount_prefix, 'auth', provider].join('/')
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module OpenSesame
2
+ extend self
3
+
4
+ autoload :Configuration, 'open_sesame/configuration'
5
+ autoload :ControllerHelper, 'open_sesame/controller_helper'
6
+ autoload :ViewHelper, 'open_sesame/view_helper'
7
+
8
+ delegate *Configuration::CONFIGURABLE_ATTRIBUTES, :to => :configuration
9
+
10
+ mattr_accessor :configuration
11
+ @@configuration = Configuration.new
12
+
13
+ def configure(&block)
14
+ yield configuration
15
+ configuration
16
+ end
17
+ end
18
+
19
+ require "open_sesame/engine"
data/lib/opensesame.rb ADDED
@@ -0,0 +1 @@
1
+ require "open_sesame"
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :opensesame do
3
+ # # Task goes here
4
+ # end