{"id":28446932,"url":"https://github.com/os-js/osjs-database-auth","last_synced_at":"2025-06-30T06:32:23.309Z","repository":{"id":55552180,"uuid":"144473467","full_name":"os-js/osjs-database-auth","owner":"os-js","description":"OS.js Database Auth Adapter","archived":false,"fork":false,"pushed_at":"2022-08-09T22:52:46.000Z","size":20,"stargazers_count":3,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-20T16:52:36.093Z","etag":null,"topics":["osjs","osjs-adapter"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/os-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"andersevenrud","patreon":"andersevenrud","open_collective":"osjs","liberapay":"os-js","custom":"https://paypal.me/andersevenrud"}},"created_at":"2018-08-12T14:27:20.000Z","updated_at":"2023-03-22T15:13:57.000Z","dependencies_parsed_at":"2022-08-15T03:01:07.085Z","dependency_job_id":null,"html_url":"https://github.com/os-js/osjs-database-auth","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/os-js/osjs-database-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os-js%2Fosjs-database-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os-js%2Fosjs-database-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os-js%2Fosjs-database-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os-js%2Fosjs-database-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/os-js","download_url":"https://codeload.github.com/os-js/osjs-database-auth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/os-js%2Fosjs-database-auth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262723686,"owners_count":23354087,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["osjs","osjs-adapter"],"created_at":"2025-06-06T11:08:51.391Z","updated_at":"2025-06-30T06:32:23.294Z","avatar_url":"https://github.com/os-js.png","language":"JavaScript","funding_links":["https://github.com/sponsors/andersevenrud","https://patreon.com/andersevenrud","https://opencollective.com/osjs","https://liberapay.com/os-js","https://paypal.me/andersevenrud","https://www.patreon.com/user?u=2978551\u0026ty=h\u0026u=2978551","https://liberapay.com/os-js/"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg alt=\"OS.js Logo\" src=\"https://raw.githubusercontent.com/os-js/gfx/master/logo-big.png\" /\u003e\n\u003c/p\u003e\n\n[OS.js](https://www.os-js.org/) is an [open-source](https://raw.githubusercontent.com/os-js/OS.js/master/LICENSE) web desktop platform with a window manager, application APIs, GUI toolkit, filesystem abstractions and much more.\n\n[![Support](https://img.shields.io/badge/patreon-support-orange.svg)](https://www.patreon.com/user?u=2978551\u0026ty=h\u0026u=2978551)\n[![Support](https://img.shields.io/badge/opencollective-donate-red.svg)](https://opencollective.com/osjs)\n[![Donate](https://img.shields.io/badge/liberapay-donate-yellowgreen.svg)](https://liberapay.com/os-js/)\n[![Donate](https://img.shields.io/badge/paypal-donate-yellow.svg)](https://paypal.me/andersevenrud)\n[![Community](https://img.shields.io/badge/join-community-green.svg)](https://community.os-js.org/)\n\n# OS.js v3 Database Auth Adapter\n\nThis is the Database Auth Adapter for OS.js v3. Built on [TypeORM](http://typeorm.io/).\n\nTo set this up, you need to do the following steps:\n\n1. Set up your database\n2. Install\n3. Configure Server\n4. Configure Client\n5. Configure CLI\n6. Manage Users\n\nPlease see the [OS.js Authentication Guide](https://manual.os-js.org/guide/auth/) for general information.\n\n**You can find a complete example using docker on [github](https://github.com/andersevenrud/osjsv3-db-auth-example)**\n\n## Set up your database\n\nBefore you begin you need to chose a database and set this up on your host system.\n\nThis documentation uses **mysql** by default, but you can use [any SQL flavor](#notes) that TypeORM supports.\n\nThe database and credentials you set up in this step has to be reflected in the configurations below.\n\nAssuming you have installed mysql (refer to you operating system documentation) and logged into the server:\n\n```bash\n# Create a new database called \"osjsv3\"\nmysql\u003e CREATE DATABASE osjsv3;\n\n# Creates a new used called \"osjsv3\" with password \"secret\"\nmysql\u003e CREATE USER 'osjsv3'@'localhost' IDENTIFIED BY 'secret';\n\n# Give permission for the user to access the database\nmysql\u003e GRANT ALL ON osjsv3.* TO 'osjsv3'@'localhost';\n```\n\n\u003e *Note that the mysql users are not related to OS.js users.*\n\n\u003c!-- --\u003e\n\n\u003e If you've already installed `@osjs/database-settings` module you can skip this step and use the same database and credentials.\n\n## Installation\n\nInstall the required OS.js module and database driver:\n\n```bash\nnpm install --save --production @osjs/database-auth\nnpm install --save mysql\n```\n\n### Configure Server\n\nTo connect the server with the database authentication module, you'll have to modify your Server bootstrap script.\n\nIn your **`src/server/index.js`** file:\n\n```javascript\n// In the top of the file load the library\nconst dbAuth = require('@osjs/database-auth');\n\n// Locate this line in the file and add the following:\nosjs.register(AuthServiceProvider, {\n  args: {\n    adapter: dbAuth.adapter,\n    config: {\n      connection: {\n        // Change this to match your local database server\n        type: 'mysql',\n        host: 'localhost',\n        username: 'osjsv3',\n        password: 'secret',\n        database: 'osjsv3',\n\n        // See TypeORM documentation for more settings\n      }\n    }\n  }\n});\n```\n\n\u003e **NOTE:** You have to restart the server after making these changes.\n\n### Configure Client\n\nBy default OS.js is set up to log in with the `demo / demo` user for demonstration purposes.\n\nIn your **`src/client/config.js`** file:\n\n```javascript\nmodule.exports = {\n  public: '/',\n\n  // Either comment out this section, or remove it entirely\n  /*\n  auth: {\n    login: {\n      username: 'demo',\n      password: 'demo'\n    }\n  }\n  */\n};\n```\n\n\u003e **NOTE:** You have to rebuild using `npm run build` after making these changes.\n\n### Configure CLI\n\nTo get CLI commands to manage users, you'll have to modify your CLI bootstrap script.\n\nIn your **`src/cli/index.js`** file:\n\n```javascript\n// In the top of the file load the library\nconst dbAuth = require('@osjs/database-auth');\n\n// Create a database authentication instance\nconst dbCli = dbAuth.cli({\n  // Change this to match your local database server\n  type: 'mysql',\n  host: 'localhost',\n  username: 'osjsv3',\n  password: 'secret',\n  database: 'osjsv3',\n\n  // See TypeORM documentation for more settings\n});\n\n// Then finally add 'dbCli' to the tasks array\nmodule.exports = {\n  discover: [],\n  tasks: [dbCli]\n};\n```\n\n### Manage Users\n\nYou can now manage users with ex. `npx osjs-cli \u003ctask\u003e`\n\n\u003e The `npx` command comes with npm 5.2 or later, but if you for some reason don't have this you can [install it manually](https://www.npmjs.com/package/npx).\n\u003e Or alternatively use `node node_modules/.bin/osjs-cli \u003ctask\u003e`\n\n#### Available tasks:\n\n* `user:list` - Lists users\n* `user:add --username=STR` - Adds user (as admin)\n* `user:add --username=STR --groups=GROUP1,GROUP2` - Adds user with groups\n* `user:pwd --username=STR` - Changes user password\n* `user:remove --username=STR` - Removes user\n\nExample: `npx osjs-cli user:add --username=anders`.\n\n## Notes\n\nIf you want to use **sqlite** run `npm install sqlite3` and change the connection options to:\n\n```javascript\n{\n  connection: {\n    type: 'sqlite',\n    database: 'path/to/database.sql'\n  }\n}\n```\n\nFor more information about configuration: https://typeorm.io/\n\nIf you don't want to repeat the connection information over multiple files, for example create `src/database-connection.js` with the contents:\n\n```javascript\nmodule.exports = {\n  type: 'mysql',\n  host: 'localhost',\n  username: 'osjsv3',\n  password: 'secret',\n  database: 'osjsv3',\n}\n```\n\nand then in your scripts:\n\n```javascript\n{\n  connection: require('../database-connection.js')\n}\n```\n\n## Contribution\n\n* **Sponsor on [Github](https://github.com/sponsors/andersevenrud)**\n* **Become a [Patreon](https://www.patreon.com/user?u=2978551\u0026ty=h\u0026u=2978551)**\n* **Support on [Open Collective](https://opencollective.com/osjs)**\n* [Contribution Guide](https://github.com/os-js/OS.js/blob/master/CONTRIBUTING.md)\n\n## Documentation\n\nSee the [Official Manuals](https://manual.os-js.org/) for articles, tutorials and guides.\n\n## Links\n\n* [Official Chat](https://gitter.im/os-js/OS.js)\n* [Community Forums and Announcements](https://community.os-js.org/)\n* [Homepage](https://os-js.org/)\n* [Twitter](https://twitter.com/osjsorg) ([author](https://twitter.com/andersevenrud))\n* [Google+](https://plus.google.com/b/113399210633478618934/113399210633478618934)\n* [Facebook](https://www.facebook.com/os.js.org)\n* [Docker Hub](https://hub.docker.com/u/osjs/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fos-js%2Fosjs-database-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fos-js%2Fosjs-database-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fos-js%2Fosjs-database-auth/lists"}