-
Notifications
You must be signed in to change notification settings - Fork 44
/
index.js
69 lines (64 loc) · 1.95 KB
/
index.js
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
32
33
34
35
36
37
38
39
40
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
66
67
68
69
const { BasePlugin } = require("..");
class ExamplePlugin extends BasePlugin {
/**
* This is invoked once during application start. It can be used to register
* new endpoints with the express webserver.
*
* `server` is the application instance. It provides access various utils,
* store, cache, etc.
*
* @param {*} server
*/
static initialize(server) {
server.WebServer.get("/endpoint", (req, res) => {
// ...
});
}
/**
* This is invoked *every* authentication request just before the `verify`
* method is invoked. You can use it to set default values on the config etc.
*
* `server` is the application instance. It provides access to various utils,
* store, cache, etc
*
* `config` is the config block relating to this plugin from the
* `config_token` plugin array.
*
* @name constructor
* @param {*} server
* @param {*} config
*/
constructor(server, config) {
super(...arguments);
}
/**
* Verify the request. Should return a promise which resolves the `res` object.
*
* `configToken` is the **full** decoded token. Generally you will want to
* use the particular plugin config which is available at `this.config`. The
* `server` instance is available at `this.server`.
*
* `req` is the express request object. It gives you access not to the
* **original** request but rather the request to the authentication server.
*
* `res` is a light-weight response object (see `PluginVerifyResponse` in
* `src/plugin/index.js`) which supports a sub-set of the express server
* response methods.
*
* @name verify
* @param {*} configToken
* @param {*} req
* @param {*} res
*/
verify(configToken, req, res) {
const plugin = this;
const parentReqInfo = plugin.server.utils.get_parent_request_info(req);
return new Promise(resolve => {
res.statusCode = 200;
resolve(res);
});
}
}
module.exports = {
ExamplePlugin
};