gds-sso 0.4.3 → 0.5.0

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/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in gds-sso.gemspec
4
- gemspec
4
+ gemspec
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 tou will need an oauth client ID and secret for sign-on-o-tron or a compatible system.
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
- require 'rake/testtask'
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/test*.rb']
9
+ t.test_files = FileList['test/**/*_test.rb']
9
10
  t.verbose = true
10
11
  end
11
12
 
12
- task :default => :test
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 Plek.current.find('signonotron') + "/users/sign_out"
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)['user']
44
+ @user_hash ||= MultiJson.decode(fetch_user_data)
45
45
  end
46
46
 
47
47
  def build_auth_hash
@@ -1,5 +1,5 @@
1
1
  module GDS
2
2
  module SSO
3
- VERSION = "0.4.3"
3
+ VERSION = "0.5.0"
4
4
  end
5
5
  end
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
+ test:
2
+ adapter: mysql2
3
+ encoding: utf8
4
+ reconnect: false
5
+ pool: 5
6
+ username: signonotron2
7
+ password: signonotron2
8
+ database: signonotron2_integration_test
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ include GDS::SSO::ControllerMethods
3
+ end
@@ -0,0 +1,12 @@
1
+ class ExampleController < ApplicationController
2
+
3
+ before_filter :authenticate_user!, :only => [:restricted]
4
+
5
+ def index
6
+ render :text => "jabberwocky"
7
+ end
8
+
9
+ def restricted
10
+ render :text => "restricted kablooie"
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ class User
2
+ include GDS::SSO::User
3
+
4
+ def self.find_by_uid(something)
5
+ stub_user
6
+ end
7
+
8
+ def self.first
9
+ # stub_user
10
+ false
11
+ end
12
+
13
+ def self.stub_user
14
+ OpenStruct.new({ :uid => '1', :name => "User" })
15
+ end
16
+
17
+
18
+ end
@@ -0,0 +1,3 @@
1
+ test:
2
+ adapter: sqlite3
3
+ database: db/combustion_test.sqlite
@@ -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
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ root :to => 'example#index'
3
+ match "/restricted" => 'example#restricted'
4
+ end
@@ -0,0 +1,3 @@
1
+ ActiveRecord::Schema.define do
2
+ #
3
+ end