{"_id":"@beliven/rb-auth-provider-simple","name":"@beliven/rb-auth-provider-simple","dist-tags":{"latest":"0.23.0"},"versions":{"0.23.0":{"name":"@beliven/rb-auth-provider-simple","version":"0.23.0","description":"A Restboard auth provider supporting email/password or bearer token","main":"src/index.js","type":"module","scripts":{"test":"tap --disable-coverage --allow-empty-coverage --exclude=test/server.js"},"repository":{"type":"git","url":"git+https://github.com/beliven-it/rb-auth-provider-simple.git"},"keywords":["REST","JSON","auth","provider","simple","restboard"],"author":{"name":"Emanuele Bertoldi","email":"emanuele.bertoldi@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/beliven-it/rb-auth-provider-simple/issues"},"homepage":"https://github.com/beliven-it/rb-auth-provider-simple#readme","dependencies":{"cross-fetch":"^4.0.0"},"peerDependencies":{"@beliven/rb-core-module":"^0.32.0"},"devDependencies":{"eslint":"^8.48.0","tap":"^18.6.1"},"publishConfig":{"access":"public"},"_id":"@beliven/rb-auth-provider-simple@0.23.0","gitHead":"64375c8f8e7d656fa3d6efdf313083709b1770d1","_nodeVersion":"20.19.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-xMl9a0Z1hv3yrNuuUDZxbKINy6LWqS2CSMKPN2YUYYYsjR2hokQeW2JjUXVKFCsDYau3cDfosc12kvSBUlea8Q==","shasum":"28d12b7186f4cc607964782a113c72ebb635c59f","tarball":"https://registry.npmjs.org/@beliven/rb-auth-provider-simple/-/rb-auth-provider-simple-0.23.0.tgz","fileCount":13,"unpackedSize":19753,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIF6jBNXAKJKxbKbk6EuDE7KaTVLpO9jV4SOvOPep+BXmAiEAsz9JAUUzUFDVzUx4Fs1ws96lpPRO8sJuaBF+l4T0pqk="}]},"_npmUser":{"name":"beliven.dev","email":"dev@beliven.com"},"directories":{},"maintainers":[{"name":"beliven.dev","email":"dev@beliven.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/rb-auth-provider-simple_0.23.0_1744295777883_0.7392662556676983"},"_hasShrinkwrap":false}},"time":{"created":"2025-04-10T14:36:17.772Z","0.23.0":"2025-04-10T14:36:18.049Z","modified":"2025-04-10T14:36:18.343Z"},"maintainers":[{"name":"beliven.dev","email":"dev@beliven.com"}],"description":"A Restboard auth provider supporting email/password or bearer token","homepage":"https://github.com/beliven-it/rb-auth-provider-simple#readme","keywords":["REST","JSON","auth","provider","simple","restboard"],"repository":{"type":"git","url":"git+https://github.com/beliven-it/rb-auth-provider-simple.git"},"author":{"name":"Emanuele Bertoldi","email":"emanuele.bertoldi@gmail.com"},"bugs":{"url":"https://github.com/beliven-it/rb-auth-provider-simple/issues"},"license":"MIT","readme":"# rb-auth-provider-simple\n\nA [Restboard](https://restboard.github.io/) auth provider supporting email/password or bearer token\n\n[![Node.js CI](https://github.com/beliven-it/rb-auth-provider-simple/actions/workflows/node.js.yml/badge.svg)](https://github.com/beliven-it/rb-auth-provider-simple/actions/workflows/node.js.yml)\n\n## Getting started\n\n```js\nimport createAuthProvider from '@beliven/rb-auth-provider-simple'\n\nconst authProvider = createAuthProvider('https://my.api.url/auth')\n\nauthProvider.login({ email: 'a@a.it', password: 'password' })\n  .then(res => console.log(`Welcome, ${authProvider.getIdentity(res.data)}`))\n  .catch(err => console.error(err))\n```\n\n## Schema\n\nInvoking `login` will call the provided authentication API as a `POST` request\nwith the passed credentials (except for the `keepLogged` attribute which is\nused internally):\n\n```js\n// e.g. login({ email = '...', password = '...', keepLogged = true })\n//      will produce the following request payload:\n{\n  email: '...',\n  password: '...'\n}\n```\n\nThis provder expects the authentication API will return a JSON response\naccording to the following schema:\n\n```js\n{\n  user: {\n    ...\n  },\n  token: '...'\n}\n```\n\n## Options\n\nBy default, a single string argument containing the URL of the authentication\nAPI to call on login can be passed to the factory function:\n\n```js\nconst authProvider = createAuthProvider('https://my.api.url/auth')\n```\n\nAdditional options can be passed as second argument, e.g.:\n\n```js\nconst authProvider = createAuthProvider('https://my.api.url/auth', {\n  tokenCacheKey: 'my-auth-token-cache-key'\n})\n```\n\n| Name                  | Description                                                    | Default          |\n|-----------------------|----------------------------------------------------------------|------------------|\n| `recoverURL`          | The (optional) URL used to send a credentials recovery request | null |\n| `activateOrResetURL`  | The (optional) URL used to activate or reset user credentials  | null |\n| `checkURL`            | The (optional) URL used to check for active authentication     | null             |\n| `parseUserDetails`    | A function used to extract user details from the API response. Should have the following signature: `(res) => object` | `(res) => res.user` |\n| `parseError`          | A function used to extract details from an API error response. Should have the following signature: `(res) => object\\|string` | `(res) => res?.statusText \\|\\| res?.status` |\n| `parseToken`          | A function used to extract the access token from the API response. Should have the following signature: `(res) => string` | `(res) => res.token` |\n| `tokenCacheKey`       | The key used to store the bearer token into the cache storage  | `rb-auth-token`  |\n| `userIdentifier`      | A function returning the `user` string representation          | null             |\n| `tenantIdentifier`    | A function returning the `user`'s tenant string representation | null             |\n| `acl`                 | A function to check if `user` is allowed to perform `action` on `subject`. Should have the following signature: `(user, action, subject) => boolean` | null |\n| `timeout`             | The timeout (ms) for each single HTTP request attempt          | 5000             |\n| `retries`             | The number of attempts before failing                          | 3                |\n| `backoff`             | The incremental delay (ms) between request attempts            | 300              |\n| `client`              | The HTTP client used to perform the requests                   | `cross-fetch`    |\n| `writeToStorage`      | A function used to store a session value. Should have the following signature: `async (key, val, persistent) => void` | *using `local/sessionStorage`* |\n| `readFromStorage`     | A function used to read a session value. Should have the following signature: `async (key) => { value, persistent }` | *using `local/sessionStorage`* |\n| `removeFromStorage`   | A function used to remove a session value. Should have the following signature: `async (key) => void` | *using `local/sessionStorage`* |\n\n## CORS issues\n\nIf you encounter any CORS issue when using the provider, please keep in mind the default HTTP client is configured to [include credentials](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#sending_a_request_with_credentials_included) for both same-origin and cross-origin requests.\n\nIf the server is configured to allow any origin (`Access-Control-Allow-Origin: *`), a CORS error\nwill be thrown.\n\nYou can solve this issue overriding the default HTTP client adjusting its configuration, e.g.:\n\n```js\nconst myClient(url, opts) {\n  return fetch(url, {\n    ...opts,\n    headers: {\n      Accept: \"application/json\",\n      ...opts.headers,\n    },\n  });\n}\n\nconst authProvider = createAuthProvider('https://my.api.url/auth', {\n  client: myClient\n})\n```\n\n## Test\n\n```bash\nnpm test\n```\n\n## Contribute\n\nIf you want, you can also freely donate to fund the project development:\n\n[![Donate](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://paypal.me/EBertoldi)\n\n## Have you found a bug?\n\nPlease open a new issue on:\n\n<https://github.com/beliven-it/rb-auth-provider-simple/issues>\n\n## License\n\nCopyright (c) Emanuele Bertoldi\n\n[MIT License](http://en.wikipedia.org/wiki/MIT_License)\n","readmeFilename":"README.md","_rev":"1-c839dcc66b86180e2923c86ab2e5b3d9"}