Skip to content

Authentication

Meir Noordermeer edited this page Apr 28, 2017 · 5 revisions

Currently ap-npm has a simple implementation of a local auth-method. This was implemented just for testing purposes and although it works, it is not considered very safe and we recommend implementing your own. Using, for example, an API to verify users.

The authentication system in ap-npm has three methods:

userLogin

Takes in username, password and email and verifies user. Returns true or false to route.

userAdd

Takes in username, password and email and tries to create the user. Returns true or false to route.

Note: npm login is an alias for npm adduser. When implementing your own auth-methods, just let userAdd return false if you manage your users elsewhere.

userRemove

Takes in username and password and tries to remove the user. This has not been implemented yet in ap-npm. The function should work with the local auth-methods, but npm does not have a command to remove users from a registry. We might implement a route to allow this feature to be used outside of npm in the future, but for now it is not used yet.

Implementing your own

  • Create a new file with a class which implements the above mentioned methods.
  • In the config file point auth.adapter to your created auth class file.
  • Once you are done run npm install -g babel-cli babel-preset-es2015 babel-preset-stage-2 as we need to convert the auth file to pre-ES6.
  • Run babel- --presets es2015,stage-2 'your-auth-file.js' -d 'output-folder', this file will be usable by ap-npm.

If everything was implemented correctly your version of ap-npm should now use your own auth-methods.

Template

export default class {
  constructor(config) {
    this.settings = config.auth;
  }

  userLogin(username, password, email) {
  }

  userAdd(username, password, email) {
  }

  userRemove(username, password) {
  }
Clone this wiki locally