grnds-sso 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ddb4c8c687ce1b47dc636537155a39a3e15162e1
4
+ data.tar.gz: daf7628fb44d0f7f1420a15b113eec8a4c7899b3
5
+ SHA512:
6
+ metadata.gz: 4c850adfe04cf8a13f63fc6014ba00e818b5ad6c729c8d27ed2af256a9536e85a577a7ab73c0c2cf569df0a50a024533a74402cdf4faff19018ab480ca1c0e4a
7
+ data.tar.gz: 4c89b94fc9a3a39a6f24d7814348447d3f7ad545f3595375052db89875501a0e2088d906647193f0bd704e65505ea579b45f352f82e3e230ca6664ba82f20e86
data/ChangeLog ADDED
@@ -0,0 +1,11 @@
1
+ 0.0.3
2
+ =====
3
+ - added VpnConstraint class for use in routes.rb to protect console URLs.
4
+
5
+ 0.0.2
6
+ =====
7
+ - changed sso_development vars to only set test data if no data previously existed.
8
+
9
+ 0.0.1
10
+ =====
11
+ - initial push
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ grnds-sso
2
+ =========
3
+
4
+
5
+ # Adding SSO to your application.
6
+
7
+ - copy the sample config(below) to your app at `config/initializers/grnds_sso.rb`
8
+
9
+ ```
10
+ Rails.application.config.action_dispatch.cookies_serializer = :marshal
11
+
12
+ Grnds::Sso.configure do |config|
13
+ case Rails.env
14
+ when 'development', 'test'
15
+ config.base_site = 'http://localhost:3000'
16
+ when 'uat'
17
+ config.base_site = 'https://www.uat.grandroundshealth.com'
18
+ when 'production'
19
+ config.base_site = 'https://www.grandroundshealth.com'
20
+ end
21
+ config.sign_in_post_fix = '/app/users/sign_in'
22
+ config.sign_out_post_fix = '/app/users/sign_out'
23
+ end
24
+ ```
25
+
26
+ - Configure your session store to use the GrandRounds session cookie. Add `config/initializers/session_store.rb`:
27
+ ```
28
+ if Rails.env == 'test' or Rails.env == 'development'
29
+ Frick::Application.config.session_store :cookie_store, key: "_GrandRounds_session_#{Rails.env}", :domain => :all
30
+ elsif Rails.env == 'production'
31
+ Frick::Application.config.session_store :cookie_store, key: "_GrandRounds_session", :domain => ".#{ConsultingMD::Application.config.website_domain}"
32
+ else
33
+ Frick::Application.config.session_store :cookie_store, key: "_GrandRounds_session_#{Rails.env}", :domain => ".#{ConsultingMD::Application.config.website_domain}"
34
+ end
35
+ ```
36
+
37
+ - In your application.rb, set up the cookie secret (and pay attention to your deployment environment variables):
38
+ ```
39
+ config.website_domain = 'grandroundshealth.com'
40
+ config.secret_token = ENV['RAILS_COOKIE_SECRET'] || copy_it_yourself_from_tim_or_tp
41
+ ```
42
+
43
+ - Make sure you don't also have a secret_token initializer.
data/grnds-sso.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'grnds/sso/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'grnds-sso'
7
+ s.version = Grnds::Sso::VERSION
8
+ s.date = '2014-12-29'
9
+ s.summary = "SSO for Grand Rounds"
10
+ s.description = "A simple way to expose SSO on Grand Rounds projects"
11
+ s.authors = ["Justin Ahn", "Rick Cobb"]
12
+ s.email = 'justin@grandroundshealth.com'
13
+ s.files = `git ls-files`.split($/)
14
+ s.license = 'MIT'
15
+ end
data/lib/grnds/sso.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'grnds/sso/version'
2
+ require 'grnds/sso/configuration'
3
+ require 'grnds/sso/view_helpers' if defined?(Rails)
4
+ require 'grnds/sso/authentication' if defined?(Rails)
5
+ require 'grnds/sso/vpn_constraint' if defined?(Rails)
@@ -0,0 +1,38 @@
1
+ module Grnds
2
+ module Sso
3
+ module Authentication
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def grnds_sso_access(options = {})
8
+ include Grnds::Sso::Authentication
9
+ include Grnds::Sso::ViewHelpers
10
+ before_filter :authenticate_user, options
11
+ end
12
+ end
13
+
14
+ protected
15
+
16
+ def set_development_credentials
17
+ session['customer_name'] ||= 'Grand Rounds'
18
+ session['uid'] ||= '57'
19
+ session['first_name'] ||= 'Kenneth'
20
+ session['last_name'] ||= 'Berland'
21
+ end
22
+
23
+ def authenticate_user
24
+ set_development_credentials if %w[test].include?(Rails.env)
25
+ redirect_to Grnds::Sso.sign_in_url unless authenticated?
26
+ end
27
+
28
+ def authenticated?
29
+ session[:init] = true unless session.loaded?
30
+ current_user.present?
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ ActionController::Base.class_eval do
37
+ extend Grnds::Sso::Authentication::ClassMethods
38
+ end
@@ -0,0 +1,31 @@
1
+ module Grnds
2
+ module Sso
3
+ def self.configure
4
+ yield configuration
5
+ end
6
+
7
+ def self.configuration
8
+ @configuration ||= Grnds::Sso::Configuration.new
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :base_site, :sign_in_post_fix, :sign_out_post_fix
13
+
14
+ def vpn
15
+ Grnds::Sso::VpnConstraint.instance
16
+ end
17
+ end
18
+
19
+ class << self
20
+ def sign_in_url
21
+ configuration = Grnds::Sso.configuration
22
+ configuration.base_site + configuration.sign_in_post_fix
23
+ end
24
+
25
+ def sign_out_url
26
+ configuration = Grnds::Sso.configuration
27
+ configuration.base_site + configuration.sign_out_post_fix
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module Grnds
2
+ module Sso
3
+ VERSION = '0.0.3'
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ module Grnds
2
+ module Sso
3
+ module ViewHelpers
4
+ extend ActiveSupport::Concern
5
+ included do
6
+ helper_method :current_user
7
+ helper_method :current_customer
8
+ helper_method :current_first_name
9
+ helper_method :current_last_name
10
+ end
11
+ def current_user
12
+ session['uid']
13
+ end
14
+
15
+ def current_customer
16
+ session['customer_name']
17
+ end
18
+
19
+ def current_first_name
20
+ session['first_name']
21
+ end
22
+
23
+ def current_last_name
24
+ session['last_name']
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,53 @@
1
+ module Grnds::Sso
2
+ class VpnConstraint
3
+ include Singleton
4
+
5
+ LOCALHOST = '127.0.0.1'.freeze
6
+ VPN = %r{^10\.}.freeze
7
+
8
+ class << self
9
+ delegate :configure, :matches?, to: :instance
10
+ end
11
+
12
+ attr_accessor :require_login, :pattern
13
+ alias :require_login? :require_login
14
+
15
+ def initialize
16
+ self.require_login = (Rails.env != 'development')
17
+
18
+ case Rails.env
19
+ when 'development', 'test' then
20
+ self.pattern = LOCALHOST
21
+ else
22
+ self.pattern = VPN
23
+ end
24
+ end
25
+
26
+ def configure
27
+ yield self
28
+ end
29
+
30
+ def matches?(request)
31
+ return false unless !require_login? || authenticated?(request)
32
+
33
+ return on_the_vpn?(request)
34
+ end
35
+
36
+ def authenticated?(request)
37
+ session = request.session
38
+ session[:init] = true unless session.loaded?
39
+
40
+ return session['uid'].present?
41
+ end
42
+
43
+ def on_the_vpn?(request)
44
+ case pattern
45
+ when String
46
+ return pattern == request.remote_ip
47
+ else
48
+ return pattern.match(request.remote_ip)
49
+ end
50
+ raise "VPN not defined"
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grnds-sso
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Justin Ahn
8
+ - Rick Cobb
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-12-29 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A simple way to expose SSO on Grand Rounds projects
15
+ email: justin@grandroundshealth.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ChangeLog
21
+ - README.md
22
+ - grnds-sso.gemspec
23
+ - lib/grnds/sso.rb
24
+ - lib/grnds/sso/authentication.rb
25
+ - lib/grnds/sso/configuration.rb
26
+ - lib/grnds/sso/version.rb
27
+ - lib/grnds/sso/view_helpers.rb
28
+ - lib/grnds/sso/vpn_constraint.rb
29
+ homepage:
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.4.3
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: SSO for Grand Rounds
53
+ test_files: []