 
   # validating req params
   { error, token, username } = validateRequest req
-  return res.status(error.statusCode).send(error.message)  if error
+  return sendApiError res, error  if error
 
   account  = null
   apiToken = null

{ argv } = require 'optimist'
KONFIG   = require('koding-config-manager').load("main.#{argv.c}")

{ daisy }                          = require 'bongo'
{ checkAuthorizationBearerHeader } = require '../../helpers'

module.exports = createSsoToken = (req, res, next) ->


      port       = if publicPort in ['80', '443'] then '' else ":#{publicPort}"

      loginUrl = "#{protocol}://#{host}#{port}/#{URL}"
      return sendApiResponse res, { token, loginUrl }

  ]

