You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Added interception points and return user from authorize
Added `preLogout` and `postLogout` interception points.
Also, return the user from `authorize`. Previously this returned `true`.
BREAKING CHANGE: `authorize` returns a `user` instance, not a boolean. If the `authorize` call fails, it will throw an exception as before.
Copy file name to clipboardExpand all lines: README.md
+28-17Lines changed: 28 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,11 @@
1
1
# cbauth
2
2
3
-
Wrapper for authentication for ColdBox.
3
+
Authentication services for ColdBox Applications.
4
+
5
+
## Requirements
6
+
7
+
- Lucee 5+
8
+
- Adobe ColdFusion 2016+
4
9
5
10
## Installation
6
11
@@ -14,7 +19,9 @@ Specify a `userServiceClass` in your `config/ColdBox.cfc` inside `moduleSettings
14
19
2.`retrieveUserByUsername( username )`
15
20
3.`retrieveUserById( id )`
16
21
17
-
Additionally, the user component returned by the `retrieve` methods needs to respond to `getId()`.
22
+
> We have provided an interface to implement and can be found at `cbauth.interfaces.IUserService`.
23
+
24
+
Additionally, the user component returned by the `retrieve` methods needs to respond to `getId()`. We have also provided a nice interface for you to follow: `cbauth.interfaces.IAuthUser`
18
25
19
26
You can also specify a `sessionStorage` and a `requestStorage` WireBox mapping.
20
27
These will be used inside `AuthenticationService`. By default, these are
@@ -51,7 +58,7 @@ This is very useful in views. And since WireBox handles singleton management, y
51
58
| user | any | true || The user component to log in. The component must respond to the `getId()` method. |
52
59
53
60
Logs a user in to the system. The user component must respond to the `getId()` method. Additionally, the user is cached in the `request` scope. If a user is already in the session, this will replace it with the given user.
54
-
61
+
This method returns the passed in `user` object.
55
62
56
63
### `logout`
57
64
@@ -61,7 +68,6 @@ Logs a user in to the system. The user component must respond to the `getId()`
61
68
62
69
Logs a user out of system. This method can be called regardless of if there is currently a logged in user.
63
70
64
-
65
71
### `authenticate`
66
72
67
73
| name | type | required | default | description |
@@ -71,8 +77,7 @@ Logs a user out of system. This method can be called regardless of if there is
71
77
72
78
Attempts to log a user by calling the `isValidCredentials` and `retrieveUserByUsername` on the provided `userServiceClass`. If `isValidCredentials` returns `false`, it throws a `InvalidCredentials` exception.
73
79
74
-
If it succeeds, it returns `true`. If it succeeds, it also sets the user id (obtained by calling `getId()` on the returned user component) in the session and the returned user component in the request.
75
-
80
+
If it succeeds, it returns the logged in `user` object. If it succeeds, it also sets the user id (obtained by calling `getId()` on the returned user component) in the session and the returned user component in the request.
76
81
77
82
### `isLoggedIn`
78
83
@@ -82,7 +87,6 @@ If it succeeds, it returns `true`. If it succeeds, it also sets the user id (ob
82
87
83
88
Returns whether a user is logged in to the system.
84
89
85
-
86
90
### `check`
87
91
88
92
| name | type | required | default | description |
@@ -91,7 +95,6 @@ Returns whether a user is logged in to the system.
91
95
92
96
_Alias for [`isLoggedIn`](#isLoggedIn)_
93
97
94
-
95
98
### `guest`
96
99
97
100
| name | type | required | default | description |
@@ -100,7 +103,6 @@ _Alias for [`isLoggedIn`](#isLoggedIn)_
100
103
101
104
Returns whether a user is logged out of the system.
102
105
103
-
104
106
### `getUser`
105
107
106
108
| name | type | required | default | description |
@@ -113,7 +115,6 @@ If there is no logged in user, it throws a `NoUserLoggedIn` exception.
113
115
114
116
Additionally, it sets the user in the `request` scope so subsequent calls to `getUser` don't re-fetch the user from the database or other permanent storage.
115
117
116
-
117
118
### `user`
118
119
119
120
| name | type | required | default | description |
@@ -122,7 +123,6 @@ Additionally, it sets the user in the `request` scope so subsequent calls to `ge
122
123
123
124
_Alias for [`getUser`](#getUser)_
124
125
125
-
126
126
### `getUserId`
127
127
128
128
| name | type | required | default | description |
@@ -133,10 +133,9 @@ Returns the currently logged in user id.
133
133
134
134
If there is no logged in user, it throws a `NoUserLoggedIn` exception.
cbauth announces several custom interception points. You can use these interception points to change request data or add additional values to session or request scopes. The `preAuthentication` and `postAuthentication` events fire during the standard `authenticate()` method call with a username and password. The `preLogin` and `postLogin` events fire during the `login()` method call.
138
+
cbauth announces several custom interception points. You can use these interception points to change request data or add additional values to session or request scopes. The `preAuthentication` and `postAuthentication` events fire during the standard `authenticate()` method call with a username and password. The `preLogin` and `postLogin` events fire during the `login()` method call. The `preLogout` and `postLogout` events fire during the `logout()` method call.
140
139
141
140
Note: the `preLogin` and `postLogin` interception points will be called during the course of `authenticate()`. The order of the calls then are `preAuthentication` -> `preLogin` -> `postLogin` -> `postAuthentication`.
142
141
@@ -151,7 +150,6 @@ interceptData
151
150
152
151
Modifying the values in the `interceptData` will change what is passed to `isValidCredentials` and `retrieveUserByUsername`. This is the prime time to ignore certain requests or remove or pad usernames.
153
152
154
-
155
153
### `postAuthentication`
156
154
157
155
interceptData
@@ -172,7 +170,6 @@ interceptData
172
170
| --- | --- |
173
171
| user | The user component to be logged in. |
174
172
175
-
176
173
### `postLogin`
177
174
178
175
interceptData
@@ -183,5 +180,19 @@ interceptData
183
180
| sessionStorage | The sessionStorage object to store additional values if needed. |
184
181
| requestStorage | The requestStorage object to store additional values if needed. |
185
182
186
-
187
183
This is a good opportunity to store additional data if your application logged the user in manually without authenticating via a username/password like a "remember me" system.
184
+
185
+
### `preLogout`
186
+
187
+
interceptData
188
+
189
+
| name | description |
190
+
| --- | --- |
191
+
| user | The user component that is logged in if you are logged in, else `null`|
0 commit comments