sso_clyent 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 (55) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +111 -0
  4. data/Rakefile +40 -0
  5. data/app/assets/javascripts/sso_clyent/application.js +15 -0
  6. data/app/assets/stylesheets/sso_clyent/application.css +13 -0
  7. data/app/controllers/sso_clyent/application_controller.rb +5 -0
  8. data/app/controllers/sso_clyent/user_sessions_controller.rb +41 -0
  9. data/app/helpers/sso_clyent/application_helper.rb +4 -0
  10. data/app/views/layouts/sso_clyent/application.html.erb +14 -0
  11. data/config/routes.rb +10 -0
  12. data/lib/sso_clyent/base.rb +1 -0
  13. data/lib/sso_clyent/controllers/current_user_helpers.rb +28 -0
  14. data/lib/sso_clyent/engine.rb +24 -0
  15. data/lib/sso_clyent/omniauth/strategies/sso.rb +36 -0
  16. data/lib/sso_clyent/version.rb +3 -0
  17. data/lib/sso_clyent.rb +43 -0
  18. data/lib/tasks/sso_clyent_tasks.rake +4 -0
  19. data/spec/dummy/README.rdoc +261 -0
  20. data/spec/dummy/Rakefile +7 -0
  21. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  22. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  24. data/spec/dummy/app/controllers/home_controller.rb +6 -0
  25. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  26. data/spec/dummy/app/models/user.rb +3 -0
  27. data/spec/dummy/app/views/home/index.html.erb +0 -0
  28. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  29. data/spec/dummy/config/application.rb +71 -0
  30. data/spec/dummy/config/boot.rb +10 -0
  31. data/spec/dummy/config/database.yml +68 -0
  32. data/spec/dummy/config/environment.rb +5 -0
  33. data/spec/dummy/config/environments/development.rb +39 -0
  34. data/spec/dummy/config/environments/production.rb +67 -0
  35. data/spec/dummy/config/environments/test.rb +37 -0
  36. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  37. data/spec/dummy/config/initializers/inflections.rb +15 -0
  38. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  39. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  40. data/spec/dummy/config/initializers/session_store.rb +8 -0
  41. data/spec/dummy/config/initializers/sso_clyent.rb +2 -0
  42. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  43. data/spec/dummy/config/locales/en.yml +5 -0
  44. data/spec/dummy/config/routes.rb +7 -0
  45. data/spec/dummy/config.ru +4 -0
  46. data/spec/dummy/db/migrate/20121125194622_create_users.rb +10 -0
  47. data/spec/dummy/db/schema.rb +23 -0
  48. data/spec/dummy/log/development.log +43 -0
  49. data/spec/dummy/public/404.html +26 -0
  50. data/spec/dummy/public/422.html +26 -0
  51. data/spec/dummy/public/500.html +25 -0
  52. data/spec/dummy/public/favicon.ico +0 -0
  53. data/spec/dummy/script/rails +6 -0
  54. data/spec/spec_helper.rb +15 -0
  55. metadata +190 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWMyNDc3OTAwNzJmZGEwM2IyMzg4Yjc4N2UxMTA0ZTZjOTMxOWM3YQ==
5
+ data.tar.gz: !binary |-
6
+ OTgwZjRiYTk4NDFkZjBmZDQ1ZTFiZDA4YWFmZjhjYzU3MDBjYmY4OQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ NGI5NWU2ZDk5YzhmMTliZGVkNDMyMjA3OGNmMWNjNjEzY2JjOWU4MWI2YzM4
10
+ NDdlNmRiMjg3N2I1NjM0NmFkMTI3YTlhYTVmNzU0MWJiMGIxMTIzMDAxMmI3
11
+ NmZmMWE4MzUwMzA3OWNlMjY4OWRiZjI0MmYwNWE3ZGE4YTVjMzg=
12
+ data.tar.gz: !binary |-
13
+ NTQxNTAwNWZjYTUzNWRmNGM5MGI5NTgwZjY0NTA4MzI4ODIyNjY0MmVmODBh
14
+ NWVmYWZmZWJkY2JlM2JkMjA4YmYyNzkzMzk5MzkxMmQ5NmM2NWRlN2JlZTA0
15
+ MDBlNzNjZGQxZGJjOWJkNjBhMDcwM2ZjMmMyOTZiZTg2MjA1NDk=
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,111 @@
1
+ gem 'sso_clyent'
2
+ ---
3
+
4
+ Setup following config variables (app.config)
5
+ ---
6
+
7
+ config.sso_clyent = {
8
+ :path => "/sso", # ex '/' - the path where you want to mount the sso_clyent_engine
9
+ :user_class => "User", # ex: User - the class where you store your users info
10
+ :unique_id => "uid", # ex: :uid - the attr of the user model that allows you to identify a user
11
+ :after_sign_in_path => '/', # ex '/' - the path where you want your users to be redirected by default after sign in
12
+
13
+ :provyder => { # info for the omniauth strategy connecting to omniauth_provider
14
+
15
+ :url => "http://localhost:3000#{options[:path_prefix]}", # url of the sso provider
16
+ :authorize_path => '/oauth/authorize', # auth path @ the sso provider
17
+ :token_path => '/oauth/token', # token path @ the sso provider
18
+ :user => { :path => "/auth/user", # path to user info @ the sso provider
19
+ :uid => "id", # name of attribute to correspond to id
20
+ :info => %w(email), # info to retrieve from provider response
21
+ :extras => %w() } # extras
22
+ :app_id => 'YOURAPPID', # your app id to identify @ the provider
23
+ :app_secret => 'YOURAPPSECRET', # your app secret to identify @ the provider
24
+ }
25
+ }
26
+
27
+ You can overwrite following methods in your controllers
28
+ ---
29
+ # def login_required
30
+ # if !current_user
31
+ # respond_to do |format|
32
+ # format.html { redirect_to "#{SsoClyent.path}/auth/sso" }
33
+ # format.json { render :json => { 'error' => 'Access Denied' }.to_json }
34
+ # end
35
+ # end
36
+ # end
37
+ #
38
+ # def current_user
39
+ # return nil unless session[:user_id]
40
+ # users = user_klass
41
+ # uid = userid
42
+ # if users.respond_to?(:"find_by_#{uid}")
43
+ # @current_user ||= users.send(:"find_by_#{uid}", session[:user_id]['uid'])
44
+ # end
45
+ # end
46
+ #
47
+ # def user_klass
48
+ # SsoClyent.user_class
49
+ # end
50
+ #
51
+ # def userid
52
+ # SsoClyent.unique_id
53
+ # end
54
+
55
+
56
+
57
+
58
+ OLD DOCS !
59
+
60
+ # A Rails Engine providing an Omniauth client with single sign on features in a minute.
61
+ #
62
+ # See sso_provyder for the provider part.
63
+ # Based on Devise, Authentifyd and joshsoftware/sso-devise-omniauth-client. Parts directly taken from https://github.com/joshsoftware/sso-devise-omniauth-client
64
+ #
65
+ # install the gem
66
+ #
67
+ # add a config/intializers/sso_clyent.rb file with the following:
68
+ #
69
+ # # Provide sso_clyent with the user_class you use to store your users
70
+ # SsoClyent.user_class = "User"
71
+ #
72
+ # # ... and the name of the attribute / field you use to identify your user
73
+ # # across services
74
+ # SsoClyent.unique_id = "unique_id"
75
+ #
76
+ # # Also provide sso_clyent with the sso_provider you want to target
77
+ # #
78
+ # # * url,
79
+ # # * authorizeurl, and
80
+ # # * access_token url
81
+ # # * user
82
+ # # + where to get user_info from provider
83
+ # # + the unique id you expect from provider
84
+ # # + the info you expect from provider
85
+ # # + the extra_info you expect from provider
86
+ # #
87
+ # # NB: the provider is expected to respond_to [:user][:path].json
88
+ # #
89
+ # SsoClyent.sso_provider = {
90
+ # :url => 'http://localhost:3000',
91
+ # :authorize_path => '/auth/sso/authorize',
92
+ # :token_path => '/auth/sso/access_token',
93
+ # :user => { :path => "/auth/sso/user"
94
+ # :uid => "id",
95
+ # :info => %w(email),
96
+ # :extras => %w() } }
97
+ #
98
+ # add a config/intializers/omniauth.rb file with the following:
99
+ #
100
+ # # Change this omniauth configuration to point to your registered provider
101
+ # # Since this is a registered application, add the app id and secret here
102
+ # APP_ID = 'YE0NYveQGoFsNLX220Dy5g'
103
+ # APP_SECRET = 'aqpGBedDnHFyp5MmgT8KErr9D015ScmaY8r3vHg5C0'
104
+ #
105
+ # Rails.application.config.middleware.use OmniAuth::Builder do
106
+ # provider :sso_server, APP_ID, APP_SECRET
107
+ # end
108
+ #
109
+ # add the following line to your controllers
110
+ #
111
+ # before_filter :login_required
data/Rakefile ADDED
@@ -0,0 +1,40 @@
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 = 'SsoClyent'
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
+
27
+
28
+ Bundler::GemHelper.install_tasks
29
+
30
+ require 'rake/testtask'
31
+
32
+ Rake::TestTask.new(:test) do |t|
33
+ t.libs << 'lib'
34
+ t.libs << 'test'
35
+ t.pattern = 'test/**/*_test.rb'
36
+ t.verbose = false
37
+ end
38
+
39
+
40
+ task :default => :test
@@ -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,13 @@
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_tree .
13
+ */
@@ -0,0 +1,5 @@
1
+ module SsoClyent
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery
4
+ end
5
+ end
@@ -0,0 +1,41 @@
1
+ class SsoClyent::UserSessionsController < SsoClyent::ApplicationController
2
+ before_filter :login_required, :only => [ :destroy ]
3
+
4
+ respond_to :html
5
+
6
+ # omniauth callback method
7
+ def create
8
+ omniauth = env['omniauth.auth']
9
+ logger.debug "+++ #{omniauth}"
10
+
11
+ user = user_klass.send("find_by_#{userid}", omniauth['uid'])
12
+ if not user
13
+ # New user registration
14
+ user = user_klass.new(:"#{userid}" => omniauth['uid'])
15
+ end
16
+ user.save
17
+
18
+ # Currently storing all the info
19
+ session[:user_id] = omniauth
20
+
21
+ flash[:notice] = "Successfully logged in"
22
+ redirect_to SsoClyent.after_sign_in_path
23
+ end
24
+
25
+ # Omniauth failure callback
26
+ def failure
27
+ flash[:notice] = params[:message]
28
+
29
+ end
30
+
31
+ # logout - Clear our rack session BUT essentially redirect to the provider
32
+ # to clean up the Devise session from there too !
33
+ def destroy
34
+ session[:user_id] = nil
35
+
36
+ flash[:notice] = 'You have successfully signed out!'
37
+ redirect_to "#{OmniAuth::Strategies::Sso._provider[:url]}/logout?callback_url=#{root_url}"
38
+ end
39
+
40
+ private
41
+ end
@@ -0,0 +1,4 @@
1
+ module SsoClyent
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>SsoClyent</title>
5
+ <%= stylesheet_link_tag "sso_clyent/application", :media => "all" %>
6
+ <%= javascript_include_tag "sso_clyent/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,10 @@
1
+ SsoClyent::Engine.routes.draw do
2
+ root :to => redirect('/')
3
+
4
+ # omniauth
5
+ match "auth/:provider/callback", :controller => "UserSessions", :action => "create"
6
+ match "auth/failure", :controller => "UserSessions", :action => "failure"
7
+ # Custom logout
8
+ match "logout", :controller => "UserSessions", :action => "destroy"
9
+
10
+ end
@@ -0,0 +1 @@
1
+ require 'sso_clyent/controllers/current_user_helpers'
@@ -0,0 +1,28 @@
1
+ module CurrentUserHelpers
2
+ def login_required
3
+ if !current_user
4
+ respond_to do |format|
5
+ format.html { redirect_to "#{SsoClyent.path}/auth/sso" }
6
+ format.json { render :json => { 'error' => 'Access Denied' }.to_json }
7
+ end
8
+ end
9
+ end
10
+
11
+ def current_user
12
+ return nil unless session[:user_id]
13
+ users = user_klass
14
+ uid = userid
15
+ if users.respond_to?(:"find_by_#{uid}")
16
+ @current_user ||= users.send(:"find_by_#{uid}", session[:user_id]['uid'])
17
+ end
18
+ end
19
+
20
+ def user_klass
21
+ SsoClyent.user_class
22
+ end
23
+
24
+ def userid
25
+ SsoClyent.unique_id
26
+ end
27
+ end
28
+ ActionController::Base.send :include, CurrentUserHelpers
@@ -0,0 +1,24 @@
1
+ module SsoClyent
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SsoClyent
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec, :view_specs => false
7
+ end
8
+
9
+ config.sso_clyent = ActiveSupport::OrderedOptions.new
10
+
11
+ initializer "sso_client.configure" do |app|
12
+ SsoClyent.configure(app.config.sso_clyent)
13
+
14
+ require 'sso_clyent/omniauth/strategies/sso'
15
+
16
+ app.config.middleware.use OmniAuth::Builder do
17
+ provider :sso, SsoClyent.provyder[:app_id], SsoClyent.provyder[:app_secret],
18
+ :callback_path => "#{SsoClyent.path}/auth/sso/callback",
19
+ :path_prefix => "#{SsoClyent.path}/auth"
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Sso < OmniAuth::Strategies::OAuth2
6
+
7
+ def raw_info
8
+ @raw_info ||= access_token.get("#{_provider[:user_url]}.json?oauth_token=#{access_token.token}").parsed
9
+ end
10
+
11
+ def self._provider; SsoClyent.provyder;end
12
+ def _provider; SsoClyent.provyder;end
13
+
14
+ option :client_options, {
15
+ :site => _provider[:url],
16
+ :authorize_url => _provider[:authorize_url],
17
+ :token_url => _provider[:access_token_url]
18
+ }
19
+ option :provider_ignores_state, true
20
+
21
+ uid { raw_info[_provider[:user][:uid]] }
22
+
23
+ info do
24
+ _provider[:user][:info].inject({}) do |h,inf|
25
+ h.merge({inf.to_sym => raw_info.send(:[], inf)})
26
+ end
27
+ end
28
+
29
+ extra do
30
+ _provider[:user][:extras].inject({}) do |h,inf|
31
+ h.merge({inf.to_sym => raw_info['extra'].try(:[], inf)})
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module SsoClyent
2
+ VERSION = "0.0.1"
3
+ end
data/lib/sso_clyent.rb ADDED
@@ -0,0 +1,43 @@
1
+ require "sso_clyent/engine"
2
+
3
+ module SsoClyent
4
+
5
+ mattr_accessor :user_class, :unique_id
6
+ mattr_accessor :after_sign_in_path
7
+ mattr_accessor :path
8
+ mattr_accessor :provyder
9
+
10
+ def self.configure(config)
11
+ @@user_class = config[:user_class]
12
+ @@unique_id = config[:unique_id]
13
+ @@after_sign_in_path = config[:after_sign_in_path] || "/"
14
+ @@path = config[:path] || "/sso"
15
+ @@provyder = complete_provyder(config[:provyder])
16
+ end
17
+
18
+ def self.user_class
19
+ @@user_class.constantize
20
+ end
21
+
22
+ private
23
+
24
+ def self.complete_provyder(_provider=nil)
25
+ options = _provider || {}
26
+ base = options.reverse_merge({
27
+ :url => "http://localhost:3000#{options[:path_prefix]}",
28
+ :authorize_path => '/oauth/authorize',
29
+ :token_path => '/oauth/token',
30
+ :user => { :path => "/user",
31
+ :uid => "id",
32
+ :info => %w(email),
33
+ :extras => %w() } })
34
+ base.reverse_merge({
35
+ :authorize_url => "#{base[:url]}#{base[:authorize_path]}",
36
+ :access_token_url => "#{base[:url]}#{base[:token_path]}",
37
+ :user_url => "#{base[:url]}#{base[:user][:path]}"
38
+ })
39
+ end
40
+
41
+ end
42
+
43
+ require 'sso_clyent/base'
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :sso_clyent do
3
+ # # Task goes here
4
+ # end