Skip to content
This repository
Browse code

Organize files structure according to best practices outline in RoR W…

…eblog.
  • Loading branch information...
commit a6b44404547229199d45fec566ff9df0c27fda7f 1 parent e16509c
José Valim authored
14  lib/warden.rb
@@ -6,14 +6,12 @@
6 6
 require 'warden/proxy'
7 7
 require 'warden/manager'
8 8
 require 'warden/errors'
9  
-require 'warden/authentication/hooks'
10  
-require 'warden/authentication/declarable'
11  
-require 'warden/authentication/strategies'
12  
-require 'warden/authentication/strategies/base'
13  
-require 'warden/authentication/serializers'
14  
-require 'warden/authentication/serializers/base'
15  
-require 'warden/authentication/serializers/cookie'
16  
-require 'warden/authentication/serializers/session'
  9
+require 'warden/strategies'
  10
+require 'warden/strategies/base'
  11
+require 'warden/serializers'
  12
+require 'warden/serializers/base'
  13
+require 'warden/serializers/cookie'
  14
+require 'warden/serializers/session'
17 15
 
18 16
 module Warden
19 17
   class NotAuthenticated < StandardError; end
124  lib/warden/authentication/hooks.rb
... ...
@@ -1,124 +0,0 @@
1  
-# encoding: utf-8
2  
-module Warden
3  
-  class Manager
4  
-
5  
-    class << self
6  
-      # A callback hook set to run every time after a user is set.
7  
-      # This will happen the first time the user is either authenticated, accessed or manually set
8  
-      # during a request.  You can supply as many hooks as you like, and they will be run in order of decleration
9  
-      #
10  
-      # Parameters:
11  
-      # <block> A block where you can set arbitrary logic to run every time a user is set
12  
-      #   Block Parameters: |user, auth, opts|
13  
-      #     user - The user object that is being set
14  
-      #     auth - The raw authentication proxy object.
15  
-      #     opts - any options passed into the set_user call includeing :scope
16  
-      #
17  
-      # Example:
18  
-      #   Warden::Manager.after_set_user do |user,auth,opts|
19  
-      #     scope = opts[:scope]
20  
-      #     if auth.session["#{scope}.last_access"].to_i > (Time.now - 5.minutes)
21  
-      #       auth.logout(scope)
22  
-      #       throw(:warden, :scope => scope, :reason => "Times Up")
23  
-      #     end
24  
-      #     auth.session["#{scope}.last_access"] = Time.now
25  
-      #   end
26  
-      #
27  
-      # :api: public
28  
-      def after_set_user(&block)
29  
-        raise BlockNotGiven unless block_given?
30  
-        _after_set_user << block
31  
-      end
32  
-
33  
-      # Provides access to the array of after_set_user blocks to run
34  
-      # :api: private
35  
-      def _after_set_user # :nodoc:
36  
-        @_after_set_user ||= []
37  
-      end
38  
-
39  
-      # A callback hook set to run after the first authentiation of a session.
40  
-      # This will only happenwhen the session is first authenticated
41  
-      #
42  
-      # Parameters:
43  
-      # <block> A block to contain logic for the callback
44  
-      #   Block Parameters: |user, auth, opts|
45  
-      #     user - The user object that is being set
46  
-      #     auth - The raw authentication proxy object.
47  
-      #     opts - any options passed into the authenticate call includeing :scope
48  
-      #
49  
-      # Example:
50  
-      #
51  
-      #   Warden::Manager.after_authentication do |user, auth, opts|
52  
-      #     throw(:warden, opts) unless user.active?
53  
-      #   end
54  
-      #
55  
-      # :api: public
56  
-      def after_authentication(&block)
57  
-        raise BlockNotGiven unless block_given?
58  
-        _after_authentication << block
59  
-      end
60  
-
61  
-      # Provides access to the array of after_authentication blocks
62  
-      # :api: private
63  
-      def _after_authentication
64  
-        @_after_authentication ||= []
65  
-      end
66  
-
67  
-      # A callback that runs just prior to the failur application being called.
68  
-      # This callback occurs after PATH_INFO has been modified for the failure (default /unauthenticated)
69  
-      # In this callback you can mutate the environment as required by the failure application
70  
-      # If a Rails controller were used for the failure_app for example, you would need to set request[:params][:action] = :unauthenticated
71  
-      #
72  
-      # Parameters:
73  
-      # <block> A block to contain logic for the callback
74  
-      #   Block Parameters: |user, auth, opts|
75  
-      #     env - The rack env hash
76  
-      #     opts - any options passed into the authenticate call includeing :scope
77  
-      #
78  
-      # Example:
79  
-      #   Warden::Manager.before_failure do |env, opts|
80  
-      #     params = Rack::Request.new(env).params
81  
-      #     params[:action] = :unauthenticated
82  
-      #     params[:warden_failure] = opts
83  
-      #   end
84  
-      #
85  
-      # :api: public
86  
-      def before_failure(&block)
87  
-        _before_failure << block
88  
-      end
89  
-
90  
-      # Provides access to the callback array for before_failure
91  
-      # :api: private
92  
-      def _before_failure
93  
-        @_before_failure ||= []
94  
-      end
95  
-
96  
-      # A callback that runs just prior to the logout of each scope.
97  
-      #
98  
-      # Parameters:
99  
-      # <block> A block to contain logic for the callback
100  
-      #   Block Parameters: |user, auth, scope|
101  
-      #     user - The authenticated user for the current scope
102  
-      #     auth - The warden proxy object
103  
-      #     scope - current logout scope
104  
-      #
105  
-      # Example:
106  
-      #   Warden::Manager.before_logout do |user, auth, scope|
107  
-      #     user.forget_me!
108  
-      #   end
109  
-      #
110  
-      # :api: public
111  
-      def before_logout(&block)
112  
-        _before_logout << block
113  
-      end
114  
-
115  
-      # Provides access to the callback array for before_logout
116  
-      # :api: private
117  
-      def _before_logout
118  
-        @_before_logout ||= []
119  
-      end
120  
-
121  
-    end
122  
-
123  
-  end # Manager
124  
-end # Warden
0  lib/warden/authentication/declarable.rb → lib/warden/declarable.rb
File renamed without changes
121  lib/warden/hooks.rb
... ...
@@ -0,0 +1,121 @@
  1
+# encoding: utf-8
  2
+module Warden
  3
+  module Hooks
  4
+
  5
+    # A callback hook set to run every time after a user is set.
  6
+    # This will happen the first time the user is either authenticated, accessed or manually set
  7
+    # during a request.  You can supply as many hooks as you like, and they will be run in order of decleration
  8
+    #
  9
+    # Parameters:
  10
+    # <block> A block where you can set arbitrary logic to run every time a user is set
  11
+    #   Block Parameters: |user, auth, opts|
  12
+    #     user - The user object that is being set
  13
+    #     auth - The raw authentication proxy object.
  14
+    #     opts - any options passed into the set_user call includeing :scope
  15
+    #
  16
+    # Example:
  17
+    #   Warden::Manager.after_set_user do |user,auth,opts|
  18
+    #     scope = opts[:scope]
  19
+    #     if auth.session["#{scope}.last_access"].to_i > (Time.now - 5.minutes)
  20
+    #       auth.logout(scope)
  21
+    #       throw(:warden, :scope => scope, :reason => "Times Up")
  22
+    #     end
  23
+    #     auth.session["#{scope}.last_access"] = Time.now
  24
+    #   end
  25
+    #
  26
+    # :api: public
  27
+    def after_set_user(&block)
  28
+      raise BlockNotGiven unless block_given?
  29
+      _after_set_user << block
  30
+    end
  31
+
  32
+    # Provides access to the array of after_set_user blocks to run
  33
+    # :api: private
  34
+    def _after_set_user # :nodoc:
  35
+      @_after_set_user ||= []
  36
+    end
  37
+
  38
+    # A callback hook set to run after the first authentiation of a session.
  39
+    # This will only happenwhen the session is first authenticated
  40
+    #
  41
+    # Parameters:
  42
+    # <block> A block to contain logic for the callback
  43
+    #   Block Parameters: |user, auth, opts|
  44
+    #     user - The user object that is being set
  45
+    #     auth - The raw authentication proxy object.
  46
+    #     opts - any options passed into the authenticate call includeing :scope
  47
+    #
  48
+    # Example:
  49
+    #
  50
+    #   Warden::Manager.after_authentication do |user, auth, opts|
  51
+    #     throw(:warden, opts) unless user.active?
  52
+    #   end
  53
+    #
  54
+    # :api: public
  55
+    def after_authentication(&block)
  56
+      raise BlockNotGiven unless block_given?
  57
+      _after_authentication << block
  58
+    end
  59
+
  60
+    # Provides access to the array of after_authentication blocks
  61
+    # :api: private
  62
+    def _after_authentication
  63
+      @_after_authentication ||= []
  64
+    end
  65
+
  66
+    # A callback that runs just prior to the failur application being called.
  67
+    # This callback occurs after PATH_INFO has been modified for the failure (default /unauthenticated)
  68
+    # In this callback you can mutate the environment as required by the failure application
  69
+    # If a Rails controller were used for the failure_app for example, you would need to set request[:params][:action] = :unauthenticated
  70
+    #
  71
+    # Parameters:
  72
+    # <block> A block to contain logic for the callback
  73
+    #   Block Parameters: |user, auth, opts|
  74
+    #     env - The rack env hash
  75
+    #     opts - any options passed into the authenticate call includeing :scope
  76
+    #
  77
+    # Example:
  78
+    #   Warden::Manager.before_failure do |env, opts|
  79
+    #     params = Rack::Request.new(env).params
  80
+    #     params[:action] = :unauthenticated
  81
+    #     params[:warden_failure] = opts
  82
+    #   end
  83
+    #
  84
+    # :api: public
  85
+    def before_failure(&block)
  86
+      _before_failure << block
  87
+    end
  88
+
  89
+    # Provides access to the callback array for before_failure
  90
+    # :api: private
  91
+    def _before_failure
  92
+      @_before_failure ||= []
  93
+    end
  94
+
  95
+    # A callback that runs just prior to the logout of each scope.
  96
+    #
  97
+    # Parameters:
  98
+    # <block> A block to contain logic for the callback
  99
+    #   Block Parameters: |user, auth, scope|
  100
+    #     user - The authenticated user for the current scope
  101
+    #     auth - The warden proxy object
  102
+    #     scope - current logout scope
  103
+    #
  104
+    # Example:
  105
+    #   Warden::Manager.before_logout do |user, auth, scope|
  106
+    #     user.forget_me!
  107
+    #   end
  108
+    #
  109
+    # :api: public
  110
+    def before_logout(&block)
  111
+      _before_logout << block
  112
+    end
  113
+
  114
+    # Provides access to the callback array for before_logout
  115
+    # :api: private
  116
+    def _before_logout
  117
+      @_before_logout ||= []
  118
+    end
  119
+
  120
+  end # Hooks
  121
+end # Warden
4  lib/warden/manager.rb
... ...
@@ -1,10 +1,14 @@
1 1
 # encoding: utf-8
  2
+require 'warden/hooks'
  3
+
2 4
 module Warden
3 5
   # The middleware for Rack Authentication
4 6
   # The middlware requires that there is a session upstream
5 7
   # The middleware injects an authentication object into
6 8
   # the rack environment hash
7 9
   class Manager
  10
+    extend Warden::Hooks
  11
+
8 12
     attr_accessor :config, :failure_app
9 13
 
10 14
     # initialize the middleware.
2  lib/warden/authentication/serializers.rb → lib/warden/serializers.rb
... ...
@@ -1,4 +1,6 @@
1 1
 # encoding: utf-8
  2
+require 'warden/declarable'
  3
+
2 4
 module Warden
3 5
   module Serializers
4 6
     extend Warden::Declarable
0  lib/warden/authentication/serializers/base.rb → lib/warden/serializers/base.rb
File renamed without changes
0  lib/warden/authentication/serializers/cookie.rb → lib/warden/serializers/cookie.rb
File renamed without changes
0  lib/warden/authentication/serializers/session.rb → lib/warden/serializers/session.rb
File renamed without changes
2  lib/warden/authentication/strategies.rb → lib/warden/strategies.rb
... ...
@@ -1,4 +1,6 @@
1 1
 # encoding: utf-8
  2
+require 'warden/declarable'
  3
+
2 4
 module Warden
3 5
   module Strategies
4 6
     extend Warden::Declarable
0  lib/warden/authentication/strategies/base.rb → lib/warden/strategies/base.rb
File renamed without changes

0 notes on commit a6b4440

Please sign in to comment.
Something went wrong with that request. Please try again.