{"id":21377477,"url":"https://github.com/brick9527/simple-jwt","last_synced_at":"2025-03-16T09:45:07.723Z","repository":{"id":57233809,"uuid":"285303083","full_name":"brick9527/simple-jwt","owner":"brick9527","description":"A simple jwt tool","archived":false,"fork":false,"pushed_at":"2020-08-26T16:17:05.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-22T21:35:33.073Z","etag":null,"topics":["jwt","jwt-token"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brick9527.png","metadata":{"files":{"readme":"README-EN.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-05T13:55:19.000Z","updated_at":"2020-08-26T16:17:08.000Z","dependencies_parsed_at":"2022-08-27T14:08:03.270Z","dependency_job_id":null,"html_url":"https://github.com/brick9527/simple-jwt","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick9527%2Fsimple-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick9527%2Fsimple-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick9527%2Fsimple-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick9527%2Fsimple-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brick9527","download_url":"https://codeload.github.com/brick9527/simple-jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243852431,"owners_count":20358270,"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":["jwt","jwt-token"],"created_at":"2024-11-22T09:21:10.391Z","updated_at":"2025-03-16T09:45:07.697Z","avatar_url":"https://github.com/brick9527.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/brick9527/simple-jwt.svg?branch=master)](https://travis-ci.org/brick9527/simple-jwt)\n![NPM](https://img.shields.io/npm/l/fd-simple-jwt)\n![GitHub package.json version (branch)](https://img.shields.io/github/package-json/v/brick9527/simple-jwt/master)\n![GitHub last commit](https://img.shields.io/github/last-commit/brick9527/simple-jwt)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/brick9527/simple-jwt)\n\n# Guide\n\n[中文文档](./README.md)\n\n# Introduction\n\n`fd-simple-jwt` is a JWT tool developed with pure JS. It does not include any third-part packages, so it is good for keeping the tool at a high-level of source-level customization.\n\n# Features\n\n- ligh-weight\n- easy using\n- friendly for customization\n- no third-part packages\n\n# Install\n\n```bash\nnpm install fd-simple-jwt --save\n```\n\n# Usage\n\n```js\nconst SimpleJWT = require('fd-simple-jwt');\n```\n\n# API\n\n`fd-simple-jwt` includes two methods:\n\n- encodeJWT：encode data to JWT\n- decodeJWT：decode JWT to data\n\n## encodeJWT\n\nGenerating a JWT string from some data.\n\nIt accepts 2 or 3 parameters:\n\n- options\n  - options.secretKey(**required**): The secret key for encoding\n- data(**required**): The data is used for encoding the JWT body.\n  - data.expire(optional): How long the JWT keeps alive (ms). If this property exists, it will check if the JWT is valid when decoding the JWT. If the JWT is out of time, it will return `new Error('JWT expired.')`.\n- callback(err, jwt) (optional): Callback function. The parameter `jwt` is the JWT generating by this method. If this parameter is undefined, this method will return the `jwt` directly.\n\n#### Directly Way\n\n```js\nconst { encodeJWT } = require('fd-simple-jwt');\n\nconst options = {\n  secretKey: 'secret key', // please keep the key secretly\n};\nconst data = {\n  id: 123,\n};\n\nconst jwt = encodeJWT(options, data);\n```\n\n#### Callback Way\n\n```js\nconst { encodeJWT } = require('fd-simple-jwt');\n\nconst options = {\n  secretKey: 'secret key',\n};\nconst data = {\n  id: 123,\n};\n\nencodeJWT(options, data, function(err, jwt) {\n  console.log(jwt);\n})\n```\n\n## decodeJWT\n\nDecoding JWT string.\n\nThis method accepts 2 or 3 parameters:\n\n- jwt(**required**): The JWT string for decoding.\n- secretKey(**required**): The secretKey for decoding. This value is set when encoding the JWT.\n- callback(err, data) (optional): Callback function.If this parameter is undefined, this method will return the data directly.\n\n#### Directly Way\n\n```js\nconst { decodeJWT } = require('fd-simple-jwt');\n\nconst jwt = '...'; // 该值为生成的jwt字符串\nconst options = {\n  secretKey: 'secret key',\n};\n\nconst result = decodeJWT(jwt, options.secretKey);\n```\n\n#### Callback Way\n\n```js\nconst { decodeJWT } = require('fd-simple-jwt');\n\nconst jwt = '...'; // 该值为生成的jwt字符串\nconst options = {\n  secretKey: 'secret key',\n};\n\ndecodeJWT(jwt, options.secretKey, function(err, data) {\n  console.log(data);\n})\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrick9527%2Fsimple-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrick9527%2Fsimple-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrick9527%2Fsimple-jwt/lists"}