{"_id":"@aytacworld/express-module-oauth-server","_rev":"1-f455695914e7c7b3cc58077191115edc","name":"@aytacworld/express-module-oauth-server","dist-tags":{"latest":"4.0.0"},"versions":{"4.0.0":{"name":"@aytacworld/express-module-oauth-server","version":"4.0.0","description":"Adding oauth server capability for @aytacworld/express","main":"index.js","repository":{"type":"git","url":"https://git.aytacworld.com/aytacworld/express"},"author":{"name":"Adem Aytaç","email":"adem@aytacworld.com","url":"https://aytacworld.com"},"license":"MIT","dependencies":{"express":"^4.17.0"},"_id":"@aytacworld/express-module-oauth-server@4.0.0","_npmVersion":"6.4.1","_nodeVersion":"10.15.3","_npmUser":{"name":"aytacworld","email":"adem@aytacworld.com"},"dist":{"integrity":"sha512-FbVgsSN/sKB22I99yd+dqR6PSkHPlSptpZWhCQMtoSz7glBI5xITlRCkD165F8hSE+gCZG4+GvoAy6VZUh/u/g==","shasum":"6e8cbb4b9b23075680202602e61d975e5b5df166","tarball":"https://registry.npmjs.org/@aytacworld/express-module-oauth-server/-/express-module-oauth-server-4.0.0.tgz","fileCount":4,"unpackedSize":11767,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJc4tdZCRA9TVsSAnZWagAAKzoP/Apqgkn2SK5JGGYeUJLp\nux6CnI736L9AvQ1wFn6SfukpAVWAgQuoIf8ZRioY0ySJ5HBbhXzqbZQxyzgQ\nOmBlFej0ozJ5vVVUz/YjuY94/XMvU5lu0fr2/eyWulfMnAj6eZBTW0PbM+PK\n2/uU1xmhc50p2bC6eiZ6pOZfFlJ8IJxwNfdJKNbEJwQHgc96Ym2hoo8/eHWE\nJJcbtgUB/WhDmOwrkwl0kgs/vZoJmBZeH9dtDUG/twIRE9fCOscYQjvFUOw2\n+9fvUdQLqYmoRKznb+cs2Ac1eQqaTPdEleMtQB6WgnTdIZUyPKGJap/yJvXl\nxhk2hw9Xv+1KD+mcCn61r0pOs/rglYSkJrczSJaLFjM2+o+FGsuLZNn8xRvI\nVF2JgbnonQ4tLE0MgtHTJ3KVm0E2p4eJpgEBwkV7W4nbfJi774KB073b1LRA\nNGF0c3Z9VSGljfIR1zoMNnEqKvsCwKdhStV/9krH+VT8vowpDHUX/jWOKQY4\nT2iL5ZY3auiMeJFncJ60LfryYaPUf2dPCA/WLoPT9i+y2DoqmpDaX0q+Zuv6\nvCepXukxs42R4WhV3ipcGIbuSXxjb4ZmftH59Rmb8kwDK+ThIYAUfTZsxYx9\n9stawVFvjjust/kG1nX75hygf5vRJl7CZjXYrY1ujwWYK8wtkFUs2Po9CYcO\n+i70\r\n=/LKo\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIBxRzBJay36Dd+upyOJAtaT3T2rE1pdjreKGc03PmKw6AiB+9bA+Nh5Fwuh4gDdeujCY2ebX2PE3efwFWF7b/dPSsw=="}]},"maintainers":[{"name":"aytacworld","email":"adem@aytacworld.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/express-module-oauth-server_4.0.0_1558370136810_0.04577154573552855"},"_hasShrinkwrap":false}},"time":{"created":"2019-05-20T16:35:36.768Z","4.0.0":"2019-05-20T16:35:36.903Z","modified":"2022-04-04T17:15:02.910Z"},"maintainers":[{"name":"aytacworld","email":"adem@aytacworld.com"}],"description":"Adding oauth server capability for @aytacworld/express","repository":{"type":"git","url":"https://git.aytacworld.com/aytacworld/express"},"author":{"name":"Adem Aytaç","email":"adem@aytacworld.com","url":"https://aytacworld.com"},"license":"MIT","readme":"# @aytacworld/express-module-oauth-server\n\nThis module is ment to be used with @aytacworld/express.\n\nIt will add oauth server capabilities.\n\n## Needed modules\n\nFor this module you need 1.authDb module to be loaded before loading this module.\n\nThe needed modules needs to be loaded before loading oauth module.\n\n1. There are already 2 modules for authDb module.\n\n    - [@aytacworld/express-module-memory](https://www.npmjs.com/package/@aytacworld/express-module-memory) uses in-memory database\n    - [@aytacworld/express-module-mongo](https://www.npmjs.com/package/@aytacworld/express-module-mongo) uses mongodb\n\n2. Or you can create it yourself\n\n## Installation\n\nusing npm\n\n`npm i @aytacworld/express-module-oauth-server`\n\nusing yarn\n\n`yarn add @aytacworld/express-module-oauth-server`\n\n## Usage\n\napp.js\n```javascript\nconst Express = require('@aytacworld/express');\nconst ExpressMongo = require('@aytacworld/express-module-mongo');\nconst ExpressOauthServer = require('@aytacworld/express-module-oauth-server');\n\nconst app = new Express({});\n\napp.module(ExpressMongo, ExpressOauthServer);\n\napp.listen();\n```\n\n## Config\n\n```json\n{\n  \"EXPRESS_MODULE_OAUTH_SERVER_DISABLE_VIEW\": true, // Boolean, default: undefined, this will don't add default pug files in your project, so you need to create your own login page\n  \"EXPRESS_MODULE_OAUTH_SERVER_DECISION_VIEW\": \"my-custom-login-view\", // String, default: 'aytacworld-express-module-oauth-server-decision'\n  \"EXPRESS_MODULE_OAUTH_SERVER_CSS\": \"/public/oauth.css\", // String, default: undefined\n  \"EXPRESS_MODULE_OAUTH_SERVER_TOKEN_LENGTH\": 345, // Number, default: 256\n  \"EXPRESS_MODULE_OAUTH_SERVER_EXPIRE_DEFAULT\": 3600, // Number, default: 1800\n}\n```\n\n## Updating decision dialog page\n\ndialog.pug\n```pug\np.module-oauth-server-p.module-oauth-server-p-username #{username}\np.module-oauth-server-p.module-oauth-server-p-client #{client} is requesting access to your account\np.module-oauth-server-p.module-oauth-server-p-question Do you approve?\n\nform(action='/oauth/decision' method='POST').module-oauth-server-form\n  input(name='transaction_id' type='hidden' value=`${transactionId}`)\n  input(type='submit' value=\"Allow\" id=\"allow\").module-oauth-server-input.module-oauth-server-input-allow\n  input(type='submit' value=\"Deny\" id=\"deny\" name='cancel').module-oauth-server-input.module-oauth-server-input-deny\n```\n\n## Database structure\n\n```javascript\n{\n  users: {\n    static comparePassword(username, password): Promise<user|false>;\n  },\n  clients: {\n    static findById(id): Promise<client>;\n    static findByClientId(clientId): Promise<client>;\n    static compareSecret(username, secret): Promise<client|false>;\n  },\n  tokens: {\n    static find(key): Promise<token>;\n    static findByUserIdAndClientId(userId, clientId): Promise<token>;\n    static findByTransactionId(transactionId): Promise<token>;\n    static saveCode(authCode, userId, clientId, redirectUri, state, transactionId): Promise<void>;\n    static exchangeAuthCodeForAccessToken(authCode, accessToken, refreshToken, expiresIn): Promise<void>;\n    static refreshAccessToken(refreshToken, accessToken, expiresIn): Promise<void>;\n  }\n}\n```\n\nUser model\n```typescript\nclass User {\n  id: any;\n  username: string;\n  password: string;\n}\n```\n\n_INFO: don't forget to hash the password before saving in database!_\n\nClient model\n```typescript\nclass Client {\n  name: string;\n  clientId: string;\n  clientSecret: string;\n  redirectUrl: string;\n}\n```\n\nToken model\n```typescript\nclass Token {\n  token: string;\n  userId: string;\n  clientId: string;\n  redirectUri: string;\n\n  refreshToken: string;\n  expiresIn: number;\n\n  authCode: string;\n  state: string;\n  transactionId: string;\n  codeChallenge: string;\n}\n```\n\n## MIT License\n\nCopyright (c) 2019 Adem Aytaç\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","readmeFilename":"README.md"}