gds-sso 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/README.md +13 -2
- data/Rakefile +16 -3
- data/app/controllers/authentications_controller.rb +1 -1
- data/lib/gds-sso/omniauth_strategy.rb +2 -2
- data/lib/gds-sso/version.rb +1 -1
- data/lib/gds-sso.rb +2 -1
- data/spec/fixtures/integration/signonotron2.sql +9 -0
- data/spec/fixtures/integration/signonotron2_database.yml +8 -0
- data/spec/internal/app/controllers/application_controller.rb +3 -0
- data/spec/internal/app/controllers/example_controller.rb +12 -0
- data/spec/internal/app/models/user.rb +18 -0
- data/spec/internal/config/database.yml +3 -0
- data/spec/internal/config/initializers/gds-sso.rb +8 -0
- data/spec/internal/config/routes.rb +4 -0
- data/spec/internal/db/schema.rb +3 -0
- data/spec/internal/log/test.log +2518 -0
- data/{test/test_http_strategy.rb → spec/internal/public/favicon.ico} +0 -0
- data/spec/requests/end_to_end_spec.rb +77 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/signonotron2_integration_helpers.rb +35 -0
- data/spec/tasks/signonotron_tasks.rake +41 -0
- data/test/{test_gds_sso_strategy.rb → gds_sso_strategy_test.rb} +0 -0
- data/test/{test_omniauth_strategy.rb → omniauth_strategy_test.rb} +6 -8
- data/test/{test_user.rb → user_test.rb} +0 -0
- metadata +92 -38
- data/lib/gds-sso/routes.rb +0 -20
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -12,7 +12,7 @@ For more details on OmniAuth and oAuth2 integration see https://github.com/intri
|
|
12
12
|
|
13
13
|
## Integration with a Rails 3+ app
|
14
14
|
|
15
|
-
To use gds-sso
|
15
|
+
To use gds-sso you will need an oauth client ID and secret for sign-on-o-tron or a compatible system.
|
16
16
|
These can be provided by one of the team with admin access to sign-on-o-tron.
|
17
17
|
|
18
18
|
Then include the gem in your Gemfile:
|
@@ -38,4 +38,15 @@ Create a `config/initializers/gds-sso.rb` that looks like:
|
|
38
38
|
|
39
39
|
The user model needs to respond to klass.find_by_uid(uid), and must include the GDS::SSO::User module.
|
40
40
|
|
41
|
-
You also need to include `GDS::SSO::ControllerMethods` in your ApplicationController
|
41
|
+
You also need to include `GDS::SSO::ControllerMethods` in your ApplicationController
|
42
|
+
|
43
|
+
## Use in development mode
|
44
|
+
|
45
|
+
In development, you generally want to be able to run an application without needing to run your own SSO server to be running as well. GDS-SSO facilitates this by using a 'mock' mode in development. Mock mode loads an arbitrary user from the local application's user tables:
|
46
|
+
|
47
|
+
GDS::SSO.test_user || GDS::SSO::Config.user_klass.first
|
48
|
+
|
49
|
+
To make it use a real strategy (e.g. if you're testing an app against the signon server), set an environment variable when you run your app:
|
50
|
+
|
51
|
+
GDS_SSO_STRATEGY=real bundle exec rails s
|
52
|
+
|
data/Rakefile
CHANGED
@@ -1,12 +1,25 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
-
|
4
|
+
load File.dirname(__FILE__) + "/spec/tasks/signonotron_tasks.rake"
|
5
5
|
|
6
|
+
require 'rake/testtask'
|
6
7
|
Rake::TestTask.new do |t|
|
7
8
|
t.libs << "test"
|
8
|
-
t.test_files = FileList['test
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
9
10
|
t.verbose = true
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
+
require 'rspec/core/rake_task'
|
14
|
+
desc "Run all specs"
|
15
|
+
RSpec::Core::RakeTask.new(:spec) do |task|
|
16
|
+
task.pattern = 'spec/**/*_spec.rb'
|
17
|
+
end
|
18
|
+
namespace :spec do
|
19
|
+
desc "Run integration specs"
|
20
|
+
RSpec::Core::RakeTask.new(:integration) do |task|
|
21
|
+
task.pattern = 'spec/integration/**/*_spec.rb'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
task :default => [:test, :spec]
|
@@ -9,6 +9,6 @@ class AuthenticationsController < ApplicationController
|
|
9
9
|
cookie_key = Rails.application.config.session_options[:key]
|
10
10
|
cookies.delete(cookie_key)
|
11
11
|
reset_session
|
12
|
-
redirect_to
|
12
|
+
redirect_to GDS::SSO::Config.oauth_root_url + "/users/sign_out"
|
13
13
|
end
|
14
14
|
end
|
@@ -37,11 +37,11 @@ class OmniAuth::Strategies::Gds < OmniAuth::Strategies::OAuth2
|
|
37
37
|
protected
|
38
38
|
|
39
39
|
def fetch_user_data
|
40
|
-
@access_token.get('/user.json')
|
40
|
+
@access_token.get('/user.json').body
|
41
41
|
end
|
42
42
|
|
43
43
|
def user_hash
|
44
|
-
@user_hash ||= MultiJson.decode(fetch_user_data)
|
44
|
+
@user_hash ||= MultiJson.decode(fetch_user_data)
|
45
45
|
end
|
46
46
|
|
47
47
|
def build_auth_hash
|
data/lib/gds-sso/version.rb
CHANGED
data/lib/gds-sso.rb
CHANGED
@@ -3,7 +3,6 @@ require 'rails'
|
|
3
3
|
require 'gds-sso/config'
|
4
4
|
require 'gds-sso/omniauth_strategy'
|
5
5
|
require 'gds-sso/warden_config'
|
6
|
-
require 'gds-sso/routes'
|
7
6
|
|
8
7
|
module GDS
|
9
8
|
module SSO
|
@@ -36,6 +35,8 @@ module GDS
|
|
36
35
|
use_mock_strategies? ? [:mock_gds_sso, :mock_gds_sso_api_access] : [:gds_sso, :gds_sso_api_access]
|
37
36
|
end
|
38
37
|
|
38
|
+
puts "Loading Warden!"
|
39
|
+
|
39
40
|
config.app_middleware.use Warden::Manager do |config|
|
40
41
|
config.default_strategies *self.default_strategies
|
41
42
|
config.failure_app = GDS::SSO::FailureApp
|
@@ -0,0 +1,9 @@
|
|
1
|
+
-- Clean data from database
|
2
|
+
DELETE FROM `oauth_access_grants`;
|
3
|
+
DELETE FROM `oauth_access_tokens`;
|
4
|
+
DELETE FROM `oauth_applications`;
|
5
|
+
DELETE FROM `users`;
|
6
|
+
|
7
|
+
-- Setup fixture data
|
8
|
+
INSERT INTO `oauth_applications` VALUES (1,'GDS_SSO integration test','gds-sso-test','secret','http://www.example-client.com/auth/gds/callback','2012-04-19 13:26:54','2012-04-19 13:26:54');
|
9
|
+
INSERT INTO `users` VALUES (1,'test@example-client.com','$2a$04$MdMkVFwTq5GLJJkHS8GLIe6dK1.C4ozzba5ZS5Ks2b/NenVsMGGRW',NULL,NULL,0,NULL,NULL,NULL,NULL,0,NULL,'2012-04-19 13:26:54','2012-04-19 13:26:54',NULL,'Test User','integration-uid');
|
@@ -0,0 +1,8 @@
|
|
1
|
+
GDS::SSO.config do |config|
|
2
|
+
config.user_model = "User"
|
3
|
+
config.oauth_id = 'gds-sso-test'
|
4
|
+
config.oauth_secret = 'secret'
|
5
|
+
config.oauth_root_url = "http://localhost:4567"
|
6
|
+
config.basic_auth_user = 'test_api_user'
|
7
|
+
config.basic_auth_password = 'api_user_password'
|
8
|
+
end
|