projects
/
websub-hub
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor of authentication and html-templates into separate modules
[websub-hub]
/
src
/
service.js
diff --git
a/src/service.js
b/src/service.js
index 1d9b8a0922af1b8699e7232fd078b5f244a66f8e..6dcde1ec201b1a212beb704d99c61edebcd75be9 100644
(file)
--- a/
src/service.js
+++ b/
src/service.js
@@
-9,8
+9,7
@@
const { Dingus } = require('@squeep/api-dingus');
const common = require('./common');
const Enum = require('./enum');
const Manager = require('./manager');
const common = require('./common');
const Enum = require('./enum');
const Manager = require('./manager');
-const SessionManager = require('./session-manager');
-const Authenticator = require('./authenticator');
+const { Authenticator, SessionManager } = require('@squeep/authentication-module');
const path = require('path');
const _fileScope = common.fileScope(__filename);
const path = require('path');
const _fileScope = common.fileScope(__filename);
@@
-155,7
+154,7
@@
class Service extends Dingus {
this.setResponseType(this.responseTypes, req, res, ctx);
this.setResponseType(this.responseTypes, req, res, ctx);
- await this.authenticator.
r
equired(req, res, ctx, this.loginPath);
+ await this.authenticator.
sessionR
equired(req, res, ctx, this.loginPath);
await this.manager.getAdminOverview(res, ctx);
}
await this.manager.getAdminOverview(res, ctx);
}
@@
-174,15
+173,16
@@
class Service extends Dingus {
this.setResponseType(this.responseTypes, req, res, ctx);
this.setResponseType(this.responseTypes, req, res, ctx);
- await this.authenticator.
r
equired(req, res, ctx, this.loginPath);
+ await this.authenticator.
sessionR
equired(req, res, ctx, this.loginPath);
await this.manager.getTopicDetails(res, ctx);
}
/**
await this.manager.getTopicDetails(res, ctx);
}
/**
- * S
ame as
super.ingestBody, but if no body was sent, do not parse (and
+ * S
imilar to
super.ingestBody, but if no body was sent, do not parse (and
* thus avoid possible unsupported media type error).
* thus avoid possible unsupported media type error).
+ * Also removes raw body from context, to simplify scrubbing sensitive data from logs.
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx
@@
-192,6
+192,7
@@
class Service extends Dingus {
const contentType = Dingus.getRequestContentType(req);
if (ctx.rawBody) {
this.parseBody(contentType, ctx);
const contentType = Dingus.getRequestContentType(req);
if (ctx.rawBody) {
this.parseBody(contentType, ctx);
+ delete ctx.rawBody;
}
}
}
}
@@
-207,7
+208,7
@@
class Service extends Dingus {
this.setResponseType(this.responseTypes, req, res, ctx);
this.setResponseType(this.responseTypes, req, res, ctx);
- await this.authenticator.
requiredLocal(req, res, ctx, this.loginPath
);
+ await this.authenticator.
apiRequiredLocal(req, res, ctx
);
await this.maybeIngestBody(req, res, ctx);
ctx.method = req.method;
await this.maybeIngestBody(req, res, ctx);
ctx.method = req.method;
@@
-226,7
+227,7
@@
class Service extends Dingus {
this.setResponseType(this.responseTypes, req, res, ctx);
this.setResponseType(this.responseTypes, req, res, ctx);
- await this.authenticator.
requiredLocal(req, res, ctx, this.loginPath
);
+ await this.authenticator.
apiRequiredLocal(req, res, ctx
);
await this.maybeIngestBody(req, res, ctx);
ctx.method = req.method;
await this.maybeIngestBody(req, res, ctx);
ctx.method = req.method;
@@
-245,13
+246,14
@@
class Service extends Dingus {
this.setResponseType(this.responseTypes, req, res, ctx);
this.setResponseType(this.responseTypes, req, res, ctx);
- await this.authenticator.
requiredLocal(req, res, ctx, this.loginPath
);
+ await this.authenticator.
apiRequiredLocal(req, res, ctx
);
await this.manager.processTasks(res, ctx);
}
/**
await this.manager.processTasks(res, ctx);
}
/**
+ * Delegate login to authentication module.
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx
@@
-269,6
+271,7
@@
class Service extends Dingus {
/**
/**
+ * Delegate login to authentication module.
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx
@@
-279,6
+282,8
@@
class Service extends Dingus {
this.setResponseType(this.responseTypes, req, res, ctx);
this.setResponseType(this.responseTypes, req, res, ctx);
+ await this.authenticator.sessionOptionalLocal(req, res, ctx);
+
await this.maybeIngestBody(req, res, ctx);
await this.sessionManager.postAdminLogin(res, ctx);
await this.maybeIngestBody(req, res, ctx);
await this.sessionManager.postAdminLogin(res, ctx);
@@
-286,6
+291,7
@@
class Service extends Dingus {
/**
/**
+ * Delegate login to authentication module.
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx
@@
-296,11
+302,14
@@
class Service extends Dingus {
this.setResponseType(this.responseTypes, req, res, ctx);
this.setResponseType(this.responseTypes, req, res, ctx);
+ await this.authenticator.sessionOptionalLocal(req, res, ctx);
+
await this.sessionManager.getAdminLogout(res, ctx);
}
/**
await this.sessionManager.getAdminLogout(res, ctx);
}
/**
+ * Delegate login to authentication module.
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {Object} ctx