Authentication in Feathers JS without the need for email addresses

Currently, I am in need of an authentication system for my dApp that operates without using email addresses or storing any user information. What I require is an endpoint where users can submit a seed phrase and password to generate a JWT. The process should involve calculating a value based on the provided inputs, and if successful (which it usually will be unless invalid data is sent), issue a JWT. However, the default functionality with Feathers CLI seems to require local strategy and an email address, which does not align with my requirements. I have been unable to find any demos or examples to guide me through this specific setup. Any suggestions or pointers on how to achieve this would be greatly appreciated as my current authentication setup is quite basic.

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());

  // The `authentication` service is used to create a JWT.
  // The before `create` hook registers strategies that can be used
  // to create a new valid JWT (e.g. local or oauth2)
  app.service('authentication').hooks({
    before: {
      create: [
        authentication.hooks.authenticate(config.strategies)
      ],
      remove: [
        authentication.hooks.authenticate('jwt')
      ]
    }
  });
};

Below is the code snippet for my service:

// Initializes the `aerAuth` service on path `/userauthendpoint`
const createService = require('feathers-memory');
const hooks = require('./userauthendpoint.hooks');

module.exports = function (app) {

  const paginate = app.get('paginate');

  const options = {
    name: 'userauthendpoint',
    paginate
  };

  // Initialize our service with any options it requires
  app.use('/userauthendpoint', createService(options) );

  // Get our initialized service so that we can register hooks and filters
  const service = app.service('userauthendpoint');

  service.hooks(hooks);
};

Although I am relatively new to Feathers, I do have experience building authentication systems, particularly in PHP.

Answer №1

If you are searching for a way to implement custom authentication strategies, the Custom authentication strategy guide along with the feathers-authentication-custom plugin might meet your requirements.

The implementation can vary based on your preferences. You have the option of using the custom strategy for individual services (like requiring an API key in the request header) or just before the /authentication service for creating a JWT token (bearing in mind that it requires a valid userId or entityId which must exist in the database).

One simple approach is to opt for the former and utilize a custom header (X-DAP-PASSWORD) as demonstrated below:

const custom = require('feathers-authentication-custom');

app.configure(authentication(settings));
app.configure(custom((req, done) => {
  const password = req.headers['x-dap-password'];

  if(checkPassword(req.app.get('seedPassphrase'), password)) {
    // Here, you can add your own logic to load and verify the user
      done(null, user);
  } else {
    done(new Error('Invalid passphrase'));
  }
}));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Switch up a font style using JavaScript to apply a Google font effect

I am attempting to implement a discreet hidden button on a website that triggers a unique Google font effect for all of the h1 elements displayed on the page. However, I am uncertain about the process and unsure if it is achievable. Below is the code snipp ...

What is the best way to split an input field into distinct fields for display on the screen?

Take a look at this image: https://i.stack.imgur.com/LoVqe.png I am interested in creating a design similar to the one shown in the image, where a 4 digit one-time password (OTP) is entered by the user. Currently, I have achieved this by using 4 separate ...

Filtering dynamically generated table rows using Jquery

I'm currently working on a project that involves filtering a dynamic table based on user input in a search bar. The table contains information such as name, surname, phone, and address of users. Using jQuery, I have created a form that dynamically ad ...

Animating a Bootstrap 4 card to the center of the screen

I am attempting to achieve the following effect: Display a grid of bootstrap 4 cards Upon clicking a button within a card, animate it by rotating 180 degrees, adjusting its height/width from 400px - 350px to the entire screen, and positioning it at the c ...

Storing Previous Commands in NodeJS ssh2

In my current project, I am utilizing the ssh2 library in conjunction with express js. The flow involves the client sending a POST request to the express api, which triggers the creation of a file. Subsequently, ssh2 is used to transfer the file from one d ...

Interactive loading of datalist choices using AJAX in the Firefox browser

I have recently decided to replace the Jquery UI autocomplete function on my website with HTML5 datalists that load dynamic options. After researching this topic extensively, I came across various answers on Stack Overflow, such as How do you refresh an HT ...

Incorporate a button within a listview on Kendoui to trigger the opening of a modal window

I am seeking assistance on how to insert a button on each element of a Listview (PHP/Json) result. When clicked, this button should open a modal window where the customer can input reservation details such as Date, Adults, and Children. Below is the JavaSc ...

The global variable remains unchanged after the Ajax request is made

I am attempting to utilize AJAX in JavaScript to retrieve two values, use them for calculations globally, and then display the final result. Below are my code snippets. // My calculation functions will be implemented here var value1 = 0; var v ...

Tips for obtaining a legitimate SSL certificate for a NodeJS Express API deployed on a Windows virtual machine within a VPS server

I'm in the process of setting up a Web API using NodeJS and need to enable HTTPS support. Can anyone recommend where I can obtain a legitimate SSL certificate for this purpose? Currently, my Windows VM is running on a specific IP address, hosting a N ...

Create an Ajax request function to execute a PHP function, for those just starting out

I came across a JS-Jquery file that almost meets my needs. It currently calls a PHP function when a checkbox is clicked, and now I want to add another checkbox that will call a different PHP function. My initial attempt was to copy the existing function a ...

The specified file for import cannot be located or is unable to be read: node_modules/bootstrap/scss/functions

I am currently using core UI version 2.1.1 along with react. Upon attempting to execute npm start, I encountered the following error: (/Users/umairsaleem/Desktop/abc/abc/node_modules/css-loader??ref--6-oneOf-5-1!/Users/umairsaleem/Desktop/abc/abc/node_mo ...

Challenge with Express.js and Mongoose Query

I am facing an issue with querying my MongoDB for a single document using _id. I am working with Mongoose version 4.11.1. The problem arises when I try to run the query by passing the _id as a URL parameter on the route localhost:3000/poi/one/595ef9c8c4891 ...

Challenges in Implementing Animated Counters on Mobile Platforms

My website is experiencing a strange issue with an animated counter. The counter works fine on desktop browsers, but when viewed on mobile devices in a live setting, it seems to have trouble parsing or converting numbers above 999. This results in the init ...

Encountering an issue with a class component stating that "this.setState is not a function

I am currently learning React JS and encountered an error when calling my first API in React. I keep getting the message "Unhandled Rejection (TypeError): this.setState is not a function." I have been trying to troubleshoot this issue on my own but haven ...

Is there a way to identify the specific button that was clicked within an Angular Material dialog?

import {Component, Inject} from '@angular/core'; import {MdDialog, MdDialogRef, MD_DIALOG_DATA} from '@angular/material'; /** * @title Dialog Overview Example with Angular Material */ @Component({ selector: 'dialog-overview-ex ...

javascript: window.open()

I am currently using VB.NET 2005 and I have a requirement to launch a new browser window using Process.Start(). The challenge is that I need to specify the size of the browser window, for example, height:300 and width:500. Process.Start("firefox.exe", "ab ...

Error encountered when attempting to delete a file with unlink due to the EBUSY condition

Describing a delete route that removes an image file, the following code is provided: router.delete('/:id', (req, res) => { let pathForThumb = ''; let pathForImage = ''; Image.findOne({ _id: req.params.id }) ...

Adding a QR code on top of an image in a PDF using TypeScript

Incorporating TypeScript and PdfMakeWrapper library, I am creating PDFs on a website integrated with svg images and QR codes. Below is a snippet of the code in question: async generatePDF(ID_PRODUCT: string) { PdfMakeWrapper.setFonts(pdfFonts); ...

What is the most effective approach for addressing errors in both the server and client sides while utilizing nodejs and express?

Seeking the most effective approach for handling errors in a response - request scenario. Here is an example of a route that receives a request: app.get('/getInfo', function (req, res, next) { let obj = {} try { obj = { ...

Changing font color of a selected item in Material-UI's textview

I have a select textview in my react app and I am wondering how to change the font color after selecting an item from this textview. <div> <TextField id="standard-select-currency" select fullWidth l ...