rack-cas-rails 0.0.1 → 0.0.2

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: 94069c44e3881fdf468716d0cde889f52bb29dc0
4
- data.tar.gz: a6561f72a97430cde57571c08a509241ba811150
3
+ metadata.gz: b0818a3cce11d21fc1c56fe4b1e70fefbb52c1cc
4
+ data.tar.gz: bad76f891b70a7c54228b4e6001623f6a5e7caef
5
5
  SHA512:
6
- metadata.gz: f4c4d0cf508b1eccec73e857220e52345b654fd7521d70693503651abe422f40b37f8181aa2f9c354f7495f7a8884b66d7086f6e3c06ca9cb72adca196755473
7
- data.tar.gz: 8aee86f4813563c42758a484fb173403b4d4fa09b42e4438cbaf42d7aed88a7ba631d9ec3b113db89e3b4cc14f635768ae2c49df06e67ff5023f97609090417e
6
+ metadata.gz: 6549563c5255ef7d4864b66566774744dd58ef2e104f3620325599fb4cd720e625b9fe6fe5d0ef6e36a85c1f85de7fe34abf70eaae2ae5b2a2073f8b116d17f2
7
+ data.tar.gz: 79dd96b5624f71039b3facbfe1aed8bb39c7b9898a827345f753211e8aee422fb1a590ffb913e289cd17bdecb1b598cb71e06a6be6365c4c1a6fa31ba93fef4d
data/README.md CHANGED
@@ -40,8 +40,8 @@ end
40
40
  ```
41
41
 
42
42
  In the simplest scenario, you'll want your entire application protected by authentication. That is, unless a user has authenticated,
43
- he can do nothing. To do so, add the following ```before_action``` callback to your ApplicationController (file
44
- ```app/controllers/application_ronctoller.rb```):
43
+ he can do nothing. To do so, add the following ```before_action``` callback to your ApplicationController
44
+ (file ```app/controllers/application_ronctoller.rb```):
45
45
 
46
46
  ```ruby
47
47
  class ApplicationController < ActionController::Base
@@ -73,11 +73,12 @@ authenticated session, which user does it belong to?
73
73
 
74
74
  Various Rails authentication gems makes the currently authenticated user available as an object via the ```current_user``` helper
75
75
  method. The rack-cas-rails gem does not provide this functionality. But you can look to gems such as
76
- [OmniAuth](https://github.com/intridea/omniauth), [Devise](https://github.com/plataformatec/devise), and so on
77
- to provide it.
76
+ [OmniAuth](https://github.com/intridea/omniauth), [Devise](https://github.com/plataformatec/devise),
77
+ [Authlogic](https://github.com/binarylogic/authlogic) and so on to provide it.
78
78
 
79
- But, assuming your application has **users** table in its database containing user records which are uniquely identifiable by a username
80
- column, you can add the following code to your ApplictionController:
79
+ But, assuming your application has a ActiveRecord model named ```User``` where its accmpanying database table containing user records
80
+ which are uniquely identifiable by a ```username``` attribute, you can add the following code to your ApplictionController to
81
+ provide your application with the ```current_user``` method:
81
82
 
82
83
  ```ruby
83
84
  class ApplicationController
@@ -93,13 +94,15 @@ class ApplicationController
93
94
  end
94
95
  ```
95
96
 
97
+ *Note the user records should be the same ones available to CASinoApp for authentication.*
98
+
96
99
  Lastly, change your ```views/layouts/application.html.erb``` to be as follows:
97
100
 
98
101
  ```erb
99
102
  <!DOCTYPE html>
100
103
  <html>
101
104
  <head>
102
- <title>Testapp420</title>
105
+ <title>MyGreatApplication</title>
103
106
  <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
104
107
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
105
108
  <%= csrf_meta_tags %>
@@ -125,7 +128,7 @@ Lastly, change your ```views/layouts/application.html.erb``` to be as follows:
125
128
 
126
129
  To recap, you'll have integrated your Rails application with a CAS-compliant server by making these changes to your application:
127
130
 
128
- 1. Add config.rack_cas.server_url to config/application.rb
131
+ 1. Add ```config.rack_cas.server_url``` to config/application.rb
129
132
  2. Add ```before_action :authenticate!``` to ApplicationController
130
133
  3. Add ```current_user``` method to ApplictionController
131
134
  4. Add simple navigational header to make use of ```current_user``` and the ```login_url```/```logout_url``` helpers
@@ -140,3 +143,4 @@ As such, you can expect the following behavior:
140
143
 
141
144
  A big *thank-you* goes out the teams and contributors behind [CASinoApp](http://rbcas.com) and
142
145
  [rack-cas](https://github.com/biola/rack-cas), without whom this gem will not be possible.
146
+
@@ -0,0 +1 @@
1
+ require "rack-cas-rails/controllers"
@@ -0,0 +1,61 @@
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
+ authenticated? or render(:file => "public/401.html", :status => :unauthorized) # HTTP 401
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.config.rack_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
+ helper_method :authenticate!
50
+ helper_method :authenticated?
51
+ helper_method :login_url
52
+ helper_method :logout_url
53
+
54
+ end
55
+
56
+ ##
57
+ # All actions in controllers derived from this controller require authentication.
58
+
59
+ class RackCASRails::AuthenticatedController < ApplicationController
60
+ before_action :authenticate!
61
+ end
@@ -0,0 +1,3 @@
1
+ module RackCASRails
2
+ VERSION = "0.0.2"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cas-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Brazil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-06 00:00:00.000000000 Z
11
+ date: 2015-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-cas
@@ -54,9 +54,10 @@ extra_rdoc_files: []
54
54
  files:
55
55
  - LICENSE
56
56
  - README.md
57
- - lib/rack-cas/rails/controllers.rb
58
- - lib/rack-cas/rails/helpers.rb
59
- homepage: https://github.com/bitaxis/json_hash.git
57
+ - lib/rack-cas-rails.rb
58
+ - lib/rack-cas-rails/controllers.rb
59
+ - lib/rack-cas-rails/version.rb
60
+ homepage: https://github.com/bitaxis/rack-cas-rails.git
60
61
  licenses:
61
62
  - MIT
62
63
  metadata: {}
@@ -1,37 +0,0 @@
1
- module RackCAS
2
- module Rails
3
-
4
- ##
5
- # All actions in controllers derived from this controller require authentication.
6
-
7
- class AuthenticatedController < ApplicationController
8
- before_action :authenticate!
9
- end
10
-
11
- end
12
- end
13
-
14
- ##
15
- # Augment Rails' ApplicationController class with authentication related methods.
16
-
17
- class ApplicationController
18
-
19
- ##
20
- # When invoked, will force authenticate. Most likely to be invoked as a before_action.
21
-
22
- def authenticate!
23
- authenticated? or render(:file => "public/401.html", :status => :unauthorized) # HTTP 401
24
- end
25
-
26
- ##
27
- # Determines whether the current request belongs to a session that is authenticated or not.
28
- # @return [Bool] True if current request belongs to an authenticated session, false otherwise.
29
-
30
- def authenticated?
31
- request.session["cas"] && request.session["cas"]["user"]
32
- end
33
-
34
- helper_method :authenticate!
35
- helper_method :authenticated?
36
-
37
- end
@@ -1,36 +0,0 @@
1
- module RackCAS
2
- module Rails
3
- end
4
- end
5
-
6
- ##
7
- # Augment the ApplicationHelper module with these methods.
8
-
9
- module ApplicationHelper
10
-
11
- ##
12
- # Renders the CAS login URL with re-direct back to some URL.
13
- # @param service_url [String] Optional url to redirect to after authentication.
14
- # @return [String] The CAS login URL.
15
-
16
- def login_url(service_url=request.url)
17
- url = URI(Rails.application.config.rack_cas.server_url)
18
- url.path = "/login"
19
- url.query = "service=#{service_url || request.url}"
20
- url.to_s
21
- end
22
-
23
- ##
24
- # Renders the CAS logout URL with re-direct back to some URL (e.g. the root URL). The logout path is "/logout",
25
- # which is actually undocumented. I had to find out by looking into the source code of the rack-cas gem.
26
- # @param service_url [String] Optional url to redirect to after authentication.
27
- # @return [String] The CAS logout URL.
28
-
29
- def logout_url(service_url=request.url)
30
- url = URI(request.url)
31
- url.path = "/logout"
32
- url.query = "service=#{service_url || request.url}"
33
- url.to_s
34
- end
35
-
36
- end