rack-cas-rails 0.0.3 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7d484d2b59603bbedf3a28c4917a463edf86c08
4
- data.tar.gz: 7bbe3d6ae9fdbf53eef3fcb523c1d019d1afe1f1
3
+ metadata.gz: 8836a05c5f0d55683c1f331678732623967cdb6b
4
+ data.tar.gz: 65b97157df8bcff33442d513e0ff3090e7c06373
5
5
  SHA512:
6
- metadata.gz: 26517014d8fc90148db433d49e79084aa83fb2d7697174e1e9b201b5d98eae5d2e04ce784b659eb68a2d3fecf860241aa57e4aca33d2d1fd30c2d6d7f7c7ccbf
7
- data.tar.gz: 2413da86e88601ae8995cb1813b4d429a8c3f1dfa0ae9b0f836d5e95240c9e34b1d48ee7a80d454cd2a1161be6586eb2971e8fce19da26e3847e6cd4dd1e2c24
6
+ metadata.gz: 5ad69911433d9916bbcc81c952883ee5e59471ed421ee040924901c47fa55c83fa2a045e76c44904f49d4b1382f4570cc11dc82dd33b12d8fe87db8c54c49f36
7
+ data.tar.gz: 887aa26f4dea0967e08f0f18b9ff07072480b069beac88f6fff2d3a99ab20d6c6032a4c46749b78255fe5115c485272490eb23002c1381103b5e59583c731ade
data/README.md CHANGED
@@ -65,7 +65,7 @@ he can do nothing. To do so, add the following ```before_action``` callback to
65
65
  ```ruby
66
66
  # app/controllers/application_ronctoller.rb
67
67
 
68
- require "rack_cas_rails"
68
+ require "rack-cas-rails"
69
69
  class ApplicationController < ActionController::Base
70
70
  # Prevent CSRF attacks by raising an exception.
71
71
  # For APIs, you may want to use :null_session instead.
@@ -101,7 +101,7 @@ In this case, only certain portions of your application requires authentication.
101
101
  ```ruby
102
102
  # app/controllers/application_ronctoller.rb
103
103
 
104
- require "rack_cas_rails"
104
+ require "rack-cas-rails"
105
105
  class ApplicationController < ActionController::Base
106
106
  # Prevent CSRF attacks by raising an exception.
107
107
  # For APIs, you may want to use :null_session instead.
@@ -200,7 +200,7 @@ Now, let's add a helper named ```current_user``` (or any other name you like) to
200
200
  ```ruby
201
201
  # app/controllers/application_ronctoller.rb
202
202
 
203
- require "rack_cas_rails"
203
+ require "rack-cas-rails"
204
204
  class ApplicationController < ActionController::Base
205
205
  # Prevent CSRF attacks by raising an exception.
206
206
  # For APIs, you may want to use :null_session instead.
@@ -0,0 +1,3 @@
1
+ require "rack-cas-rails/action_controller_base_additions"
2
+ require "rack-cas-rails/rails_application_additions"
3
+ require "rack-cas-rails/version"
@@ -0,0 +1,64 @@
1
+ module RackCASRails
2
+ module ActionControllerBaseAdditions
3
+
4
+ ##
5
+ # When invoked, will force authenticate. Most likely to be invoked as a before_action.
6
+
7
+ def authenticate!
8
+ return if authenticated?
9
+ if File.exists?("public/401.html")
10
+ render(:file => "public/401.html", :status => :unauthorized)
11
+ else
12
+ render(:plain => "Unauthorized!", :status => :unauthorized)
13
+ end
14
+ end
15
+
16
+ ##
17
+ # Determines whether the current request belongs to a session that is authenticated or not.
18
+ # @return [Bool] True if current request belongs to an authenticated session, false otherwise.
19
+
20
+ def authenticated?
21
+ request.session["cas"] && request.session["cas"]["user"]
22
+ end
23
+
24
+ ##
25
+ # Renders the CAS login URL with re-direct back to some URL.
26
+ # @param service_url [String] Optional url to redirect to after authentication.
27
+ # @return [String] The CAS login URL.
28
+
29
+ def login_url(service_url=request.url)
30
+ url = URI(Rails.application.cas_server_url)
31
+ url.path = "/login"
32
+ url.query = "service=#{service_url || request.url}"
33
+ url.to_s
34
+ end
35
+
36
+ ##
37
+ # Renders the CAS logout URL with re-direct back to some URL (e.g. the root URL). The logout path is "/logout",
38
+ # which is actually undocumented. I had to find out by looking into the source code of the rack-cas gem.
39
+ # @param service_url [String] Optional url to redirect to after authentication.
40
+ # @return [String] The CAS logout URL.
41
+
42
+ def logout_url(service_url=request.url)
43
+ url = URI(request.url)
44
+ url.path = "/logout"
45
+ url.query = "service=#{service_url || request.url}"
46
+ url.to_s
47
+ end
48
+
49
+ def self.included(base)
50
+ # Expose newly added instance methods as helpers
51
+ base.helper_method :authenticate!
52
+ base.helper_method :authenticated?
53
+ base.helper_method :login_url
54
+ base.helper_method :logout_url
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+ # Add instance mthods to the ActionController::Base class
61
+ ActionController::Base.class_eval do
62
+ include RackCASRails::ActionControllerBaseAdditions
63
+ end
64
+
@@ -1,5 +1,5 @@
1
1
  ##
2
- # Augments the Rails application class.
2
+ # Augments the Rails::Application class.
3
3
 
4
4
  class Rails::Application < Rails::Engine
5
5
 
@@ -1,3 +1,3 @@
1
1
  module RackCASRails
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cas-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Brazil
@@ -96,10 +96,10 @@ extra_rdoc_files: []
96
96
  files:
97
97
  - LICENSE
98
98
  - README.md
99
- - lib/rack_cas_rails.rb
100
- - lib/rack_cas_rails/application.rb
101
- - lib/rack_cas_rails/controllers.rb
102
- - lib/rack_cas_rails/version.rb
99
+ - lib/rack-cas-rails.rb
100
+ - lib/rack-cas-rails/action_controller_base_additions.rb
101
+ - lib/rack-cas-rails/rails_application_additions.rb
102
+ - lib/rack-cas-rails/version.rb
103
103
  homepage: https://github.com/bitaxis/rack-cas-rails.git
104
104
  licenses:
105
105
  - MIT
@@ -1,3 +0,0 @@
1
- require "rack_cas_rails/application"
2
- require "rack_cas_rails/controllers"
3
- require "rack_cas_rails/version"
@@ -1,66 +0,0 @@
1
- module RackCASRails
2
- end
3
-
4
- ##
5
- # Augment Rails' ApplicationController class with authentication related methods.
6
-
7
- class ApplicationController < ActionController::Base
8
-
9
- ##
10
- # When invoked, will force authenticate. Most likely to be invoked as a before_action.
11
-
12
- def authenticate!
13
- return if authenticated?
14
- if File.exists?("public/401.html")
15
- render(:file => "public/401.html", :status => :unauthorized)
16
- else
17
- render(:plain => "Unauthorized!", :status => :unauthorized)
18
- end
19
- end
20
-
21
- ##
22
- # Determines whether the current request belongs to a session that is authenticated or not.
23
- # @return [Bool] True if current request belongs to an authenticated session, false otherwise.
24
-
25
- def authenticated?
26
- request.session["cas"] && request.session["cas"]["user"]
27
- end
28
-
29
- ##
30
- # Renders the CAS login URL with re-direct back to some URL.
31
- # @param service_url [String] Optional url to redirect to after authentication.
32
- # @return [String] The CAS login URL.
33
-
34
- def login_url(service_url=request.url)
35
- url = URI(Rails.application.cas_server_url)
36
- url.path = "/login"
37
- url.query = "service=#{service_url || request.url}"
38
- url.to_s
39
- end
40
-
41
- ##
42
- # Renders the CAS logout URL with re-direct back to some URL (e.g. the root URL). The logout path is "/logout",
43
- # which is actually undocumented. I had to find out by looking into the source code of the rack-cas gem.
44
- # @param service_url [String] Optional url to redirect to after authentication.
45
- # @return [String] The CAS logout URL.
46
-
47
- def logout_url(service_url=request.url)
48
- url = URI(request.url)
49
- url.path = "/logout"
50
- url.query = "service=#{service_url || request.url}"
51
- url.to_s
52
- end
53
-
54
- helper_method :authenticate!
55
- helper_method :authenticated?
56
- helper_method :login_url
57
- helper_method :logout_url
58
-
59
- end
60
-
61
- ##
62
- # All actions in controllers derived from this controller require authentication.
63
-
64
- class RackCASRails::AuthenticatedController < ApplicationController
65
- before_action :authenticate!
66
- end