{"id":19142308,"url":"https://github.com/flipboxfactory/craft-jwt","last_synced_at":"2025-05-06T23:46:08.653Z","repository":{"id":62505727,"uuid":"126093726","full_name":"flipboxfactory/craft-jwt","owner":"flipboxfactory","description":"JWT for Craft CMS","archived":false,"fork":false,"pushed_at":"2022-02-14T19:35:15.000Z","size":40,"stargazers_count":11,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-18T05:21:34.821Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","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/flipboxfactory.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-20T23:03:07.000Z","updated_at":"2022-12-03T15:14:55.000Z","dependencies_parsed_at":"2022-11-02T12:45:31.256Z","dependency_job_id":null,"html_url":"https://github.com/flipboxfactory/craft-jwt","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipboxfactory%2Fcraft-jwt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipboxfactory%2Fcraft-jwt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipboxfactory%2Fcraft-jwt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipboxfactory%2Fcraft-jwt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flipboxfactory","download_url":"https://codeload.github.com/flipboxfactory/craft-jwt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252788404,"owners_count":21804280,"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-09T07:26:47.691Z","updated_at":"2025-05-06T23:46:08.634Z","avatar_url":"https://github.com/flipboxfactory.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JWT Tokens for Craft CMS\n[![Join the chat at https://gitter.im/flipboxfactory/craft-jwt](https://badges.gitter.im/flipboxfactory/craft-jwt.svg)](https://gitter.im/flipboxfactory/craft-jwt?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Latest Version](https://img.shields.io/github/release/flipboxfactory/craft-jwt.svg?style=flat-square)](https://github.com/flipboxfactory/craft-jwt/releases)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md)\n[![Build Status](https://img.shields.io/travis/flipboxfactory/craft-jwt/master.svg?style=flat-square)](https://travis-ci.com/flipboxfactory/craft-jwt)\n[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/flipboxfactory/craft-jwt.svg?style=flat-square)](https://scrutinizer-ci.com/g/flipboxfactory/craft-jwt/code-structure)\n[![Quality Score](https://img.shields.io/scrutinizer/g/flipboxfactory/craft-jwt.svg?style=flat-square)](https://scrutinizer-ci.com/g/flipboxfactory/craft-jwt)\n[![Total Downloads](https://img.shields.io/packagist/dt/flipboxfactory/craft-jwt.svg?style=flat-square)](https://packagist.org/packages/flipboxfactory/craft-jwt)\n\nJWT (JSON Web Token) for Craft CMS assists in issuing and claiming tokens.  The intent is to issue a token which, at a later time, can be claimed and used to perform various actions.  \nThe life of a JWT is defined upon creation and \n\n## Use Cases\n* Protected downloads\n* Protected pages/content\n* Authorization to API\n* Tracking actions (by user)\n* Sharing downloads/pages to guests\n\nTo learn more about JWT visit [JWT.IO](https://jwt.io/introduction/)\n\n## Requirements\nThis plugin requires Craft CMS 3.0 or later.\n\n## Installation\n\nSimply run the following command from your project root:\n\n```\ncomposer require flipboxfactory/craft-jwt\n```\n\nOnce the plugin is included in your project, navigate to the Control Panel, go to Settings → Plugins and click the “Install” button for the [JWT Plugin].\n\n### Templating\nThe `craft.jwt` template variable provides access to the entire [JWT] plugin.  To access the services, you may use:\n\nIdentity Service:\n```twig\n{% set token = craft.jwt.identity.issue(currentUser) %} {# To generate a token (store the identity) #}\n{% set claim = craft.jwt.identity.claim(token|trim) %} {# To claim a token (retrieve the identity) #}\n```\n\nRoute Service:\n```twig\n{% set token = craft.jwt.route.issue('action/path') %} {# To generate a token (store the action path) #}\n{% set claim = craft.jwt.route.claim(token|trim) %} {# To claim a token (retrieve the action path) #}\n```\n\n## Examples\nCommon usages of this plugin are as follows:\n\n### Self-Consumable API (Hybrid API - calling your own API)\nMaking calls to your own API is a great candidate for JWT Identity tokens.  The flow works something like this:\n1. Set a JavaScript variable: `let jwt = '{{ craft.jwt.identity.issue(currentUser) }}'`\n2. Using [Axois](https://github.com/axios/axios) (or other HTTP client library), make a call to your own API using the JWT token created in step 1.\n3. Apply the Authentication filter to your API controller(s).\n```php\n/**\n * @inheritdoc\n */\npublic function behaviors()\n{\n    return \\craft\\helpers\\ArrayHelper::merge(\n        parent::behaviors(),\n        [\n            'authenticator' =\u003e [\n                'authMethods' =\u003e [\n                    \\flipbox\\craft\\jwt\\filters\\JwtHttpBearerAuth::class\n                ]\n            ]\n        ]\n    );\n}\n```\nA full example of the Authentication filter implementation can be found in our [RESTful API for Craft CMS](https://github.com/flipboxfactory/craft-restful/blob/master/src/controllers/AbstractController.php)\n\n\n### Protected Downloads (or page access)\nPerhaps a user needs to access a protected page or file download.  To circumvent exposing the url publicly, issue a JWT Route token. \n\n##### Render template: \n```twig\n{% set token  = craft.jwt.route.issue(['templates/render', {'template': '_protected/template'}], currentUser)\n{# the link will automatically render the template #}\n\u003ca href=\"{{ actionUrl(\"jwt/route\", {jwt: token|trim}) }}\"\u003eView Protected Page\u003c/a\u003e\n```\n\n##### File Download\n```twig\n{% set asset = craft.assets.one() %}\n{% set token  = craft.jwt.route.issue(['assets/thumb', {'uid': asset.uid, width: 100, height: 100}], currentUser) %}\n\u003ca href=\"{{ actionUrl(\"jwt/route\", {jwt: token|trim}) }}\"\u003eDownload Protected File\u003c/a\u003e\n```\n\nNote: It's important to note that in the File Download example, we're also passing the `currentUser` param when generating\nthe token.  As a result, when the action is processed we're assuming the identity of the user who issued the token prior to performing the action.  This means a user\ndoesn't have to be logged in to Craft.\n\n\n## Caution\nJWTs created by this plugin are technically JWS (JSON Web Signature) tokens.  The contents of a token can be \neasily decoded and viewed using tools such as [jwt.io](https://jwt.io).  It is important **NOT** to store sensitive data\nin a token.  The Craft '[security key](https://docs.craftcms.com/v3/installation.html#step-3-set-a-security-key)' is used to sign each token; ensuring the contents have not been\ntampered with.\n\nA token is valid for \n\n## Contributing\nPlease see [CONTRIBUTING](https://github.com/flipboxfactory/craft-jwt/blob/master/CONTRIBUTING.md) for details.\n\n## Credits\n- [Flipbox Digital](https://github.com/flipbox)\n\n## License\nThe MIT License (MIT). Please see [License File](https://github.com/flipboxfactory/craft-jwt/blob/master/LICENSE) for more information.\n\n[Plugin Store]: https://plugins.craftcms.com/jwt\n[JWT for Craft CMS]: https://github.com/flipboxfactory/craft-jwt\n[JWT]: https://github.com/flipboxfactory/craft-jwt\n[JWT Plugin]: https://github.com/flipboxfactory/craft-jwt","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipboxfactory%2Fcraft-jwt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflipboxfactory%2Fcraft-jwt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipboxfactory%2Fcraft-jwt/lists"}