{"id":18347719,"url":"https://github.com/ghivert/authentication","last_synced_at":"2025-04-09T23:26:08.437Z","repository":{"id":42523452,"uuid":"242569970","full_name":"ghivert/authentication","owner":"ghivert","description":"Authentication service for your micro-service architecture.","archived":false,"fork":false,"pushed_at":"2023-03-03T11:25:31.000Z","size":528,"stargazers_count":1,"open_issues_count":6,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-15T14:47:58.161Z","etag":null,"topics":["authentication","french-pastries","microservice"],"latest_commit_sha":null,"homepage":"","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/ghivert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-23T18:35:19.000Z","updated_at":"2022-02-01T23:07:04.000Z","dependencies_parsed_at":"2024-12-23T19:13:08.047Z","dependency_job_id":"4dbcede7-128e-41cb-a019-21e8c7d80c21","html_url":"https://github.com/ghivert/authentication","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghivert%2Fauthentication","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghivert%2Fauthentication/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghivert%2Fauthentication/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ghivert%2Fauthentication/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ghivert","download_url":"https://codeload.github.com/ghivert/authentication/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248127862,"owners_count":21052303,"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","french-pastries","microservice"],"created_at":"2024-11-05T21:14:44.809Z","updated_at":"2025-04-09T23:26:08.417Z","avatar_url":"https://github.com/ghivert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Authentication\n\nAuthentication provides an easy to install, easy to use authentication micro-service. While still being in development, it allows to sign up, sign in, and log in and out user right now. Of course more features are planned and on the roadmap.\n\nThis project is born on an idea and major participations of [arthurescriou](https://github.com/arthurescriou). This project would not live without him. Take a look at what he’s doing. I mainly mirrored his code.\n\n## Roadmap\n\n- [x] Reset Password\n- [ ] Delete user account\n- [ ] OAuth2\n- [ ] Back Office built-in\n\n## How it works?\n\nIt automatically connects to your [Bakery](https://github.com/FrenchPastries/Bakery) in order to provide its service and communicate with the outside world.\n\n## Getting Started\n\n```bash\nyarn add @ghivert/authentication\n```\n\nTo get it running, you need some parameters in your environment. You can use a `.env` at your root launch, the Authentication will automatically read it.\n\nIn the environment you need many variables.\n\n- `RSA_PRIVATE_KEY` An RSA private key.\n- `RSA_PUBLIC_KEY` The corresponding RSA public key.\n- `PORT` The port on which the server is running.\n- `HOSTNAME` The hostname on which the Authentication is running.\n- `REGISTRY_HOST` The host on which the Bakery is running.\n- `REGISTRY_PORT` The port on which the Bakery is running.\n- `DATABASE_URL` The PostgreSQL database URI.\n- `ORIGIN` The address from where you’re communicating.\n- `AES_KEY` The AES key for crypting.\n- `AES_IV` The AES param.\n- `SENDGRID_API_KEY` Your sendgrid API key.\n\nThen you can install the Authentication:\n\n```bash\nyarn add @frenchpastries/authentication\n```\n\nAnd start it right away!\n\n```javascript\nconst Authentication = require('@frenchpastries/authentication')\n\nAuthentication.start()\n```\n\nTo call it from your application:\n\n### Sign In\n\n```javascript\nconst mySignInHandler = request =\u003e {\n  const { username, password } = request.body\n  const response = await request.services.authentication.signIn().post({\n    body: JSON.stringify({\n      username,\n      password,\n    }),\n  })\n  const token = await response.text()\n  // Here is the resulting token.\n}\n```\n\n### Sign Up\n\n```javascript\nconst mySignUpHandler = request =\u003e {\n  const { username, password } = request.body\n  const response = await request.services.authentication.signUp().post({\n    body: JSON.stringify({\n      username,\n      password,\n    }),\n  })\n  const token = await response.text()\n  // Here is the resulting token.\n}\n```\n\n### Check token\n\n```javascript\nconst myCheckTokenHandler = request =\u003e {\n  const { token } = request.headers.Authorize\n  const response = await request.services.authentication\n    .checkToken()\n    .post({ body: JSON.stringify({ token }) })\n  const userId = await response.text()\n  // Here is the resulting user UUID.\n}\n```\n\n### Delete session\n\n```javascript\nconst mySignOutHandler = request =\u003e {\n  const { token } = request.headers.Authorize\n  const response = await request.services.authentication\n    .signOut()\n    .delete({ body: JSON.stringify({ token }) })\n  const ok = await response.text()\n  // assert(ok === 'OK')\n}\n```\n\n### Reset password link\n\n```javascript\nconst myResetPasswordHandler = ({ body }) =\u003e {\n  const response = await request.services.authentication\n    .sendMailReset()\n    .post({ body })\n  const ok = await response.text()\n  // assert(ok === 'OK')\n}\n```\n\n### Change password\n\n```javascript\nconst myChangePasswordHandler = ({ body }) =\u003e {\n  const response = await request.services.authentication\n    .resetPassword()\n    .post({ body })\n  const ok = await response.text()\n  // assert(ok === 'OK')\n}\n```\n\n## Full API\n\nThe API is RESTful. All requests should contain a JSON body.\n\n### User creation.\n\nCreates a user and a session. Returns the JWT of the session.\n\n`POST` `/sign-up`\n\n```json\n{\n  \"username\": \"rick.sanchez@miniverse.com\",\n  \"password\": \"73|2|2Ys[_]|\u003cS!\"\n}\n```\n\n```\neyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\n```\n\nCreates a user and a session. Returns the JWT of the session.\n\n### Authentication.\n\nCreates a session for a registered user. Returns the JWT of the session.\n\n`POST` `/sign-in`\n\n```json\n{\n  \"username\": \"rick.sanchez@miniverse.com\",\n  \"password\": \"73|2|2Ys[_]|\u003cS!\"\n}\n```\n\n```\neyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\n```\n\n### Token checking\n\nCheck if a session is still active and if the token is valid. Returns user UUID if everything is correct.\n\n`POST` `/check-token`\n\n```json\n{\n  \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\"\n}\n```\n\n```\nc751dcf0-4efe-43e9-99c4-acdb8b995d04\n```\n\n### Log out\n\nSet the session as invalid. Returns `OK`.\n\n`DELETE` `/sign-out`\n\n```json\n{\n  \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\"\n}\n```\n\n```\nOK\n```\n\n### Reset password link\n\nSend an email for reseting password. Returns `OK`.\n\n`POST` `/reset-password`\n\n```json\n{ \"username\": \"rick.sanchez@miniverse.com\" }\n```\n\n```\nOK\n```\n\n### Change password\n\nReset the password. Returns `OK`.\n\n`POST` `/reset-password`\n\n```json\n{ \"password\": \"New-password\", \"resetId\": \"XXXXXXXXXXXXXX\" }\n```\n\n```\nOK\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghivert%2Fauthentication","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fghivert%2Fauthentication","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fghivert%2Fauthentication/lists"}