https://github.com/bchanudet/verdaccio-mysql
Verdaccio MySQL plugin authentication
https://github.com/bchanudet/verdaccio-mysql
mysql node-js verdaccio verdaccio-plugin
Last synced: 3 months ago
JSON representation
Verdaccio MySQL plugin authentication
- Host: GitHub
- URL: https://github.com/bchanudet/verdaccio-mysql
- Owner: bchanudet
- License: mit
- Created: 2019-10-28T21:35:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-05-03T23:31:32.000Z (about 4 years ago)
- Last Synced: 2024-04-23T21:37:23.636Z (about 1 year ago)
- Topics: mysql, node-js, verdaccio, verdaccio-plugin
- Language: TypeScript
- Size: 12.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MySQL Authentication plugin for Verdaccio
This plugin allows you to use a MySQL database as the store for your user data. This is especially useful if you already one and you want to use it for Verdaccio as well.
## Install the plugin
### 1. Get the package with NPM
> npm install -g verdaccio-mysql
Current release version is v1.0.0
### 2. Add the plugin in your Verdaccio configuration
In your `config.yaml` file, look for the `auth` section. Add the following part right after, replacing the string `YOUR_[...]` with your values.
`connection` is a [mysql.Connection](https://github.com/mysqljs/mysql#connection-options) object, have a look there if you need more options.
```yaml
auth:
mysql:
connection:
host: "YOUR_SERVER_IP"
port: 3306
user: "YOUR_MYSQL_USER"
password: "YOUR_MYSQL_PASSWORD"
database: "YOUR_DATABASE"
queries:
auth_user: 'SELECT QUERY'
add_user: 'INSERT QUERY'
update_user: 'UPDATE QUERY'
```### 3. Specify custom queries to match your database schema.
Similarly as prepared queries, and according to [mysql documentation](https://github.com/mysqljs/mysql#escaping-query-values), the parameters for each query must be declared in the query with `?` as placeholders.
#### `auth_user`: Authentication query
This is the query that will be ran for each authentication tentative.
This query has two parameters in this exact order:
1. The username provided by the user
2. The password givenIf the authentication is successful, the query must return one row with two columns:
- `username`: Username of the user.
- `usergroups`: comma-separated list of all user's groups.If not successful, the query must return an empty recordset.
#### `add_user`: New user query
This query allows users to create a new record in the MySQL database.
This query has two parameters in this exact order:
1. The username for the new user
2. The password givenDeclare `add_user` as an empty string to forbid anyone to create a new user in the database from Verdaccio or the npm CLI.
#### `update_user`: Update user password
This query allows users to change their password with Verdaccio.
This query has three parameters in this exact order:
1. The new password for the user
2. The username
3. The original passwordDeclare `update_user` as an empty string to forbid anyone to update their password from Verdaccio or the npm CLI.
## See an example of the configuration
Have a look inside the [example](example/) folder to find an example of the configuration on a simple server:
- [mysql-database.sql](example/mysql-database.sql) contains queries to setup a really simple database with 3 tables: `users`, `groups` and `user_group`
- [mysql-config.yaml](example/mysql-config.yaml) describes the configuration to put into `config.yaml` to work with the schema described in the SQL file.## Development / Building
This plugin is a regular TypeScript project.
### Get the sources
$ git clone https://github.com/bchanudet/verdaccio-mysql.git
$ npm install### Build the plugin and link it globally
For plugins, Verdaccio only looks for packages installed in its directory, or globally installed.
$ npm link
This command wil build verdaccio-mysql, and add a symbolic link to the new version in the global repository of npm. This way it can be used with your local version of Verdaccio.
## Found a bug?
[Create a new issue](https://github.com/bchanudet/verdaccio-mysql/issues/new), I'll do my best to answer and fix the problem!