{"id":29178265,"url":"https://github.com/knfs-library/bamimi-auth","last_synced_at":"2025-07-01T18:33:00.926Z","repository":{"id":236874895,"uuid":"793328500","full_name":"knfs-library/bamimi-auth","owner":"knfs-library","description":"Auth for bamimi","archived":false,"fork":false,"pushed_at":"2025-05-17T07:22:52.000Z","size":177,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-19T16:47:11.706Z","etag":null,"topics":["authentication","bamimi","nodejs","nodejs-server"],"latest_commit_sha":null,"homepage":"https://knfs-library.github.io/bamimi-auth/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knfs-library.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-29T02:27:55.000Z","updated_at":"2025-05-17T07:22:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"456b7937-1d6d-4bd0-97dc-5b4b6bf84852","html_url":"https://github.com/knfs-library/bamimi-auth","commit_stats":null,"previous_names":["knfs-jsc/auth","knfs-library/bamimi-auth","knfs-jsc/bamimi-auth"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/knfs-library/bamimi-auth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knfs-library","download_url":"https://codeload.github.com/knfs-library/bamimi-auth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knfs-library%2Fbamimi-auth/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263017140,"owners_count":23400433,"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":["authentication","bamimi","nodejs","nodejs-server"],"created_at":"2025-07-01T18:31:12.118Z","updated_at":"2025-07-01T18:33:00.908Z","avatar_url":"https://github.com/knfs-library.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"250\" src=\"https://github.com/knfs-jsc/bamimi-auth/blob/master/docs/images/logo-background.png?raw=true\"\u003e\n  \u003cbr\u003e\n\t\u003ca href=\"https://app.fossa.com/api/projects/git%2Bgithub.com%2Fknfs-jsc%2Fbamimi-auth.svg?type=shield\u0026issueType=license\" alt=\"FOSSA Status\"\u003e\n\t\t\u003cimg src=\"https://app.fossa.com/api/projects/git%2Bgithub.com%2Fknfs-jsc%2Fbamimi-auth.svg?type=shield\u0026issueType=license\"/\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://app.fossa.com/api/projects/git%2Bgithub.com%2Fknfs-jsc%2Fbamimi-auth.svg?type=shield\u0026issueType=security\" alt=\"FOSSA Status\"\u003e\n\t\t\u003cimg src=\"https://app.fossa.com/api/projects/git%2Bgithub.com%2Fknfs-jsc%2Fbamimi-auth.svg?type=shield\u0026issueType=security\"/\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://scrutinizer-ci.com/g/knfs-jsc/bamimi-auth/badges/quality-score.png?b=master\"alt=\"scrutinizer\"\u003e\n\t\t\u003cimg src=\"https://scrutinizer-ci.com/g/knfs-jsc/bamimi-auth/badges/quality-score.png?b=master\" alt=\"Build Status\" /\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://scrutinizer-ci.com/g/knfs-jsc/bamimi-autoload/?branch=master\"alt=\"scrutinizer\"\u003e\n\t\t\u003cimg src=\"https://scrutinizer-ci.com/g/knfs-jsc/bamimi-autoload/badges/quality-score.png?b=master\" alt=\"Scrutinizer Code Quality\" /\u003e\n\t\u003c/a\u003e\n\t\u003ca href=\"https://github.com/knfs-jsc/bamimi-auth/actions/workflows/unit-test.yml\" alt=\"github\"\u003e\n\t\t\u003cimg src=\"https://github.com/knfs-jsc/bamimi-auth/actions/workflows/unit-test.yml/badge.svg\" alt=\"Github \" /\u003e\n\t\u003c/a\u003e\n\u003c/p\u003e\n\n\u003ch1\u003e \u003cspan style=\"color:#013C4D;\"\u003eAbout\u003c/span\u003e \u003cspan style=\"color:#2B7F84;\"\u003eBamimi auth\u003c/span\u003e\u003c/h1\u003e\n\n\nThis package was developed to make using auth types easier because:\n * Login, verify with password, password\n * Flexible use with Basic Auth\n* Powerful use with Token Auth (JWT)\n* Extended use, enhanced security with MFA (otp and qrcode)\n\n---\n\n## Install\n```bash\nnpm i @knfs-tech/bamimi-auth\n#or\nyarn add @knfs-tech/bamimi-auth\n```\n\n## Usage\n\n### Importing Modules\n\n```javascript\nconst { Auth } = require(\"@knfs-tech/bamimi-auth\");\n```\n\n#### Config file with type \n\n```javascript\nmodule.exports = {\n\taccessPassword: {\n\t\tidFields: ['username'], // fields id to verify, you can use with multiple ['username', 'email']\n\t\tpinField: ['password'] // field as password, you can use with other name field\n\t},\n\ttokenBasedToken: {\n\t\taccessToken: {\n\t\tsecretKey: \"\",\n\t\toptions: {}\n\t\t},\n\t\trefreshToken: {\n\t\t\tsecretKey: \"\",\n\t\t\toptions: {},\n\t\t\tmultiple: false, // if you want to multiple refresh token, in case multiple device\n\t\t\tuse: false // if you want to use refresh token\n\t\t},\n\t\tuseBlacklist: false, // if you want to black list to block token\n\t\t// storage for save refresh token (in case using multiple) and use black list\n\t\tstorage: {\n\t\t\t/**\n\t\t\t * @type {Enum(\"memory\", \"redis\")}\n\t\t\t */\n\t\t\ttype: \"memory\",\n\t\t\toptions: {} // if you redis, it is connection info of redis, In code we use ioredis\n\t\t},\n\t\t// fields of origin data to create token\n\t\tfields: [\n\t\t\t\"id\",\n\t\t\t\"username\",\n\t\t\t\"email\"\n\t\t]\n\t},\n\tmfa: {\n\t\tappName: \"@knfs-tech/bamimi-auth\",\n\t\tfieldId: \"id\" // id for uri auth and Qrcode\n\t}\n}\n```\nyou can check by \n```javascript\nconst { configType } = require(\"@knfs-tech/bamimi-auth\");\n```\n\n### Initializing the Authentication System\n\nTo initialize the authentication system, create an instance of the Auth class:\n\n```javascript\nconst auth = Auth.init();\n//or \nconst auth = Auth.init(config);\n```\n\n\n### Using Authentication Functionalities\n\nIf Auth have been initialized, you can use instance and other file by \n```javascript \nconst auth = Auth.getAuth();\n```\n\nNow, let's explore how to use different authentication functionalities provided by the system with a specific example:\n\n#### 1. Authenticating with Basic Auth\n\nSuppose you receive an HTTP request with Basic Authentication credentials in the Authorization header. You can authenticate the user with Basic Auth as follows:\n\n```javascript\nconst authorizationHeader = req.headers.authorization; // Get Authorization header from request\nconst userData = await getUserDataFromDatabase(); // Retrieve user data from your database\nconst isAuthenticated = await auth.verifyWithBasicAuth(userData, authorizationHeader);\n```\n\n#### 2. Generating Multi-Factor Authentication (MFA)\n\nSuppose you want to generate a QR code for MFA setup for a specific user. You can do it as follows:\n\n```javascript\nconst originalData = { id: \"user_id_here\" }; // User data for which MFA is to be set up\nconst qrCodeUrl = await auth.generateMFA(originalData, RETURN_TYPE.MFA.URL);\n```\n\n#### 3. Verifying Password and Generating JWT Tokens\n\nSuppose you want to verify a user's password and generate JWT tokens for authentication. You can do it as follows:\n\n```javascript\nconst originalData = { username: \"example_user\", password: \"example_password\" }; // User credentials\nconst comparisonData = { username: \"example_user\", password: \"hashed_password_here\" }; // User data from the database\nconst jwtTokens = await auth.verifyWithPassword(originalData, comparisonData, RETURN_TYPE.JWT.TOKEN);\n//or\nconst resultBasic = await auth.verifyWithPassword(originData, comparisonData) // return true or false\n```\n\n#### 4. Generating One-Time Password (OTP)\n\nSuppose you want to generate a one-time password for MFA verification. You can do it as follows:\n\n```javascript\nconst secretKey = \"user_secret_key_here\"; // Secret key for MFA\nconst oneTimePassword = await auth.generateOTP(secretKey);\n```\n\n## Author\n* [Kent Phungg](https://github.com/khapu2906)\n  \n## Owner\n* [Knfs.,jsc](https://github.com/knfs-jsc)\n\n## More\n* [Main](https://github.com/knfs-jsc/bamimi-auth/blob/master/docs/MAIN.md)\n* [Password based auth](https://github.com/knfs-jsc/bamimi-auth/blob/master/docs/PASSWORD_BASED.md)\n* [Basic auth](https://github.com/knfs-jsc/bamimi-auth/blob/master/docs/BASIC_AUTH.md)\n* [Token auth](https://github.com/knfs-jsc/bamimi-auth/blob/master/docs/TOKEN_BASE.md)\n* [MFA](https://github.com/knfs-jsc/bamimi-auth/blob/master/docs/MFA.md)\n  \n## License\n\nBamimi is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknfs-library%2Fbamimi-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknfs-library%2Fbamimi-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknfs-library%2Fbamimi-auth/lists"}