# @jc21/cypress-jwt-creation

> Generate a JWT for use your tests

Latest version **0.0.6** (published 2023-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @jc21/cypress-jwt-creation
pnpm add @jc21/cypress-jwt-creation
yarn add @jc21/cypress-jwt-creation
bun add @jc21/cypress-jwt-creation
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2023-10-17 |
| First published | 2019-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 11.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Jamie Curnow |
| Maintainers | jc21 |
| Keywords | cypress, jwt, tokens |

## Links

- npm: https://www.npmjs.com/package/@jc21/cypress-jwt-creation
- Repository: https://github.com/jc21/cypress-jwt-creation
- Homepage: https://github.com/jc21/cypress-jwt-creation#readme
- Issues: https://github.com/jc21/cypress-jwt-creation/issues
- npm.io page: https://npm.io/package/@jc21/cypress-jwt-creation

## Dependencies (1)

- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^9.0.2

## Alternatives

- [@snazzah/davey](https://npm.io/package/@snazzah/davey.md) — 1.5M weekly downloads
- [@vendure/testing](https://npm.io/package/@vendure/testing.md) — 8.3K weekly downloads
- [vue-simple-context-menu](https://npm.io/package/vue-simple-context-menu.md) — 6.6K weekly downloads
- [cypress-webpack-preprocessor-v5](https://npm.io/package/cypress-webpack-preprocessor-v5.md) — 2.1K weekly downloads
- [@backstage/plugin-catalog-backend-module-puppetdb](https://npm.io/package/@backstage/plugin-catalog-backend-module-puppetdb.md) — 1.3K weekly downloads

## Recent versions

- 0.0.6 (latest) — 2023-10-17
- 0.0.5 — 2023-10-17
- 0.0.4 — 2020-07-19
- 0.0.3 — 2020-07-08
- 0.0.2 — 2019-10-03
- 0.0.1 — 2019-10-03

## README

# Cypress JWT Creation

Create JWT tokens with ease

[![npm (scoped)](https://img.shields.io/npm/v/@jc21/cypress-jwt-creation.svg?style=for-the-badge)](https://www.npmjs.com/package/@jc21/cypress-jwt-creation)
[![npm (types)](https://img.shields.io/npm/types/@jc21/cypress-jwt-creation.svg?style=for-the-badge)](https://www.npmjs.com/package/@jc21/cypress-jwt-creation)
[![npm (licence)](https://img.shields.io/npm/l/@jc21/cypress-jwt-creation.svg?style=for-the-badge)](https://www.npmjs.com/package/@jc21/cypress-jwt-creation)


### Cypress Installation

```bash
yarn add @jc21/cypress-jwt-creation
```

Then in your cypress Plugins file:
```javascript
const {JwtCreation} = require('@jc21/cypress-jwt-creation');

module.exports = (on, config) => {
    // ...
    on('task', JwtCreation(config));
    // ...
    return config;
};
```


### Cypress Usage

```javascript
describe('Hit an authenticated endpoint', () => {
    it('Should be able to get a response', async function () {
        cy.request('/users/me').then($response => {

            const token = await cy.task('generateToken', {
                privateKey: '/path/to/private.key',
                issuer:     'cypress-tester',
                algo:       'RS256',
                expires:    '1 day',
                claims:     {
                    capabilities: 'superuser'
                }
            });

            // use token in your requests
        });
    });
});
```

### The Private Key

Due to the fact that this plugin runs on the Cypress Backend, the location of the private key file must be defined as either
the full path on disk or relative path to the running of the cypress command. You can define the file location
either with an environment variable which can apply to all tests:

`config.env.jwtPrivateKey`

or within each individial test using the options below. In addition, you can also define the JWT algorithm if different from
the default `RS256` with:

`config.env.jwtAlgo`


### Options

| Option       | Description                                                   | Optional | Default                         |
| ------------ | ------------------------------------------------------------- | -------- | ------------------------------- |
| `privateKey` | The location of the private key file                          | true     | `config.env.jwtPrivateKey`      |
| `issuer`     | Issuer string                                                 | true     | "cypress.testing"               |
| `algo`       | The request method of the endpoint                            | true     | `config.env.jwtAlgo` or `RS256` |
| `expires`    | English interval of token expiry                              | true     | "1 day"                         |
| `claims`     | An object of extra claims you might want to set               | true     | {}                              |


### Compiling Source

```bash
yarn install
yarn build
yarn test
```

---
_Source: https://npm.io/package/@jc21/cypress-jwt-creation · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
