{"id":136981,"date":"2021-02-24T05:22:33","date_gmt":"2021-02-24T05:22:33","guid":{"rendered":"https:\/\/wordpress.org\/plugins\/custom-fields-for-jwt-authentication-for-wp-rest-api\/"},"modified":"2022-08-01T18:33:26","modified_gmt":"2022-08-01T18:33:26","slug":"custom-fields-for-jwt-authentication-for-wp-rest-api","status":"publish","type":"plugin","link":"https:\/\/he.wordpress.org\/plugins\/custom-fields-for-jwt-authentication-for-wp-rest-api\/","author":18140568,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_crdt_document":"","version":"1.2.1","stable_tag":"1.2.1","tested":"6.0.11","requires":"","requires_php":"","requires_plugins":"","header_name":"User Data Fields For Jwt Authentication","header_author":"AhmedHnewa","header_description":"Simple Plugin It Will Add User Data (Id ,Url ,Status ,Roles ,FirstName ,LastName ,Avatar URl ,etc ) Fields To The Jwt Endpoint After Get Successful Response","assets_banners_color":"","last_updated":"2022-08-01 18:33:26","external_support_url":"","external_repository_url":"","donate_link":"","header_plugin_uri":"https:\/\/wordpress.org\/plugins\/custom-fields-for-jwt-authentication-for-wp-rest-api\/","header_author_uri":"https:\/\/www.youtube.com\/darkzeroone","rating":5,"author_block_rating":0,"active_installs":40,"downloads":2392,"num_ratings":3,"support_threads":0,"support_threads_resolved":0,"author_block_count":0,"sections":["description","faq","changelog"],"tags":{"1.2.0":{"tag":"1.2.0","author":"ahmedriyadh","date":"2021-02-26 21:08:40"},"1.2.1":{"tag":"1.2.1","author":"ahmedriyadh","date":"2022-08-01 18:33:26"}},"upgrade_notice":{"1.2.1":"<ul>\n<li>Tested up to the current version of wordpress<\/li>\n<\/ul>","1.2.0":"<ul>\n<li>Add User Data Fields To Validate Token Endpoint (Please Read Docs)<\/li>\n<\/ul>"},"ratings":{"1":0,"2":0,"3":0,"4":0,"5":3},"assets_icons":{"icon-128x128.png":{"filename":"icon-128x128.png","revision":2480516,"resolution":"128x128","location":"assets","locale":""}},"assets_banners":[],"assets_blueprints":{},"all_blocks":[],"tagged_versions":["1.2.0","1.2.1"],"block_files":[],"assets_screenshots":{"screenshot-1.PNG":{"filename":"screenshot-1.PNG","revision":2480342,"resolution":"1","location":"assets","locale":""},"screenshot-2.PNG":{"filename":"screenshot-2.PNG","revision":2480342,"resolution":"2","location":"assets","locale":""}},"screenshots":{"1":"This is when get token response","2":"This Is when get validate token response"},"jetpack_post_was_ever_published":false},"plugin_section":[],"plugin_tags":[38852,38851,2300,38850],"plugin_category":[],"plugin_contributors":[196607],"plugin_business_model":[],"class_list":["post-136981","plugin","type-plugin","status-publish","hentry","plugin_tags-json-web-authentication","plugin_tags-jwt","plugin_tags-wp-api","plugin_tags-wp-json","plugin_contributors-ahmedriyadh","plugin_committers-ahmedriyadh"],"banners":[],"icons":{"svg":false,"icon":"https:\/\/ps.w.org\/custom-fields-for-jwt-authentication-for-wp-rest-api\/assets\/icon-128x128.png?rev=2480516","icon_2x":false,"generated":false},"screenshots":[{"src":"https:\/\/ps.w.org\/custom-fields-for-jwt-authentication-for-wp-rest-api\/assets\/screenshot-1.PNG?rev=2480342","caption":"This is when get token response"},{"src":"https:\/\/ps.w.org\/custom-fields-for-jwt-authentication-for-wp-rest-api\/assets\/screenshot-2.PNG?rev=2480342","caption":"This Is when get validate token response"}],"raw_content":"<!--section=description-->\n<p>Wordpress is a good content mangement system for building websites, but it will be better if you build like mobile apps,\nWith the wordpress rest api you can create posts, edit posts, view posts, Users, Uploading Media etc...\nbut the problem with the wordpress rest api it does not provide any authentication methods for third party application like mobile apps\nThe Jwt Plugin on wordpress.org does provide that<\/p>\n\n<p>and this plugin is just a addon for that plugin<\/p>\n\n<p>So this plugin is useful if you don't want to make another request to fetch user data like Id etc..\nbecause you have to get the id of the user in ordet to get all data<\/p>\n\n<p>It really simple plugin\nit writed with 50 lines of code, the size of the plugin is 3Kb<\/p>\n\n<p>Note: This Is Plugin For\n<a href=\"https:\/\/wordpress.org\/plugins\/jwt-authentication-for-wp-rest-api\/\">JWT Authentication for WP REST API Plugin<\/a><\/p>\n\n<p>so if the jwt authentication plugin is not installed\nthis plugin will not add the fields to it endpoints<\/p>\n\n<p>and the fields will be added only if the token is getted successfully<\/p>\n\n<p>Example request (before install the plugin):\n{\n\u00a0 \u00a0 \"token\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xOTIuMTY4LjAuMTgyIiwiaWF0IjoxNjE0MDg3NDQ2LCJuYmYiOjE2MTQwODc0NDYsImV4cCI6MTYxNDY5MjI0NiwiZGF0YSI6eyJ1c2VyIjp7ImlkIjoiMSJ9fX0.KeAUc7PiTne0_PThsSAWo1ruvl2Ocu-fbCn2jG7zkoE\",\n\u00a0 \u00a0 \"user_email\": \"example@example.com\",\n\u00a0 \u00a0 \"user_nicename\": \"admin\",\n\u00a0 \u00a0 \"user_display_name\": \"admin\"\n}<\/p>\n\n<p>Example response (after install the plugin):\n{\n\u00a0 \u00a0 \"token\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xOTIuMTY4LjAuMTgyIiwiaWF0IjoxNjE0MDg2NjQyLCJuYmYiOjE2MTQwODY2NDIsImV4cCI6MTYxNDY5MTQ0MiwiZGF0YSI6eyJ1c2VyIjp7ImlkIjoiMSJ9fX0.nyDOICdQcZKbWZo2kQRp_eLBkuxjnK_rpxs-HJREyCg\",\n\u00a0 \u00a0 \"user_email\": \"example@example.com\",\n\u00a0 \u00a0 \"user_nicename\": \"admin\",\n\u00a0 \u00a0 \"user_display_name\": \"admin\",\n\u00a0 \u00a0 \"user_id\": 1,\n\u00a0 \u00a0 \"user_login\": \"admin\",\n\u00a0 \u00a0 \"user_first_name\": \"sfd\",\n\u00a0 \u00a0 \"user_last_name\": \"\",\n\u00a0 \u00a0 \"user_roles\": [\n\u00a0 \u00a0 \u00a0 \u00a0 \"administrator\"\n\u00a0 \u00a0 ],\n\u00a0 \u00a0 \"user_role\": \"administrator\",\n\u00a0 \u00a0 \"user_registered\": \"2021-02-17 09:21:29\",\n\u00a0 \u00a0 \"user_url\": \"http:\/\/localhost\",\n\u00a0 \u00a0 \"user_status\": \"0\",\n\u00a0 \u00a0 \"user_avatar_url\": \"https:\/\/secure.gravatar.com\/avatar\/22feea4605ac5b7163eac439b5241034?s=96&amp;d=mm&amp;r=g\",\n\u00a0 \u00a0 \"user_activation_key\": \"\"\n}<\/p>\n\n<p>Of course you can add the code of this plugin to your Theme,\nbut this is not recommened because when you change the theme or update it\nthe changes will revert back, you can create child theme for that\nbut instead you can just install this simple plugin<\/p>\n\n<p>Don't forget to setup (JwtAuthenticatonForWordpress)[https:\/\/wordpress.org\/plugins\/jwt-authentication-for-wp-rest-api\/]<\/p>\n\n<p><a href=\"https:\/\/github.com\/ahmedhnewa\/user-data-fields-jwt-plugin\">Github<\/a><\/p>\n\n<h3>Can Add User Data Fields To Validate Token Endpoint ?<\/h3>\n\n<p>This plugin can also add user data fields to validate token endpoint,<\/p>\n\n<p>Unfortunately, the jwt extension does not support using the filter for validate_token function,\nSo You Will Need To Modify Some Codes Inside Jwt Plugin Codes\nGo To \\wp-content\\plugins\\jwt-authentication-for-wp-rest-api\\public\\class-jwt-auth-public.php\nAnd At The End Of Function That Named validate_token\nIn Line 302<\/p>\n\n<p>Edit This Code \nFrom :\n\/** If the output is true return an answer to the request to show it *\/\n            return array(\n                'code' =&gt; 'jwt_auth_valid_token',\n                'data' =&gt; array(\n                    'status' =&gt; 200,\n                ),\n            );\nTo : \n$value = array(\n            'code' =&gt; 'jwt_auth_valid_token',\n                'data' =&gt; array(\n                    'status' =&gt; 200,\n                )\n            );\n            \/** If the output is true return an answer to the request to show it *\/\n            return apply_filters('jwt_auth_validate_token', $value, $token);<\/p>\n\n<p>Now you have done,\nthe plugin should be able to add new values by adding a filter<\/p>\n\n<p>Note :\nIf you updated the jwt plugin,\nyou should again edit the code because it will be removed<\/p>\n\n<h3>REQUIREMENTS<\/h3>\n\n<p><a href=\"https:\/\/wordpress.org\/plugins\/jwt-authentication-for-wp-rest-api\/\">JWT Authentication for WP REST API Plugin<\/a><\/p>\n\n<!--section=faq-->\n<dl>\n<dt id='how%20to%20use%20this%20plugin%20%3F'><h3>How To Use This Plugin ?<\/h3><\/dt>\n<dd><p>Just install it to your wordpress site, and no another action required, but if you want to add the user fields to validate token endpoint,\nplease make sure that you have edit the jwt plugin code, Please read description for more information<\/p><\/dd>\n\n<\/dl>\n\n<!--section=changelog-->\n<p>.<\/p>","raw_excerpt":"Wordpress is a good content mangement system for building websites, but it will be better if you build like mobile apps,","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin\/136981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin"}],"about":[{"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/types\/plugin"}],"replies":[{"embeddable":true,"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/comments?post=136981"}],"author":[{"embeddable":true,"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wporg\/v1\/users\/ahmedriyadh"}],"wp:attachment":[{"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/media?parent=136981"}],"wp:term":[{"taxonomy":"plugin_section","embeddable":true,"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_section?post=136981"},{"taxonomy":"plugin_tags","embeddable":true,"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_tags?post=136981"},{"taxonomy":"plugin_category","embeddable":true,"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_category?post=136981"},{"taxonomy":"plugin_contributors","embeddable":true,"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_contributors?post=136981"},{"taxonomy":"plugin_business_model","embeddable":true,"href":"https:\/\/he.wordpress.org\/plugins\/wp-json\/wp\/v2\/plugin_business_model?post=136981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}