Skip to content

Commit 3276db3

Browse files
authored
Merge pull request #21 from leaonline/migration/3.0
Migration to Meteor 3.0
2 parents 69af291 + b696430 commit 3276db3

23 files changed

+721
-617
lines changed

.versions

+64-69
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,65 @@
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
28-
29-
30-
31-
1+
2+
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
3231
33-
34-
35-
36-
37-
local-test:leaonline:[email protected]
38-
39-
40-
41-
meteortesting:[email protected]
42-
meteortesting:[email protected]
43-
meteortesting:[email protected]
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
practicalmeteor:[email protected]_3
55-
56-
57-
58-
59-
60-
61-
62-
63-
64-
65-
66-
67-
68-
69-
70-
32+
33+
34+
local-test:leaonline:[email protected]
35+
36+
37+
38+
meteortesting:[email protected]
39+
meteortesting:[email protected]
40+
meteortesting:[email protected]
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+

API.md

+57-43
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ Uses the following values to check:</p>
4646
<li>&#39;saveRefreshToken&#39;,</li>
4747
<li>&#39;saveToken&#39;,</li>
4848
<li>&#39;getAccessToken&#39;</li>
49+
<li>&#39;revokeToken&#39;</li>
4950
</ul>
5051
</dd>
5152
<dt><a href="#UserValidation">UserValidation</a></dt>
5253
<dd><p>Used to register handlers for different instances that validate users.
5354
This allows you to validate user access on a client-based level.</p>
5455
</dd>
56+
<dt><a href="#validateParams">validateParams</a> ⇒ <code>boolean</code></dt>
57+
<dd><p>Abstraction that checks given query/body params against a given schema</p>
58+
</dd>
5559
<dt><a href="#app">app</a> : <code>Object</code></dt>
5660
<dd><p>Wrapped <code>WebApp</code> with express-style get/post and default use routes.</p>
5761
</dd>
@@ -76,6 +80,8 @@ Implements the OAuth2Server model with Meteor-Mongo bindings.
7680
* [.saveRefreshToken(token, clientId, expires, user)](#OAuthMeteorModel+saveRefreshToken) ⇒ <code>Promise.&lt;\*&gt;</code>
7781
* [.getRefreshToken()](#OAuthMeteorModel+getRefreshToken)
7882
* [.grantTypeAllowed(clientId, grantType)](#OAuthMeteorModel+grantTypeAllowed) ⇒ <code>boolean</code>
83+
* [.verifyScope(accessToken, scope)](#OAuthMeteorModel+verifyScope) ⇒ <code>Promise.&lt;boolean&gt;</code>
84+
* [.revokeToken()](#OAuthMeteorModel+revokeToken)
7985

8086
<a name="OAuthMeteorModel+log"></a>
8187

@@ -199,6 +205,24 @@ getRefreshToken(token) should return an object with:
199205
| clientId |
200206
| grantType |
201207

208+
<a name="OAuthMeteorModel+verifyScope"></a>
209+
210+
### oAuthMeteorModel.verifyScope(accessToken, scope) ⇒ <code>Promise.&lt;boolean&gt;</code>
211+
Compares expected scope from token with actual scope from request
212+
213+
**Kind**: instance method of [<code>OAuthMeteorModel</code>](#OAuthMeteorModel)
214+
215+
| Param |
216+
| --- |
217+
| accessToken |
218+
| scope |
219+
220+
<a name="OAuthMeteorModel+revokeToken"></a>
221+
222+
### oAuthMeteorModel.revokeToken()
223+
revokeToken(refreshToken) is required and should return true
224+
225+
**Kind**: instance method of [<code>OAuthMeteorModel</code>](#OAuthMeteorModel)
202226
<a name="OAuth2ServerDefaults"></a>
203227

204228
## OAuth2ServerDefaults : <code>Object</code>
@@ -250,6 +274,7 @@ Defaults to a 500 response, unless further details were added.
250274
| res | | |
251275
| options | <code>Object</code> | options with error information |
252276
| options.error | <code>String</code> | Error name |
277+
| options.logError | <code>boolean</code> | optional flag to log the erroe to the console |
253278
| options.description | <code>String</code> | Error description |
254279
| options.uri | <code>String</code> | Optional uri to redirect to when error occurs |
255280
| options.status | <code>Number</code> | Optional statuscode, defaults to 500 |
@@ -274,6 +299,7 @@ Uses the following values to check:
274299
- 'saveRefreshToken',
275300
- 'saveToken',
276301
- 'getAccessToken'
302+
- 'revokeToken'
277303

278304
**Kind**: global constant
279305
**Returns**: <code>boolean</code> - true if valid, otherwise false
@@ -289,6 +315,24 @@ Used to register handlers for different instances that validate users.
289315
This allows you to validate user access on a client-based level.
290316

291317
**Kind**: global constant
318+
319+
* [UserValidation](#UserValidation)
320+
* [.register(instance, validationHandler)](#UserValidation.register)
321+
* [.isValid(instance, handlerArgs)](#UserValidation.isValid) ⇒ <code>\*</code>
322+
323+
<a name="UserValidation.register"></a>
324+
325+
### UserValidation.register(instance, validationHandler)
326+
Registers a validation method that allows
327+
to validate users on custom logic.
328+
329+
**Kind**: static method of [<code>UserValidation</code>](#UserValidation)
330+
331+
| Param | Type | Description |
332+
| --- | --- | --- |
333+
| instance | [<code>OAuth2Server</code>](#OAuth2Server) | |
334+
| validationHandler | <code>function</code> | sync or async function that performs the validation |
335+
292336
<a name="UserValidation.isValid"></a>
293337

294338
### UserValidation.isValid(instance, handlerArgs) ⇒ <code>\*</code>
@@ -302,53 +346,23 @@ Delegates `handlerArgs` to the registered validation handler.
302346
| instance | [<code>OAuth2Server</code>](#OAuth2Server) |
303347
| handlerArgs | <code>\*</code> |
304348

305-
<a name="app"></a>
349+
<a name="validateParams"></a>
306350

307-
## app : <code>Object</code>
308-
Wrapped `WebApp` with express-style get/post and default use routes.
351+
## validateParams ⇒ <code>boolean</code>
352+
Abstraction that checks given query/body params against a given schema
309353

310354
**Kind**: global constant
311-
**See**: https://docs.meteor.com/packages/webapp.html
312-
313-
* [app](#app) : <code>Object</code>
314-
* [.get(url, handler)](#app.get)
315-
* [.post(url, handler)](#app.post)
316-
* [.use(args)](#app.use)
317-
318-
<a name="app.get"></a>
319-
320-
### app.get(url, handler)
321-
Creates a get route for a given handler
322-
323-
**Kind**: static method of [<code>app</code>](#app)
324-
325-
| Param | Type |
326-
| --- | --- |
327-
| url | <code>string</code> |
328-
| handler | <code>function</code> |
329-
330-
<a name="app.post"></a>
331-
332-
### app.post(url, handler)
333-
Creates a post route for a given handler.
334-
If headers' content-type does not equal to `application/x-www-form-urlencoded`
335-
then it will be transformed accordingly.
336-
337-
**Kind**: static method of [<code>app</code>](#app)
338-
339-
| Param | Type |
340-
| --- | --- |
341-
| url | <code>string</code> |
342-
| handler | <code>function</code> |
343-
344-
<a name="app.use"></a>
345-
346-
### app.use(args)
347-
Default wrapper around `WebApp.use`
348-
349-
**Kind**: static method of [<code>app</code>](#app)
350355

351356
| Param |
352357
| --- |
353-
| args |
358+
| actualParams |
359+
| requiredParams |
360+
| debug |
361+
362+
<a name="app"></a>
354363

364+
## app : <code>Object</code>
365+
Wrapped `WebApp` with express-style get/post and default use routes.
366+
367+
**Kind**: global constant
368+
**See**: https://docs.meteor.com/packages/webapp.html

HISTORY.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# History
22

3+
### 6.0.0
4+
- Meteor 3 / Express compatibility
5+
- added scope verification in authenticated routes
6+
- improved internal logging
7+
- fix bug in validation for custom models
8+
- fix support for explicit `client.id` field
9+
10+
## 5.0.0
11+
- sync support for @node-oauth/oauth2-server 5.x by
12+
313
## 4.2.1
414
- this is a patch release, fixing a syntax error
515
(that never got picked up, due to wrong linter config)

lib/middleware/getDebugMiddleware.js

+22-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,29 @@ import { debug } from '../utils/console'
44
* Creates a middleware to debug routes on an instance level
55
* @private
66
* @param instance
7-
* @return {function(*, *, *): *}
7+
* @param options {object?} optional options
8+
* @param options.description {string?} optional way to descrive the next handler
9+
* @param options.data {boolean?} optional flag to log body/query
810
*/
9-
export const getDebugMiddleWare = instance => (req, res, next) => {
10-
if (instance.debug === true) {
11+
export const getDebugMiddleWare = (instance, options = {}) => {
12+
if (!instance.debug) {
13+
return function (req, res, next) { next() }
14+
}
15+
16+
return function (req, res, next) {
1117
const baseUrl = req.originalUrl.split('?')[0]
12-
debug(req.method, baseUrl, req.query || req.body)
18+
let message = `${req.method} ${baseUrl}`
19+
20+
if (options.description) {
21+
message = `${message} (${options.description})`
22+
}
23+
24+
if (options.data) {
25+
const data = { query: req.query, body: req.body }
26+
message = `${message} data: ${data}`
27+
}
28+
29+
debug(message)
30+
next()
1331
}
14-
return next()
1532
}

lib/middleware/secureHandler.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import { bind } from '../utils/bind'
88
* @param handler
99
* @return {Function}
1010
*/
11-
export const secureHandler = (self, handler) => bind(function (req, res, next) {
11+
export const secureHandler = (self, handler) => bind(async function (req, res, next) {
1212
const that = this
13-
1413
try {
15-
handler.call(that, req, res, next)
14+
return handler.call(that, req, res, next)
1615
} catch (anyError) {
1716
// to avoid server-crashes we wrap all request handlers and
1817
// catch the error here, creating a default 500 response

0 commit comments

Comments
 (0)