{"id":18256888,"url":"https://github.com/mediacomem/knex-nonce-store","last_synced_at":"2025-04-08T22:28:59.713Z","repository":{"id":73832487,"uuid":"139424302","full_name":"MediaComem/knex-nonce-store","owner":"MediaComem","description":"A nonce store using Knex for ims-lti.","archived":false,"fork":false,"pushed_at":"2018-07-09T07:48:11.000Z","size":123,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-17T11:53:00.841Z","etag":null,"topics":[],"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/MediaComem.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":"2018-07-02T09:53:49.000Z","updated_at":"2018-07-09T07:48:05.000Z","dependencies_parsed_at":"2023-06-17T10:45:10.776Z","dependency_job_id":null,"html_url":"https://github.com/MediaComem/knex-nonce-store","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fknex-nonce-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fknex-nonce-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fknex-nonce-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MediaComem%2Fknex-nonce-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MediaComem","download_url":"https://codeload.github.com/MediaComem/knex-nonce-store/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247938552,"owners_count":21021548,"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":[],"created_at":"2024-11-05T10:24:01.858Z","updated_at":"2025-04-08T22:28:59.706Z","avatar_url":"https://github.com/MediaComem.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Knex Nonce Store\n\nThis package is to be used with the [`ims-lti` package][imslti] that helps implementing some parts of the LTI spec for a web application, notably the part where you have to validate a request as being a correct LTI request.\n\nTo achieve that, the `ims-lti` uses a store to save OAuth nonce/timestramp received. It also implements two stores : one in-memory, another using Redis (see [here][noncestore]), and allows you to add you own nonce store.\n\n**This `knex-nonce-store` package implements a new nonce store that uses [Knex][knex] to do the work.**\n\n## Prerequisites\n\nThis package expect that the following packages are installed on your project.\n\n### `ims-lti`\n\nBeing a complement to the `ims-lti` package, you should install this package prior to installing `knex-nonce-store` (see [the doc of `ims-lti`][imslti-install] to do that).\n\n### `knex` and database package\n\nBefore using the `knex-nonce-store`, you need to install `knex` as long as the package for the database you will use with it.\n\nTo do that, please see the [knex documentation][knex-install].\n\n## Setup\n\nTo manage and store the OAuth nonce/timestamp with `knex-nonce-store` you need to create a new table in your database.\n\nBy default, this table should be called `nonce_store`, but you can give the library the name you want when instanciating it (see [API](#API)).\n\nThe table should be composed of at least two columns :\n\n* `value` - Will store the nonce's value. Should accept the longest strings allowed by your DBMS. It's suggested to make this column the primary key of your table.\n* `timestramp` - Will store the timestamp's value. Should accept long enough string to store a timestamp.\n\n## Usage\n\nTo use this nonce store, you need to instanciate it and pass the instance to the constructor of `Provider` when setting up a Tool Provider with the `ims-lti` package (see [the corresponding doc of `ims-lti`][imslti-setup]).\n\n```javascript\nconst { Provider } = require('ims-lti');\nconst knex = require('knex');\nconst { KnexNonceStore } = require('@mediacomem/knex-nonce-store');\n\nconst knexDB = knex({\n  // You need to initialize the knex library. See the Knex documentation.\n});\n\n// Pass your knex instance to the constructor of KnexNonceStore\nconst store = new KnexNonceStore(knexDB);\n\n// Pass your store instance to the constructor of Provider\nconst provider = new Provider(\u003cconsumer_key\u003e, \u003cconsumer_secret\u003e, store);\n```\n## API\n\n### `KnexNonceStore` class\n\nThe main API of the `knex-nonce-store` is the `KnexNonceStore` class ([documentation](./lib/knex-nonce-store.class.js)).\n\nIt's constructor can accept four paramaters :\n\n* `knex` _{ Object }_ - A initialized knex instance. This is mandatory.\n* `tableName` _{ String }_ - The name of the table where the nonces/timestamps will be stored. **Optional and defaults to `nonce_store`.**\n* `expireIn` _{ Number }_ - The nonce are stored so that they cannot be reused by another request before a certain amount of time. This parameter allows you to define this duration (in number of seconds). **Optional and defaults to 5 minutes (300 seconds).**\n* `lifetime` _{ Number }_ - The request are timed using a timestamp. This timestamp should not be too old when validated by the `ims-lti` `Provider`. This parameter allows you to define the number of seconds during which the timestamp is \"fresh\". **Optional and defaults to 5 minutes (300 seconds).**\n\n### Utiliy functions\n\nYou can also import two utility functions, that are used internally by the `KnexNonceStore` class.\n\n* `isTimestamp()` ([documentation](./lib/is-timestamp.js)) - A function that takes a single parameter and tells you (with a boolean) wether or not its value could be considered a timestamp.\n* `isFreshTimestamp()` ([documentation](./lib/is-fresh-timestamp.js)) - A function that checks if a timestamp is \"fresh\" _(as in \"not too old\")_. It takes two parameters and returns a boolean :\n  * `timestamp` - The timestamp to test.\n  * `lifetime` - The number of seconds during which the timestamp is fresh. **Optional and defaults to 5 minutes (300 seconds).**\n\n[imslti]: https://github.com/omsmith/ims-lti\n[imslti-install]: https://github.com/omsmith/ims-lti#install\n[imslti-setup]: https://github.com/omsmith/ims-lti#setting-up-a-tool-provider-tp\n[noncestore]: https://github.com/omsmith/ims-lti#nonce-stores\n[knex]: https://knexjs.org/\n[knex-install]: https://knexjs.org/#Installation\n[knex-config]: https://knexjs.org/#Installation-client\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Fknex-nonce-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmediacomem%2Fknex-nonce-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmediacomem%2Fknex-nonce-store/lists"}