{"id":21483531,"url":"https://github.com/burner/fastjwt","last_synced_at":"2026-01-02T23:57:45.827Z","repository":{"id":66857757,"uuid":"80674834","full_name":"burner/fastjwt","owner":"burner","description":"Fast JSON Web Token Library for Dlang's vibe.d Framework","archived":false,"fork":false,"pushed_at":"2023-07-07T15:56:12.000Z","size":20,"stargazers_count":5,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T18:51:20.035Z","etag":null,"topics":["dlang","jwt","user-auth","viber"],"latest_commit_sha":null,"homepage":null,"language":"D","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/burner.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":"2017-02-01T23:22:14.000Z","updated_at":"2024-08-29T02:58:41.000Z","dependencies_parsed_at":"2025-01-23T18:58:51.231Z","dependency_job_id":null,"html_url":"https://github.com/burner/fastjwt","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burner%2Ffastjwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burner%2Ffastjwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burner%2Ffastjwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burner%2Ffastjwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/burner","download_url":"https://codeload.github.com/burner/fastjwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244006303,"owners_count":20382444,"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":["dlang","jwt","user-auth","viber"],"created_at":"2024-11-23T12:48:04.356Z","updated_at":"2026-01-02T23:57:45.776Z","avatar_url":"https://github.com/burner.png","language":"D","funding_links":[],"categories":[],"sub_categories":[],"readme":"FastJWT\n=======\n\n\u003ca href=\"https://code.dlang.org/packages/fastjwt\" title=\"Go to fastjwt\"\u003e\u003cimg src=\"https://img.shields.io/dub/v/fastjwt.svg\" alt=\"Dub version\"\u003e\u003c/a\u003e\n\nFastJWT is a very fast, vibe.d focused Json Web Token (JWT) implementation that \ntries to avoid the use of the GC. If the the JWT is shorter than 512 charaters no\nmemory will be allocated. If it is longer the memory will be automatically\nallocated and free by the used StringBuffer.\n\nPerformance comparision with LDC calling encode/decode 50000 times:\nhttps://github.com/burner/dlang_jwt_benchmark\n\nfastjwt : 309 ms, 474 μs, and 3 hnsecs\n\njwtd : 499 ms, 281 μs, and 9 hnsecs\n\njwt : 2 secs, 233 ms, 331 μs, and 3 hnsecs\n\nExample\n=======\n\nThe following example shows an examplary use of the fastjwt library in\ncombiation with vibe.d.\nTo use the /secureapi endpoint the JWT created by the /login entpoint needs to\nbe send to the in the request header in the authentication field with the\nBearer prefix to.\n\n```d\nimport vibe.d;\n\nimport fastjwt.jwt;\nimport stringbuffer;\n\nstring secret = \"SuperStrongPassword\";\nJWTAlgorithm algo = JWTAlgorithm.HS512;\n\nshared static this()\n{\n\tauto settings = new HTTPServerSettings;\n\tsettings.port = 8080;\n\tsettings.bindAddresses = [\"::1\", \"127.0.0.1\"];\n\n\tauto router = new URLRouter();\n\trouter.get(\"/login\", \u0026login);\n\trouter.get(\"/secureapi\", \u0026validator!securedApi);\n\n\tlistenHTTP(settings, router);\n\tlogInfo(\"Please open http://127.0.0.1:8080/ in your browser.\");\n}\n\n// Get a new JWTToken\nvoid login(HTTPServerRequest req, HTTPServerResponse res) {\n\tStringBuffer buf;\n\tencodeJWTToken(buf, algo, secret, \"sub\", 1337);\n\tres.writeBody(buf.getData());\n}\n\n// An example validator function that can be used as a template to custom\n// validator function. See the router in the shared statis this for its usage.\nvoid validator(alias fun)(HTTPServerRequest req,\n\t\tHTTPServerResponse res)\n{\n\timport std.algorithm.searching : startsWith;\n\n\tauto authStr = \"Authorization\";\n\tauto bearer = \"Bearer \";\n\n\tif(authStr !in req.headers || !req.headers[authStr].startsWith(bearer)) {\n\t\tres.writeBody(\"Get out, you're not welcome\");\n\t\treturn;\n\t}\n\n\t// Make sure that no reference of any StringBuffer do not escape, as their\n\t// stored data will be freed.\n\tStringBuffer header;\n\tStringBuffer payload;\n\n\tconst rslt = decodeJWTToken(req.headers[authStr][bearer.length .. $],\n\t\t\tsecret, algo, header, payload);\n\n\tif(rslt \u003e 0) {\n\t\tres.writeBody(\"Your token was not OK\");\n\t\treturn;\n\t}\n\n\t//\n\t// Here you would parse payload into Json and see if you find the data\n\t// you were expecting\n\t//\n\n\tfun(req, res);\n}\n\n// If you JWTToken is not ok you cannot use this api.\nvoid securedApi(HTTPServerRequest req, HTTPServerResponse res) {\n\tres.writeBody(\"Here is your secure api!\");\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fburner%2Ffastjwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fburner%2Ffastjwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fburner%2Ffastjwt/lists"}