     @remoteAddr = @options.remoteAddr
 
 class RequestFilter
+  constructor: (@environment)->
   run: (request, next)->
     next null, request
 
 class AuthenticateFilter extends RequestFilter
   run: (request, callback)->
-    authenticator = authenticators[request[0].authentication?.type]
+    authenticator = authenticators[request.authentication?.type]
     if not authenticator
       return callback "wrong/unsupported authentication type request", request
 
-    if not authenticator.authenticate(request[0].authentication.key)
+    authenticated = authenticator.authenticate(request.authentication.key, @environment.kodingKey())
+    if not authenticated
       return callback "couldnt authenticate request", request
+
+    # TODO: check timestamp validuntil
+    request.username = authenticated.username
 
     callback null, request
 

  runServer: (@host="localhost", @port=9999)->
    worker = this
    @wss = new WebSocketServer host:@host, port: @port
    @environment = new Environment username: @username
    @kontrolClient = new Client name:@kiteName, port: @port, environment: @environment
    @kontrolClient.on 'connected', ()=>
      console.log "connecting to kontrol"


        clientCallback = unscrubbed[1]

        options =
          localKite: worker,
          remoteKite: client, # <-- this is subject to change
          method: scrubbed.method,
          args: unscrubbed[0].withArgs,
          username: null, # <-- this will be added by authentication filter
          authentication: unscrubbed[0].authentication
        request = new Request options

        worker.requestFilters.runFilters request, (err, request)->
          return clientCallback err, null if err

          if callback
            callback request, runWithTimeout(worker, 2, clientCallback)

module.exports.Worker = Worker
