sso_client 0.0.1.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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2011 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
+ = SsoClient
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
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 = 'SsoClient'
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
@@ -0,0 +1,7 @@
1
+ /*
2
+ * This is a manifest file that'll automatically include all the stylesheets available in this directory
3
+ * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
4
+ * the top of the compiled file, but it's generally better to create a new file per style scope.
5
+ *= require_self
6
+ *= require_tree .
7
+ */
@@ -0,0 +1,25 @@
1
+ module SsoClient
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery
4
+ helper_method :current_user
5
+
6
+ protected
7
+
8
+ def login_required
9
+ if !current_user
10
+ respond_to do |format|
11
+ format.html {
12
+ redirect_to "#{sso_client.root_path}identity"
13
+ }
14
+ format.json {
15
+ render :json => { 'error' => 'Access Denied' }.to_json
16
+ }
17
+ end
18
+ end
19
+ end
20
+
21
+ def current_user
22
+ session[:user]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,8 @@
1
+ module SsoClient
2
+ class HomeController < ApplicationController
3
+ before_filter :login_required
4
+
5
+ def show
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,30 @@
1
+ module SsoClient
2
+ class UserSessionsController < ApplicationController
3
+ before_filter :login_required, :only => :destroy
4
+
5
+ respond_to :html
6
+
7
+ # Omniauth callback method
8
+ def create
9
+ session[:user] = User.from_omniauth(request.env['omniauth.auth'])
10
+
11
+ flash[:notice] = "Successfully logged in"
12
+ redirect_to main_app.root_path
13
+ end
14
+
15
+ # Omniauth failure callback
16
+ def failure
17
+ flash[:notice] = params[:message]
18
+ redirect_to main_app.root_path
19
+ end
20
+
21
+ # logout - Clear our rack session BUT essentially redirect to the provider
22
+ # to clean up the Devise session from there too !
23
+ def destroy
24
+ session[:user] = nil
25
+
26
+ flash[:notice] = 'You have successfully signed out!'
27
+ redirect_to "#{Settings['sso_provider.host']}/users/sign_out"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ module SsoClient
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,32 @@
1
+ module SsoClient
2
+ class SsoClient::User
3
+ ATTRIBUTES = [:uid, :name, :nickname, :email, :first_name, :last_name]
4
+ attr_accessor *ATTRIBUTES
5
+
6
+ def initialize(attributes = {})
7
+ self.attributes = attributes
8
+ end
9
+
10
+ def self.from_omniauth(omniauth)
11
+ User.new(omniauth['info']).tap do | user |
12
+ user.attributes = omniauth['extra']
13
+ user.uid = omniauth['uid']
14
+ end
15
+ end
16
+
17
+ def attributes
18
+ ATTRIBUTES.inject(ActiveSupport::HashWithIndifferentAccess.new) do |result, key|
19
+ result[key] = read_attribute_for_validation(key)
20
+ result
21
+ end
22
+ end
23
+
24
+ def attributes=(attrs)
25
+ attrs.each_pair {|k, v| send("#{k}=", v) if ATTRIBUTES.include? k.to_sym}
26
+ end
27
+
28
+ def read_attribute_for_validation(key)
29
+ send(key)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>SsoClient</title>
5
+ <%= stylesheet_link_tag "sso_client/application" %>
6
+ <%= javascript_include_tag "sso_client/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,10 @@
1
+ <% if flash[:notice] %>
2
+ <p><%=flash[:notice] %> </p>
3
+ <% flash[:notice] = nil %>
4
+ <% end %>
5
+ <% if not current_user %>
6
+ <%= link_to 'login', login_path %>
7
+ <% else %>
8
+ <h1>Hello <%= current_user.name %>!</h1>
9
+ <%= link_to 'logout', logout_path %>
10
+ <% end %>
data/config/routes.rb ADDED
@@ -0,0 +1,14 @@
1
+ SsoClient::Engine.routes.draw do
2
+ root :to => 'home#show'
3
+
4
+ # omniauth
5
+ get "/:provider/callback", :to => 'user_sessions#create'
6
+ get "/failure", :to => 'user_sessions#failure'
7
+
8
+ # logout
9
+ get "/logout", :to => 'user_sessions#destroy', :as => :logout
10
+ end
11
+
12
+ Rails.application.routes.draw do
13
+ mount SsoClient::Engine => "/sso"
14
+ end
@@ -0,0 +1,17 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Identity < OmniAuth::Strategies::OAuth2
6
+ option :client_options, { :site => Settings['sso_provider.host'] }
7
+
8
+ uid { raw_info['uid'] }
9
+ info { raw_info['info'] }
10
+ extra { {:raw_info => raw_info} }
11
+
12
+ def raw_info
13
+ @raw_info ||= access_token.get("/oauth/user.json?oauth_token=#{access_token.token}").parsed
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module SsoClient
2
+ class Engine < Rails::Engine
3
+ isolate_namespace SsoClient
4
+
5
+ engine_root = File.expand_path("../../../", __FILE__)
6
+
7
+ config.after_initialize do
8
+ raise 'Please specify sso_provider.host in settings.yml' unless defined?(Settings) && Settings[:sso_provider]
9
+ end
10
+
11
+ require 'omniauth'
12
+ middleware.use OmniAuth::Builder do
13
+ require "#{engine_root}/lib/omniauth-identity/omniauth/strategies/identity"
14
+ configure do | config |
15
+ config.path_prefix = ''
16
+ end
17
+ provider :identity, Settings['sso_provider.app_id'], Settings['sso_provider.app_secret']
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module SsoClient
2
+ VERSION = "0.0.1.1"
3
+ end
data/lib/sso_client.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "sso_client/engine"
2
+
3
+ module SsoClient
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :sso_client do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sso_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dmitry Lihachev
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &19474340 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 3.1.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *19474340
25
+ - !ruby/object:Gem::Dependency
26
+ name: configliere
27
+ requirement: &19473360 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *19473360
36
+ - !ruby/object:Gem::Dependency
37
+ name: omniauth
38
+ requirement: &19470820 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.1
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *19470820
47
+ - !ruby/object:Gem::Dependency
48
+ name: omniauth-oauth2
49
+ requirement: &19469840 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *19469840
58
+ - !ruby/object:Gem::Dependency
59
+ name: fabrication
60
+ requirement: &19468820 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *19468820
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: &19483700 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *19483700
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard-spork
82
+ requirement: &19482500 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *19482500
91
+ - !ruby/object:Gem::Dependency
92
+ name: libnotify
93
+ requirement: &19481180 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *19481180
102
+ - !ruby/object:Gem::Dependency
103
+ name: rb-inotify
104
+ requirement: &19480360 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *19480360
113
+ - !ruby/object:Gem::Dependency
114
+ name: rspec-rails
115
+ requirement: &19479500 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ~>
119
+ - !ruby/object:Gem::Version
120
+ version: 2.6.0
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *19479500
124
+ - !ruby/object:Gem::Dependency
125
+ name: shoulda-matchers
126
+ requirement: &19478880 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *19478880
135
+ - !ruby/object:Gem::Dependency
136
+ name: spork
137
+ requirement: &19478040 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ~>
141
+ - !ruby/object:Gem::Version
142
+ version: 0.9.0.rc9
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: *19478040
146
+ - !ruby/object:Gem::Dependency
147
+ name: sqlite3
148
+ requirement: &19477260 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: *19477260
157
+ description: Client gem for connecting to SSO server (http://github.com/openteam/sso_server)
158
+ email:
159
+ - lda@openteam.ru
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - app/assets/stylesheets/sso_client/application.css
165
+ - app/helpers/sso_client/application_helper.rb
166
+ - app/models/sso_client/user.rb
167
+ - app/controllers/sso_client/home_controller.rb
168
+ - app/controllers/sso_client/application_controller.rb
169
+ - app/controllers/sso_client/user_sessions_controller.rb
170
+ - app/views/sso_client/home/show.html.erb
171
+ - app/views/layouts/sso_client/application.html.erb
172
+ - config/routes.rb
173
+ - lib/sso_client/engine.rb
174
+ - lib/sso_client/version.rb
175
+ - lib/sso_client.rb
176
+ - lib/tasks/sso_client_tasks.rake
177
+ - lib/omniauth-identity/omniauth/strategies/identity.rb
178
+ - MIT-LICENSE
179
+ - Rakefile
180
+ - README.rdoc
181
+ homepage: http://github.com/openteam/sso_client
182
+ licenses: []
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ! '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ segments:
194
+ - 0
195
+ hash: -1055641977507148518
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ segments:
203
+ - 0
204
+ hash: -1055641977507148518
205
+ requirements: []
206
+ rubyforge_project:
207
+ rubygems_version: 1.8.11
208
+ signing_key:
209
+ specification_version: 3
210
+ summary: Client gem for connecting to SSO server
211
+ test_files: []