title: Authentication to Featherjs using socket.io-client
body: <p>How can I authenticate to Feathersjs (<a href="https://docs.feathersjs.com/api/client/socketio.html#authentication" rel="nofollow noreferrer">https://docs.feathersjs.com/api/client/socketio.html#authentication</a>) using Direct Connection (<a href="https://docs.feathersjs.com/api/client/socketio.html#direct-connection" rel="nofollow noreferrer">https://docs.feathersjs.com/api/client/socketio.html#direct-connection</a>)? The following code says that my accessToken is malformed, but I suspect there's more than that to get it working. Where do I fetch an accessToken?</p>
  
  <p>app.js (client):</p>
  
  <pre><code>import express from 'express';
  
  const socket = require('socket.io-client')('http://localhost:3030', {
    transports: ['websocket']
  });
  
  socket.emit('authenticate', { 
    strategy: 'jwt',
    accessToken: 'what to enter here'
  }, (message: any, data: any) =&gt; {
    console.log(message);
    console.log(data);
  });
  
  const app = express();
  
  app.get('/', (req, res) =&gt; res.send('Up and running!'));
  
  app.listen(4390, () =&gt; console.log('Example app listening on port 4390!'));
  </code></pre>
  
  <p>authentication.js (feathers server)</p>
  
  <pre><code>const authentication = require('@feathersjs/authentication');
  const jwt = require('@feathersjs/authentication-jwt');
  const local = require('@feathersjs/authentication-local');
  
  module.exports = function (app) {
    const config = app.get('authentication');
  
    // Set up authentication with the secret
    app.configure(authentication(config));
    app.configure(jwt());
    app.configure(local());
  
    app.service('authentication').hooks({
      before: {
        create: [
          authentication.hooks.authenticate(config.strategies),
        ],
        remove: [
          authentication.hooks.authenticate('jwt')
        ]
      }
    });
  };
  </code></pre>
  
  <p>I tried using the secret as an accessToken but it didnt work :)
  default.json (feathers server config)</p>
  
  <pre><code>"authentication": {
      "secret": "r323r32rada86700f18d82ea1d3e74fb58141dbefcd7460ef71736759265e347151a12d68dff50aa59c05e2f18db88661be8ae91a3f12932fddea8891b5ca9f63b5e4fc650edabc59d0d14e8fe4ea54256e7e386845321ab58a320a9ec99438bd058a3fbbda65dadf97bc9585ea82f72201f932beqwdqwdqwd5761a0d0be3e95474db5b9c8a3f4c7303beed0344a1768ba5dad6a1c916d183ea5dd923587768661ff0b08f25ed85dff4ff4e6b58327fe5914e5e7fb2356ee67754b102434f22686444a35fc38c75bcdd6386240a22e0cf62bdc7f227200868da387174b365af2afa7dec378c4ccf22956b134a3ec961fd1ba8d3dc85a7594ab711",
      "strategies": [
        "jwt",
        "local"
      ],
      "path": "/authentication",
      "service": "users",
      "jwt": {
        "header": {
          "typ": "access"
        },
        "audience": "https://yourdomain.com",
        "subject": "anonymous",
        "issuer": "feathers",
        "algorithm": "HS256",
        "expiresIn": "1d"
      },
      "local": {
        "entity": "user",
        "usernameField": "email",
        "passwordField": "password"
      }
    },
  ...
  </code></pre>
  
  <p>Thankful for all replies!</p>