moved auth lib into validators lib

This commit is contained in:
Chris Troutner
2021-07-07 17:15:27 -07:00
parent c5e0a8a95b
commit 6e08ddba7f
2 changed files with 17 additions and 22 deletions
@@ -4,7 +4,6 @@
const User = require('../../../adapters/localdb/models/users')
const config = require('../../../../config')
const getToken = require('../../../lib/auth')
const jwt = require('jsonwebtoken')
const wlogger = require('../../../adapters/wlogger')
@@ -13,7 +12,6 @@ let _this
class Validators {
constructor () {
this.User = User
this.getToken = getToken
this.jwt = jwt
this.config = config
@@ -149,6 +147,23 @@ class Validators {
ctx.throw(401, error.message)
}
}
getToken (ctx) {
const header = ctx.request.header.authorization
if (!header) {
return null
}
const parts = header.split(' ')
if (parts.length !== 2) {
return null
}
const scheme = parts[0]
const token = parts[1]
if (/^Bearer$/i.test(scheme)) {
return token
}
return null
}
}
module.exports = Validators
-20
View File
@@ -1,20 +0,0 @@
/*
Retrieves the JWT token from the header of the API request.
*/
module.exports = function getToken (ctx) {
const header = ctx.request.header.authorization
if (!header) {
return null
}
const parts = header.split(' ')
if (parts.length !== 2) {
return null
}
const scheme = parts[0]
const token = parts[1]
if (/^Bearer$/i.test(scheme)) {
return token
}
return null
}