├── .gitignore ├── LICENCE ├── README.md ├── bin └── authmagic.js ├── index.js ├── package-lock.json └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Node 2 | node_modules 3 | npm-debug.log 4 | 5 | # IDE 6 | .idea 7 | 8 | # AuthMagic 9 | authmagic.json 10 | 11 | .DS_Store -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2018-present Oleksandr Knyga, oleksandrknyga@gmail.com 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | authmagic-cli 4 | ======================== 5 | CLI tool for authmagic - reusable, expandable authorization service which could be used for project initialization, core/plugins/theme installation.. 6 | 7 | Commands list 8 | ----------- 9 | ### init 10 | Creates an empty configuration file. 11 | 12 | #### Options: 13 | -e, --example - creates predefined example configuration file, so you could try authmagic quickly. 14 | 15 | ### install [name] [source] 16 | Installs module. Similar to npm install. If name wasn't provided it will install everything based on the configuration file. If no source provided would check the module via npm. 17 | 18 | #### Optional params: 19 | name - package name 20 | 21 | source - location of the package (git or filesystem) 22 | 23 | #### Options: 24 | -p, --plugin - Uninstall plugin 25 | 26 | -c, --core - Uninstall core 27 | 28 | -t, --theme - Uninstall theme 29 | 30 | ### uninstall [name] 31 | Uninstalls module. Similar to npm uninstall. 32 | 33 | #### Optional params: 34 | name - package name 35 | 36 | #### Options: 37 | -p, --plugin - Uninstall plugin 38 | -c, --core - Uninstall core 39 | -t, --theme - Uninstall theme 40 | 41 | ### clear 42 | Uninstalls all plugins and removes configuration file. 43 | 44 | 45 | Configuration file 46 | ----------- 47 | authmagic-cli allows to boot up authorization service with a command line. 48 | ``` 49 | module.exports = { 50 | "core": { 51 | "name": "authmagic-timerange-stateless-core", 52 | "source": "../authmagic-timerange-stateless-core" 53 | }, 54 | "plugins": { 55 | "authmagic-email-plugin": { 56 | "source": "../authmagic-email-plugin" 57 | } 58 | }, 59 | "params": { 60 | "authmagic-email-plugin": { 61 | "isTest": true, 62 | "mailer": { 63 | "auth": { 64 | "user": "", 65 | "pass": "" 66 | }, 67 | "host": "smtp.ethereal.email", 68 | "port": 587, 69 | "secure": false 70 | }, 71 | "from": "AuthMailer", 72 | "subject": "Your Magic Link" 73 | }, 74 | "authmagic-timerange-stateless-core": { 75 | "duration": 300, 76 | "key": "ad6de0e6c809b89b", 77 | "sendKeyPlugin": "authmagic-email-plugin", 78 | "expiresIn": 1200 79 | } 80 | }, 81 | "port": 3000, 82 | "theme": { 83 | "name": "authmagic-link-email-phone-bootstrap-theme", 84 | "source": "../authmagic-link-email-phone-bootstrap-theme" 85 | } 86 | }; 87 | ``` 88 | 89 | Licence 90 | ----------- 91 | authmagic-cli is [MIT licensed](./LICENSE). 92 | -------------------------------------------------------------------------------- /bin/authmagic.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 'use strict'; 3 | require('../index.js'); 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const path = require('path'); 3 | const crypto = require('crypto'); 4 | const program = require('commander'); 5 | const shell = require('shelljs'); 6 | const {ncp} = require('ncp'); 7 | const rimraf = require('rimraf'); 8 | const packageName = 'authmagic.js'; 9 | const authMagicEngine = 'authmagic'; 10 | 11 | const emptyDescription = { 12 | core: {}, 13 | plugins: {}, 14 | params: {}, 15 | port: 3000, 16 | }; 17 | 18 | const exampleDescription = Object.assign({}, emptyDescription, { 19 | core: {name: 'authmagic-timerange-stateless-core'}, 20 | theme: {name: 'authmagic-link-email-phone-bootstrap-theme'}, 21 | plugins: {'authmagic-email-plugin': {name: 'authmagic-email-plugin'}}, 22 | }); 23 | 24 | function startAuthmagic() { 25 | shell.exec('node ./node_modules/authmagic/app.js'); 26 | } 27 | 28 | function write(obj) { 29 | fs.writeFileSync('./'+packageName, 'module.exports = ' + JSON.stringify(obj, null, 2) + ';'); 30 | } 31 | 32 | function read() { 33 | if(!fs.existsSync('./'+packageName)) { 34 | return false; 35 | } 36 | 37 | try { 38 | return require(path.resolve('./'+packageName)); 39 | } catch(e) { 40 | return false; 41 | } 42 | } 43 | 44 | function init(content) { 45 | write(content); 46 | install(); 47 | shell.exec(`npm install ${authMagicEngine} --save`); 48 | } 49 | 50 | function createStaticIfDoestExist() { 51 | const dir = './static'; 52 | 53 | if (!fs.existsSync(dir)){ 54 | fs.mkdirSync(dir); 55 | } 56 | } 57 | 58 | function populateParams(packageName) { 59 | const config = read(); 60 | const file = `./node_modules/${packageName}/params.js`; 61 | if(config.params.hasOwnProperty(packageName)) { 62 | console.log(`params for ${packageName} are already defined`); 63 | return false; 64 | } 65 | 66 | if(!fs.existsSync(file)) { 67 | console.log(`no params were predefined for ${packageName}`); 68 | return false; 69 | } 70 | 71 | config.params[packageName] = require(path.resolve(file)); 72 | write(config); 73 | return true; 74 | } 75 | 76 | function populateStatic(packageName, cb, destination) { 77 | if(!destination) { 78 | destination = packageName; 79 | } 80 | 81 | if(!fs.existsSync(`./node_modules/${packageName}/static`)) { 82 | return false; 83 | } 84 | 85 | if(fs.existsSync(`./static/${destination}`)) { 86 | console.log(`static files for ${packageName} are already defined`); 87 | return false; 88 | } 89 | 90 | createStaticIfDoestExist(); 91 | ncp(`./node_modules/${packageName}/static`, `./static/${destination}`, cb); 92 | } 93 | 94 | function install() { 95 | const {plugins, core, theme} = read(); 96 | 97 | if(plugins) { 98 | for(let i=0, pluginNames = Object.keys(plugins); i rimraf('./static', () => console.log('clear operation finished'))); 236 | }); 237 | 238 | program 239 | .command('start') 240 | .action(startAuthmagic); 241 | 242 | if(process.argv.length < 3) { 243 | startAuthmagic(); 244 | } else { 245 | program.parse(process.argv); 246 | } -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "authmagic-cli", 3 | "version": "0.0.3", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "balanced-match": { 8 | "version": "1.0.0", 9 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 10 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" 11 | }, 12 | "brace-expansion": { 13 | "version": "1.1.11", 14 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", 15 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", 16 | "requires": { 17 | "balanced-match": "1.0.0", 18 | "concat-map": "0.0.1" 19 | } 20 | }, 21 | "commander": { 22 | "version": "2.16.0", 23 | "resolved": "https://registry.npmjs.org/commander/-/commander-2.16.0.tgz", 24 | "integrity": "sha512-sVXqklSaotK9at437sFlFpyOcJonxe0yST/AG9DkQKUdIE6IqGIMv4SfAQSKaJbSdVEJYItASCrBiVQHq1HQew==" 25 | }, 26 | "concat-map": { 27 | "version": "0.0.1", 28 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 29 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" 30 | }, 31 | "fs.realpath": { 32 | "version": "1.0.0", 33 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 34 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" 35 | }, 36 | "glob": { 37 | "version": "7.1.2", 38 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", 39 | "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", 40 | "requires": { 41 | "fs.realpath": "1.0.0", 42 | "inflight": "1.0.6", 43 | "inherits": "2.0.3", 44 | "minimatch": "3.0.4", 45 | "once": "1.4.0", 46 | "path-is-absolute": "1.0.1" 47 | } 48 | }, 49 | "inflight": { 50 | "version": "1.0.6", 51 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 52 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 53 | "requires": { 54 | "once": "1.4.0", 55 | "wrappy": "1.0.2" 56 | } 57 | }, 58 | "inherits": { 59 | "version": "2.0.3", 60 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 61 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 62 | }, 63 | "interpret": { 64 | "version": "1.1.0", 65 | "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.1.0.tgz", 66 | "integrity": "sha1-ftGxQQxqDg94z5XTuEQMY/eLhhQ=" 67 | }, 68 | "minimatch": { 69 | "version": "3.0.4", 70 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 71 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 72 | "requires": { 73 | "brace-expansion": "1.1.11" 74 | } 75 | }, 76 | "ncp": { 77 | "version": "2.0.0", 78 | "resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz", 79 | "integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=" 80 | }, 81 | "once": { 82 | "version": "1.4.0", 83 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 84 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 85 | "requires": { 86 | "wrappy": "1.0.2" 87 | } 88 | }, 89 | "path-is-absolute": { 90 | "version": "1.0.1", 91 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 92 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" 93 | }, 94 | "path-parse": { 95 | "version": "1.0.5", 96 | "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.5.tgz", 97 | "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=" 98 | }, 99 | "rechoir": { 100 | "version": "0.6.2", 101 | "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", 102 | "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", 103 | "requires": { 104 | "resolve": "1.8.1" 105 | } 106 | }, 107 | "resolve": { 108 | "version": "1.8.1", 109 | "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.8.1.tgz", 110 | "integrity": "sha512-AicPrAC7Qu1JxPCZ9ZgCZlY35QgFnNqc+0LtbRNxnVw4TXvjQ72wnuL9JQcEBgXkI9JM8MsT9kaQoHcpCRJOYA==", 111 | "requires": { 112 | "path-parse": "1.0.5" 113 | } 114 | }, 115 | "rimraf": { 116 | "version": "2.6.2", 117 | "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", 118 | "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", 119 | "requires": { 120 | "glob": "7.1.2" 121 | } 122 | }, 123 | "shelljs": { 124 | "version": "0.8.2", 125 | "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.2.tgz", 126 | "integrity": "sha512-pRXeNrCA2Wd9itwhvLp5LZQvPJ0wU6bcjaTMywHHGX5XWhVN2nzSu7WV0q+oUY7mGK3mgSkDDzP3MgjqdyIgbQ==", 127 | "requires": { 128 | "glob": "7.1.2", 129 | "interpret": "1.1.0", 130 | "rechoir": "0.6.2" 131 | } 132 | }, 133 | "wrappy": { 134 | "version": "1.0.2", 135 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 136 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" 137 | } 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "authmagic-cli", 3 | "version": "0.0.7", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "engines": { 10 | "node" : ">=8.10.0" 11 | }, 12 | "keywords": [ 13 | "auth", 14 | "authentication", 15 | "authorization", 16 | "openid", 17 | "oauth2" 18 | ], 19 | "author": "Oleksandr Knyga ", 20 | "license": "MIT", 21 | "dependencies": { 22 | "commander": "^2.15.1", 23 | "ncp": "^2.0.0", 24 | "rimraf": "^2.6.2", 25 | "shelljs": "^0.8.1" 26 | }, 27 | "bin": { 28 | "authmagic": "./bin/authmagic.js" 29 | } 30 | } 31 | --------------------------------------------------------------------------------