update dependencies and devDependencies
[squeep-authentication-module] / lib / common.js
index d69e6ad6a2131d12d975dbaaddaca70fdb3551e5..1a117e9a71d7ff877abd15c7b9fd467315cd0818 100644 (file)
@@ -46,8 +46,23 @@ const mysteryBoxLogger = (logger, scope) => {
   };
 };
 
+/**
+ * Hide sensitive part of an Authorization header.
+ * @param {String} authHeader
+ * @returns {String}
+ */
+const obscureAuthorizationHeader = (authHeader) => {
+  if (!authHeader) {
+    return authHeader;
+  }
+  const space = authHeader.indexOf(' ');
+  // This blurs entire string if no space found, because -1.
+  return authHeader.slice(0, space + 1) + '*'.repeat(authHeader.length - (space + 1));
+};
+
 module.exports = Object.assign(Object.create(common), {
   freezeDeep,
   mysteryBoxLogger,
+  obscureAuthorizationHeader,
   omit,
 });
\ No newline at end of file