{"id":37232085,"url":"https://github.com/thamtech/yii2-jsonrpc-jwsauth","last_synced_at":"2026-01-15T03:47:19.586Z","repository":{"id":57067543,"uuid":"43174985","full_name":"thamtech/yii2-jsonrpc-jwsauth","owner":"thamtech","description":"JWS Token Authentication over JSON RPC 2.0","archived":false,"fork":false,"pushed_at":"2015-09-25T22:37:53.000Z","size":160,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-14T18:47:49.244Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thamtech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-25T20:52:48.000Z","updated_at":"2019-11-04T04:48:24.000Z","dependencies_parsed_at":"2022-08-24T10:20:13.317Z","dependency_job_id":null,"html_url":"https://github.com/thamtech/yii2-jsonrpc-jwsauth","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/thamtech/yii2-jsonrpc-jwsauth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thamtech%2Fyii2-jsonrpc-jwsauth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thamtech%2Fyii2-jsonrpc-jwsauth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thamtech%2Fyii2-jsonrpc-jwsauth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thamtech%2Fyii2-jsonrpc-jwsauth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thamtech","download_url":"https://codeload.github.com/thamtech/yii2-jsonrpc-jwsauth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thamtech%2Fyii2-jsonrpc-jwsauth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28417962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":"2026-01-15T03:47:18.938Z","updated_at":"2026-01-15T03:47:19.570Z","avatar_url":"https://github.com/thamtech.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"yii2-jsonrpc-jwsauth\n====================\n\nAn extension to handle signed access token authentication via JSON RPC 2.0.\n\nThis library interfaces\nwith [yii2-json-rpc-2.0](http://github.com/cranetm/yii2-json-rpc-2.0) to provide\nthe JSON RPC 2.0 communication in your controller and\n[namshi/jose](http://github.com/namshi/jose) to generate signed\n[JWS](https://tools.ietf.org/html/rfc7515) tokens.\n\nFor license information check the [LICENSE](LICENSE.md)-file.\n\nInstallation\n------------\n\nThe preferred way to install this extensions is through [composer](http://getcomposer.org/download/).\n\nEither run\n```\nphp composer.phar require --prefer-dist thamtech/yii2-jsonrpc-jwsauth\n```\nor add\n```\n\"thamtech/yii2-jsonrpc-jwsauth\": \"*\"\n```\nto the `require` section of your `composer.json` file.\n\nIntegration\n-----------\n\n1. [Generate a kepair using OpenSSL](https://en.wikibooks.org/wiki/Cryptography/Generate_a_keypair_using_OpenSSL)\n   and store the keys in public.pem and private.pem.\n\n2. Add the JwsManager application component in your site configuration:\n\n    ```php\n    return [\n      'components' =\u003e [\n        'jwsManager' =\u003e [\n          'class' =\u003e 'thamtech\\jwsauth\\components\\JwsManager',\n          'pubkey' =\u003e '@app/config/keys/jwsauth/public.pem',\n          'pvtkey' =\u003e '@app/config/keys/jwsauth/private.pem',\n          \n          // The settings below are optional. Defaults will be used if not set here.\n          //'encoder' =\u003e 'Namshi\\JOSE\\Base64\\Base64UrlSafeEncoder',\n          //'refreshExp' =\u003e '24 hours',\n          //'exp' =\u003e '1 hour',\n          //'alg' =\u003e 'RS256',\n          //'jwsClass' =\u003e 'Namshi\\JOSE\\SimpleJWS',\n        ],\n      ]\n    ]\n    ```\n\n3. Create a `UserController` in your application:\n\n    ```php\n    class UserController extends \\thamtech\\jwsauth\\controllers\\UserController\n    {\n      // parent class provides actionAuthenticate($username, $passwrd)\n      // and actionRefreshToken()\n      \n      // You may add your own additional methods to provide additional user\n      // management services such as registration, password changes, etc.\n    }\n    ```\n\n4. Update your `User` model to implement `\\thamtech\\jwsauth\\models\\IdentityInterface`\n   instead of `\\yii\\web\\IdentityInterface`, and use the `SimpleUserTrait`:\n\n    ```php\n    class User extends \\yii\\base\\Object implements \\thamtech\\jwsauth\\models\\IdentityInterface\n    {\n      use SimpleUserTrait;\n      \n      public $id;\n      public $username;\n      \n      // You must still implement all methods required by \\yii\\web\\IdentityInterface\n      // since \\thamtech\\jwsauth\\models\\IdentityInterface extends\n      // \\yii\\web\\IdentityInterface\n    }\n    ```\n\n5. Add the JsonRpcAuth filter on any \\JsonRpc2\\Controller you would like\n   jwsauth-authenticated users to access:\n    \n    ```php\n    public function behaviors()\n    {\n      return [\n        'authenticator' =\u003e [\n          'class' =\u003e \\thamtech\\jwsauth\\filters\\auth\\JsonRpcAuth::className(),\n          'except' =\u003e ['public-method-1', 'public-method-2'],\n        ],\n      ];\n    }\n    ```\n\nClient-Side Usage\n-----------------\n\n1. Make a JSON RPC request to the authenticate method passing in a username\n   and password.\n   \n    ```\n    http://yoursite/user\n    ```\n    with data\n    ```javascript\n    {\n      \"jsonrpc\": \"2.0\",\n      \"id\": 1,\n      \"method\": \"authenticate\",\n      \"params\": {\n        \"username\": \"YOUR-USERNAME\",\n        \"password\": \"YOUR-PASSWORD\"\n      }\n    }\n    ```\n    and a successful response will be something like this\n    ```javascript\n    {\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"token\":\"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpZCI6MT-TRIMMED_FOR_BREVITY\"}}\n    ```\n\n2. Make a JSON RPC request to any controller/method requiring authentication\n   using the token provided in the previous step:\n    \n    ```\n    http://yoursite/protected-controller\n    ```\n    with data\n    ```javascript\n    {\n      \"jsonrpc\": \"2.0\",\n      \"id\": 2,\n      \"auth\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpZCI6MT-TRIMMED_FOR_BREVITY\",\n      \"method\": \"access-sensitive-data\",\n      \"params\": {\"id\": 27}\n    }\n    ```\n\n### Expiration and Refreshing Tokens\n\nWhen the token expires (after 1 hour by default), you may refresh the token\nwithout requiring the user to re-authenticate with username and password. This\nis allowed up to the refresh expiration of a token (24 hours by default).\n\nIf you have a valid token and make an authenticated request but receive a\nresult like the following:\n```javascript\n{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 3,\n  \"error\": {\n    \"code\": -32652,\n    \"data\": null,\n    \"message\": \"Invalid or expired token\"\n  }\n}\n```\nthen your next step is to try to refresh the token:\n```\nhttp://yoursite/user\n```\nwith data\n```javascript\n{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 4,\n  \"auth\": \"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpZCI6MT-TRIMMED_FOR_BREVITY\",\n  \"method\": \"refresh-token\"\n}\n```\n\nThe response will either contain a new token which you may continue using\nnormally:\n```javascript\n{\"jsonrpc\":\"2.0\",\"id\":4,\"result\":{\"token\":\"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpZCI6MT-TRIMMED_FOR_BREVITY\"}}\n```\n\nOr an indication that the token could not be refreshed:\n```javascript\n{\n  \"jsonrpc\": \"2.0\",\n  \"id\": 3,\n  \"error\": {\n    \"code\": -32652,\n    \"data\": null,\n    \"message\": \"expired; user must reauthenticate\"\n  }\n}\n```\n\nIf the token could not be refreshed, then you will need to:\n\n1. Ask the user to re-login with their username and password\n\n2. Use the \"authenticate\" method in Step 1 of the Client-Side Usage section above\n   to get a new auth token.\n\n3. Continue making authenticated requests with the new token.\n\nAdvanced Usage\n--------------\n\n* You do not have to use `SimpleUserTrait` in your User identity. It is merely\n  a convenience for most use cases. You are free to implement your own\n  `getAuthKey()` and `findIdentityByAccessToken()` methods directly in your\n  `User` identity class in a way that better suits your application's needs.\n\n* Rather than instantiating a `UserController` as a sublcass, you could refer\n  to `\\thamtech\\jwsauth\\controllers\\UserController` directly in a controller map:\n  \n  ```php\n  [\n    'controllerMap' =\u003e [\n      // declares \"login\" controller using a class name\n      'login' =\u003e 'thamtech\\jwsauth\\controllers\\UserController',\n    ],\n  ]\n  ```\n\nSee Also\n--------\n\n* [cranetm/yii2-json-rpc-2.0](http://github.com/cranetm/yii2-json-rpc-2.0) - Yii 2\n  extension that helps turn your Controllers into JSON RPC 2.0 APIs.\n  \n* [namshi/jose](http://github.com/namshi/jose) - PHP implementation of the\n  JWS (JSON Web Signature) specification.\n  \n* [JSON Web Signature (JWS)](https://tools.ietf.org/html/rfc7515) - JWS specifications\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthamtech%2Fyii2-jsonrpc-jwsauth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthamtech%2Fyii2-jsonrpc-jwsauth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthamtech%2Fyii2-jsonrpc-jwsauth/lists"}