1 | MeshbluAuthParser = require '../helpers/meshblu-auth-parser'
|
2 | debug = require('debug')('meshblu-server-http:authenticate-controller')
|
3 | _ = require 'lodash'
|
4 |
|
5 | class AuthenticateController
|
6 | constructor: ({@jobManager}) ->
|
7 | @authParser = new MeshbluAuthParser
|
8 |
|
9 | create: (req, res) =>
|
10 | auth = @authParser.parse req
|
11 |
|
12 | options =
|
13 | metadata:
|
14 | auth: auth
|
15 | jobType: 'Authenticate'
|
16 |
|
17 | @jobManager.do 'request', 'response', options, (error, jobResponse) =>
|
18 | return res.sendError error if error?
|
19 | _.each jobResponse.metadata, (value, key) => res.set "x-meshblu-#{key}", value
|
20 | res.status(jobResponse.metadata.code).end()
|
21 |
|
22 | module.exports = AuthenticateController
|