recsolu_login_client 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1 @@
1
+ 1.9.3-p327
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.3-p286@recsolu_login_client --create
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'omniauth', '1.1.3'
7
+ gem 'omniauth-oauth2', '1.1.1'
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "rdoc", "~> 3.12"
13
+ gem "bundler"
14
+ gem "jeweler", "~> 1.8.4"
15
+ end
@@ -0,0 +1,44 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ faraday (0.8.5)
5
+ multipart-post (~> 1.1)
6
+ git (1.2.5)
7
+ hashie (1.2.0)
8
+ httpauth (0.2.0)
9
+ jeweler (1.8.4)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rdoc
14
+ json (1.7.7)
15
+ jwt (0.1.5)
16
+ multi_json (>= 1.0)
17
+ multi_json (1.6.1)
18
+ multipart-post (1.1.5)
19
+ oauth2 (0.8.1)
20
+ faraday (~> 0.8)
21
+ httpauth (~> 0.1)
22
+ jwt (~> 0.1.4)
23
+ multi_json (~> 1.0)
24
+ rack (~> 1.2)
25
+ omniauth (1.1.3)
26
+ hashie (~> 1.2)
27
+ rack
28
+ omniauth-oauth2 (1.1.1)
29
+ oauth2 (~> 0.8.0)
30
+ omniauth (~> 1.0)
31
+ rack (1.5.2)
32
+ rake (10.0.3)
33
+ rdoc (3.12.1)
34
+ json (~> 1.4)
35
+
36
+ PLATFORMS
37
+ ruby
38
+
39
+ DEPENDENCIES
40
+ bundler
41
+ jeweler (~> 1.8.4)
42
+ omniauth (= 1.1.3)
43
+ omniauth-oauth2 (= 1.1.1)
44
+ rdoc (~> 3.12)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Andy Maleh
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.
@@ -0,0 +1,19 @@
1
+ = recsolu_login_client
2
+
3
+ A gem that makes it easy for Recsolu apps to authenticate with the login app using single sign on
4
+
5
+ == Contributing to recsolu_login_client
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) 2013 Andy Maleh. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "recsolu_login_client"
18
+ gem.homepage = "https://recsolu.beanstalkapp.com/recsolu_login_client"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Login app client for single sign on}
21
+ gem.description = %Q{A gem that makes it easy for Recsolu apps to authenticate with the login app using single sign on}
22
+ gem.email = "andy.maleh.ic@recsolu.com"
23
+ gem.authors = ["Andy Maleh", "Lance Ennen"]
24
+ # dependencies defined in Gemfile
25
+ gem.add_dependency 'omniauth', '1.1.3'
26
+ gem.add_dependency 'omniauth-oauth2', '1.1.1'
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ #task :default => :test
31
+
32
+ require 'rdoc/task'
33
+ Rake::RDocTask.new do |rdoc|
34
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
35
+
36
+ rdoc.rdoc_dir = 'rdoc'
37
+ rdoc.title = "recsolu_login_client #{version}"
38
+ rdoc.rdoc_files.include('README*')
39
+ rdoc.rdoc_files.include('lib/**/*.rb')
40
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,53 @@
1
+ class UserSessionsController < 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.find_by_uid(omniauth['uid'])
12
+ if not user
13
+ # New user registration
14
+ user = User.new(:uid => omniauth['uid'])
15
+ end
16
+ user.first_name = omniauth['extra']['first_name']
17
+ user.last_name = omniauth['extra']['last_name']
18
+ user.email = omniauth['info']['email']
19
+ user.save
20
+
21
+ #p omniauth
22
+
23
+ # Currently storing all the info
24
+ session[:user_id] = omniauth
25
+
26
+ flash[:notice] = "Successfully logged in"
27
+ redirect_to root_path
28
+ end
29
+
30
+ # Omniauth failure callback
31
+ def failure
32
+ flash[:notice] = params[:message]
33
+
34
+ end
35
+
36
+ # logout - Clear our rack session BUT essentially redirect to the provider
37
+ # to clean up the Devise session from there too !
38
+ def destroy
39
+ session[:user_id] = nil
40
+
41
+ flash[:notice] = 'You have successfully signed out!'
42
+ redirect_to "#{RecsoluLoginClient::Configuration.app_provider_url}/users/sign_out?redirect_to=#{params[:redirect_to]}"
43
+ end
44
+
45
+ # to facilitate testing in Cucumber steps
46
+ if Rails.env.to_s == 'test'
47
+ def set_session_user
48
+ session[:user_id] = {'uid' => params[:user_uid]}
49
+ render :nothing => true
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,9 @@
1
+ # Change this omniauth configuration to point to your registered provider
2
+ # Since this is a registered application, add the app id and secret here
3
+
4
+ require 'omniauth'
5
+ require 'omniauth-oauth2'
6
+
7
+ Rails.application.config.middleware.use OmniAuth::Builder do
8
+ provider :recsolu_id, RecsoluLoginClient::Configuration.app_id, RecsoluLoginClient::Configuration.app_secret
9
+ end
@@ -0,0 +1,14 @@
1
+ RecsoluLoginClient::Engine.routes.draw do
2
+ #SSO PROVIDER
3
+ # omniauth
4
+ match '/auth/:provider/callback', :to => 'user_sessions#create'
5
+ match '/auth/failure', :to => 'user_sessions#failure'
6
+ match '/logout', :to => 'user_sessions#destroy', :as => :logout
7
+ match '/login' => redirect('/auth/recsoluid'), :as => :login
8
+
9
+ if Rails.env.to_s == 'test'
10
+ match '/set_session_user', :to => 'user_sessions#set_session_user', :as => :set_session_user
11
+ end
12
+
13
+ #SSO PROVIDER
14
+ end
@@ -0,0 +1,5 @@
1
+ class AddUidToUsers < ActiveRecord::Migration
2
+ def change
3
+ add_column :users, :uid, :integer
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'recsolu_login_client/configuration'
2
+ require 'recsolu_login_client/engine'
3
+
4
+ module RecsoluLoginClient
5
+ def self.configure(&config)
6
+ config.call(RecsoluLoginClient::Configuration)
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module RecsoluLoginClient
2
+ class Configuration
3
+ class << self
4
+ attr_accessor :app_id, :app_secret, :app_provider_url, :app_user_model
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module RecsoluLoginClient
2
+ class Engine < Rails::Engine
3
+ engine_name "recsolu_login_client"
4
+
5
+ config.autoload_paths << File.expand_path("..", __FILE__)
6
+ config.after_initialize do
7
+ ApplicationHelper.class_eval do
8
+ include OmniauthableHelper
9
+ end
10
+ ApplicationController.class_eval do
11
+ include OmniauthableController
12
+ end
13
+ RecsoluLoginClient::Configuration.app_user_model.to_s.classify.constantize.class_eval do
14
+ include OmniauthableUserModel
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,33 @@
1
+ require 'omniauth-oauth2'
2
+ module OmniAuth
3
+ module Strategies
4
+ class RecsoluId < OmniAuth::Strategies::OAuth2
5
+
6
+ option :client_options, {
7
+ :site => RecsoluLoginClient::Configuration.app_provider_url,
8
+ :authorize_url => "#{RecsoluLoginClient::Configuration.app_provider_url}/auth/recsolu_id/authorize",
9
+ :access_token_url => "#{RecsoluLoginClient::Configuration.app_provider_url}/auth/recsolu_id/access_token"
10
+ }
11
+
12
+ uid { raw_info['id'] }
13
+
14
+ info do
15
+ {
16
+ :email => raw_info['info']['email']
17
+ }
18
+ end
19
+
20
+ extra do
21
+ {
22
+ :first_name => raw_info['extra']['first_name'],
23
+ :last_name => raw_info['extra']['last_name']
24
+ }
25
+ end
26
+
27
+ def raw_info
28
+ @raw_info ||= access_token.get("/auth/recsolu_id/user.json?oauth_token=#{access_token.token}").parsed
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -0,0 +1,19 @@
1
+ require File.expand_path('omniauthable_helper', File.dirname(__FILE__))
2
+
3
+ module OmniauthableController
4
+ include OmniauthableHelper
5
+
6
+ def login_required
7
+ if !current_user
8
+ respond_to do |format|
9
+ format.html {
10
+ redirect_to '/auth/recsoluid'
11
+ }
12
+ format.json {
13
+ render :json => { 'error' => 'Access Denied' }.to_json
14
+ }
15
+ end
16
+ end
17
+ end
18
+ alias_method :authenticate_user!, :login_required
19
+ end
@@ -0,0 +1,10 @@
1
+ module OmniauthableHelper
2
+ def current_user
3
+ return nil unless session[:user_id]
4
+ @current_user ||= User.find_by_uid(session[:user_id]['uid'])
5
+ end
6
+
7
+ def user_signed_in?
8
+ current_user.present?
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module OmniauthableUserModel
2
+ def self.included(including_class)
3
+ including_class.class_eval do
4
+ attr_accessible :uid
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,78 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "recsolu_login_client"
8
+ s.version = "0.1.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andy Maleh", "Lance Ennen"]
12
+ s.date = "2013-04-10"
13
+ s.description = "A gem that makes it easy for Recsolu apps to authenticate with the login app using single sign on"
14
+ s.email = "andy.maleh.ic@recsolu.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rbenv-version",
22
+ ".rvmrc",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "app/controllers/user_sessions_controller.rb",
30
+ "config/initializers/omniauth.rb",
31
+ "config/routes.rb",
32
+ "db/migrations/20130222225658_add_uid_to_users.rb",
33
+ "lib/recsolu_login_client.rb",
34
+ "lib/recsolu_login_client/configuration.rb",
35
+ "lib/recsolu_login_client/engine.rb",
36
+ "lib/recsolu_login_client/omni_auth/strategies/recsolu_id.rb",
37
+ "lib/recsolu_login_client/omniauthable_controller.rb",
38
+ "lib/recsolu_login_client/omniauthable_helper.rb",
39
+ "lib/recsolu_login_client/omniauthable_user_model.rb",
40
+ "recsolu_login_client.gemspec"
41
+ ]
42
+ s.homepage = "https://recsolu.beanstalkapp.com/recsolu_login_client"
43
+ s.licenses = ["MIT"]
44
+ s.require_paths = ["lib"]
45
+ s.rubygems_version = "1.8.24"
46
+ s.summary = "Login app client for single sign on"
47
+
48
+ if s.respond_to? :specification_version then
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<omniauth>, ["= 1.1.3"])
53
+ s.add_runtime_dependency(%q<omniauth-oauth2>, ["= 1.1.1"])
54
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_development_dependency(%q<bundler>, [">= 0"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
57
+ s.add_runtime_dependency(%q<omniauth>, ["= 1.1.3"])
58
+ s.add_runtime_dependency(%q<omniauth-oauth2>, ["= 1.1.1"])
59
+ else
60
+ s.add_dependency(%q<omniauth>, ["= 1.1.3"])
61
+ s.add_dependency(%q<omniauth-oauth2>, ["= 1.1.1"])
62
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
+ s.add_dependency(%q<bundler>, [">= 0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
65
+ s.add_dependency(%q<omniauth>, ["= 1.1.3"])
66
+ s.add_dependency(%q<omniauth-oauth2>, ["= 1.1.1"])
67
+ end
68
+ else
69
+ s.add_dependency(%q<omniauth>, ["= 1.1.3"])
70
+ s.add_dependency(%q<omniauth-oauth2>, ["= 1.1.1"])
71
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
72
+ s.add_dependency(%q<bundler>, [">= 0"])
73
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
74
+ s.add_dependency(%q<omniauth>, ["= 1.1.3"])
75
+ s.add_dependency(%q<omniauth-oauth2>, ["= 1.1.1"])
76
+ end
77
+ end
78
+
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: recsolu_login_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andy Maleh
9
+ - Lance Ennen
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-04-10 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: omniauth
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - '='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.1.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - '='
29
+ - !ruby/object:Gem::Version
30
+ version: 1.1.3
31
+ - !ruby/object:Gem::Dependency
32
+ name: omniauth-oauth2
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - '='
37
+ - !ruby/object:Gem::Version
38
+ version: 1.1.1
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 1.1.1
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: '3.12'
63
+ - !ruby/object:Gem::Dependency
64
+ name: bundler
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: jeweler
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: 1.8.4
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: 1.8.4
95
+ - !ruby/object:Gem::Dependency
96
+ name: omniauth
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - '='
101
+ - !ruby/object:Gem::Version
102
+ version: 1.1.3
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 1.1.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: omniauth-oauth2
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - '='
117
+ - !ruby/object:Gem::Version
118
+ version: 1.1.1
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - '='
125
+ - !ruby/object:Gem::Version
126
+ version: 1.1.1
127
+ description: A gem that makes it easy for Recsolu apps to authenticate with the login
128
+ app using single sign on
129
+ email: andy.maleh.ic@recsolu.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files:
133
+ - LICENSE.txt
134
+ - README.rdoc
135
+ files:
136
+ - .document
137
+ - .rbenv-version
138
+ - .rvmrc
139
+ - Gemfile
140
+ - Gemfile.lock
141
+ - LICENSE.txt
142
+ - README.rdoc
143
+ - Rakefile
144
+ - VERSION
145
+ - app/controllers/user_sessions_controller.rb
146
+ - config/initializers/omniauth.rb
147
+ - config/routes.rb
148
+ - db/migrations/20130222225658_add_uid_to_users.rb
149
+ - lib/recsolu_login_client.rb
150
+ - lib/recsolu_login_client/configuration.rb
151
+ - lib/recsolu_login_client/engine.rb
152
+ - lib/recsolu_login_client/omni_auth/strategies/recsolu_id.rb
153
+ - lib/recsolu_login_client/omniauthable_controller.rb
154
+ - lib/recsolu_login_client/omniauthable_helper.rb
155
+ - lib/recsolu_login_client/omniauthable_user_model.rb
156
+ - recsolu_login_client.gemspec
157
+ homepage: https://recsolu.beanstalkapp.com/recsolu_login_client
158
+ licenses:
159
+ - MIT
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ segments:
171
+ - 0
172
+ hash: -1807676362241518614
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ none: false
175
+ requirements:
176
+ - - ! '>='
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 1.8.24
182
+ signing_key:
183
+ specification_version: 3
184
+ summary: Login app client for single sign on
185
+ test_files: []