title: FeathersJS authentication using client certificate
body: <p>I'm trying to create my own authentication strategy that reads the client's PKI certificate within a FeathersJS backend. This is handled in a <code>before</code> hook and based on the documentation hooks are</p>
  
  <blockquote>
    <p>A hook is transport independent, which means it does not matter if it has been called through HTTP(S) (REST), Socket.io, Primus or any other transport Feathers may support in the future. They are also service agnostic, meaning they can be used with ​any​ service regardless of whether they have a model or not.</p>
  </blockquote>
  
  <p>This is not a bad idea, however I need the TLS socket structure within the hook to get the user's certificate. Essentially calling: <code>req.socket.getPeerCertificate()</code>. I'm using the <code>passport-client-certificate</code> module and here's the strategy in question:</p>
  
  <pre><code>class ClientCertStrategy extends Strategy {
    constructor (options, verify) {
      if (typeof options === 'function') {
        verify = options
        options = {}
      }
      if (!verify) throw new Error('Client cert authentication strategy requires a verify function')
  
      super()
  
      this.name = 'client-cert'
      this._verify = verify
      this._passReqToCallback = options.passReqToCallback
    }
  
    _verified (err, user) {
      if (err) { return this.error(err) }
      if (!user) { return this.fail() }
      this.success(user)
    }
  
    authenticate (req, options) {
      // Requests must be authorized
      // (i.e. the certificate must be signed by at least one trusted CA)
      if (!req.socket.authorized) {
        this.fail()
        return
      }
  
      // This is where it fails! req.socket does not exist
      const clientCert = req.socket.getPeerCertificate()
  
      if (!clientCert) {
        this.fail()
        // TODO: Failure message
        // this.fail({message: options.badRequestMessage || 'Missing client     certificate'}, 400)
        return
      }
  
      try {
        if (this._passReqToCallback) {
          this._verify(req, clientCert, this._verified.bind(this))
        } else {
          this._verify(clientCert, this._verified.bind(this))
        }
      } catch (err) {
        return this.error(err)
      }
    }
  }
  </code></pre>
  
  <p>Based on the FeathersJS code, the <code>authenticate</code> function basically makes a new request object from the <code>hook</code>. Is there any way to get the user's certificate earlier and make it available later on when the hook is executed?</p>