   queue = [
 
     ->
-      # checking if token is valid
-      JApiToken.one { code : token }, (err, apiToken_) ->
-        return sendApiError res, apiErrors.internalError    if err
-        return sendApiError res, apiErrors.invalidApiToken  unless apiToken_
+      verifyApiToken token, (err, apiToken_) ->
+        return sendApiError res, err  if err
+
         apiToken = apiToken_
-        queue.next()
-
-    ->
-      checkApiAvailability { apiToken }, (err) ->
-        return sendApiError res, err  if err
         queue.next()
 
     ->

{ daisy }                          = require 'bongo'
{ checkAuthorizationBearerHeader } = require '../../helpers'
{ sendApiError
  sendApiResponse
  checkApiAvailability }           = require './helpers'



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

  { JAccount, JUser } = (require '../../bongo').models

  # validating req params
  { error, token, username } = validateRequest req
