Title: User Data Fields For JWT Authentication
Author: Ahmed Hnewa
Published: <strong>February 24, 2021</strong>
Last modified: August 1, 2022

---

Search plugins

This plugin **hasn’t been tested with the latest 3 major releases of WordPress**.
It may no longer be maintained or supported and may have compatibility issues when
used with more recent versions of WordPress.

![](https://ps.w.org/custom-fields-for-jwt-authentication-for-wp-rest-api/assets/
icon-128x128.png?rev=2480516)

# User Data Fields For JWT Authentication

 By [Ahmed Hnewa](https://profiles.wordpress.org/ahmedriyadh/)

[Download](https://downloads.wordpress.org/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api.1.2.1.zip)

 * [Details](https://pcd.wordpress.org/plugins/custom-fields-for-jwt-authentication-for-wp-rest-api/#description)
 * [Reviews](https://pcd.wordpress.org/plugins/custom-fields-for-jwt-authentication-for-wp-rest-api/#reviews)
 * [Development](https://pcd.wordpress.org/plugins/custom-fields-for-jwt-authentication-for-wp-rest-api/#developers)

 [Support](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/)

## Description

WordPress is a good content mangement system for building websites, but it will 
be better if you build like mobile apps,
 With the wordpress rest api you can create
posts, edit posts, view posts, Users, Uploading Media etc… but the problem with 
the wordpress rest api it does not provide any authentication methods for third 
party application like mobile apps The Jwt Plugin on wordpress.org does provide 
that

and this plugin is just a addon for that plugin

So this plugin is useful if you don’t want to make another request to fetch user
data like Id etc..
 because you have to get the id of the user in ordet to get all
data

It really simple plugin
 it writed with 50 lines of code, the size of the plugin
is 3Kb

Note: This Is Plugin For
 [JWT Authentication for WP REST API Plugin](https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/)

so if the jwt authentication plugin is not installed
 this plugin will not add the
fields to it endpoints

and the fields will be added only if the token is getted successfully

Example request (before install the plugin):
 {     “token”: “eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.
eyJpc3MiOiJodHRwOlwvXC8xOTIuMTY4LjAuMTgyIiwiaWF0IjoxNjE0MDg3NDQ2LCJuYmYiOjE2MTQwODc0NDYsImV4cCI6MTYxNDY5MjI0NiwiZGF0YSI6eyJ1c2VyIjp7ImlkIjoiMSJ9fX0.
KeAUc7PiTne0_PThsSAWo1ruvl2Ocu-fbCn2jG7zkoE”,     “user_email”: “example@example.
com”,     “user_nicename”: “admin”,     “user_display_name”: “admin” }

Example response (after install the plugin):
 {     “token”: “eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.
eyJpc3MiOiJodHRwOlwvXC8xOTIuMTY4LjAuMTgyIiwiaWF0IjoxNjE0MDg2NjQyLCJuYmYiOjE2MTQwODY2NDIsImV4cCI6MTYxNDY5MTQ0MiwiZGF0YSI6eyJ1c2VyIjp7ImlkIjoiMSJ9fX0.
nyDOICdQcZKbWZo2kQRp_eLBkuxjnK_rpxs-HJREyCg”,     “user_email”: “example@example.
com”,     “user_nicename”: “admin”,     “user_display_name”: “admin”,     “user_id”:
1,     “user_login”: “admin”,     “user_first_name”: “sfd”,     “user_last_name”:“”,“
user_roles”: [         “administrator”     ],     “user_role”: “administrator”, “
user_registered”: “2021-02-17 09:21:29”,     “user_url”: “http://localhost”,    “
user_status”: “0”,     “user_avatar_url”: “https://secure.gravatar.com/avatar/22feea4605ac5b7163eac439b5241034?
s=96&d=mm&r=g”,     “user_activation_key”: “” }

Of course you can add the code of this plugin to your Theme,
 but this is not recommened
because when you change the theme or update it the changes will revert back, you
can create child theme for that but instead you can just install this simple plugin

Don’t forget to setup (JwtAuthenticatonForWordpress)[https://wordpress.org/plugins/
jwt-authentication-for-wp-rest-api/]

[Github](https://github.com/ahmedhnewa/user-data-fields-jwt-plugin)

### Can Add User Data Fields To Validate Token Endpoint ?

This plugin can also add user data fields to validate token endpoint,

Unfortunately, the jwt extension does not support using the filter for validate_token
function,
 So You Will Need To Modify Some Codes Inside Jwt Plugin Codes Go To \
wp-content\plugins\jwt-authentication-for-wp-rest-api\public\class-jwt-auth-public.
php And At The End Of Function That Named validate_token In Line 302

Edit This Code
 From : /** If the output is true return an answer to the request
to show it */ return array( ‘code’ => ‘jwt_auth_valid_token’, ‘data’ => array( ‘
status’ => 200, ), ); To : $value = array( ‘code’ => ‘jwt_auth_valid_token’, ‘data’
=> array( ‘status’ => 200, ) ); /** If the output is true return an answer to the
request to show it */ return apply_filters(‘jwt_auth_validate_token’, $value, $token);

Now you have done,
 the plugin should be able to add new values by adding a filter

Note :
 If you updated the jwt plugin, you should again edit the code because it
will be removed

### REQUIREMENTS

[JWT Authentication for WP REST API Plugin](https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/)

## Screenshots

 * [[
 * This is when get token response
 * [[
 * This Is when get validate token response

## FAQ

### How To Use This Plugin ?

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,
 please make sure that you
have edit the jwt plugin code, Please read description for more information

## Reviews

![](https://secure.gravatar.com/avatar/7e50b8b988f11ce3da0d6e6ff9ec6dc0047509017fc4587311d855ee4e4039ce?
s=60&d=retro&r=g)

### 󠀁[This a great plugin](https://wordpress.org/support/topic/this-a-great-plugin-2/)󠁿

 [innoxgraphics](https://profiles.wordpress.org/innoxgraphics/) August 24, 2021

I just wanted to thank the author for making such great plugins 😊

![](https://secure.gravatar.com/avatar/a67655dd695a0ed7fd779cf08b7f4f75caf1ddd75a10a4e75e90a61cd9fc13b0?
s=60&d=retro&r=g)

### 󠀁[Well Self Usage Plugin](https://wordpress.org/support/topic/well-self-usage-plugin/)󠁿

 [Wilson](https://profiles.wordpress.org/mtoolstec/) July 26, 2021

The JWT team should add a filter for validating requests too.

![](https://secure.gravatar.com/avatar/1b858abea6bc56a08cb57bae336d91f75daeb45f7cbc34092c67e52af1894485?
s=60&d=retro&r=g)

### 󠀁[Good And Very Simple Plugin For Jwt Authentication](https://wordpress.org/support/topic/good-and-very-simple-plugin-for-jwt-authentication/)󠁿

 [Ahmed Hnewa](https://profiles.wordpress.org/ahmedriyadh/) February 24, 2021

I Used It For My Own Sites 😅

 [ Read all 3 reviews ](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/reviews/)

## Contributors & Developers

“User Data Fields For JWT Authentication” is open source software. The following
people have contributed to this plugin.

Contributors

 *   [ Ahmed Hnewa ](https://profiles.wordpress.org/ahmedriyadh/)

[Translate “User Data Fields For JWT Authentication” into your language.](https://translate.wordpress.org/projects/wp-plugins/custom-fields-for-jwt-authentication-for-wp-rest-api)

### Interested in development?

[Browse the code](https://plugins.trac.wordpress.org/browser/custom-fields-for-jwt-authentication-for-wp-rest-api/),
check out the [SVN repository](https://plugins.svn.wordpress.org/custom-fields-for-jwt-authentication-for-wp-rest-api/),
or subscribe to the [development log](https://plugins.trac.wordpress.org/log/custom-fields-for-jwt-authentication-for-wp-rest-api/)
by [RSS](https://plugins.trac.wordpress.org/log/custom-fields-for-jwt-authentication-for-wp-rest-api/?limit=100&mode=stop_on_copy&format=rss).

## Changelog

.

## Meta

 *  Version **1.2.1**
 *  Last updated **4 years ago**
 *  Active installations **40+**
 *  Tested up to **6.0.11**
 *  Language
 * [English (US)](https://wordpress.org/plugins/custom-fields-for-jwt-authentication-for-wp-rest-api/)
 * Tags
 * [json web authentication](https://pcd.wordpress.org/plugins/tags/json-web-authentication/)
   [jwt](https://pcd.wordpress.org/plugins/tags/jwt/)[wp-api](https://pcd.wordpress.org/plugins/tags/wp-api/)
   [wp-json](https://pcd.wordpress.org/plugins/tags/wp-json/)
 *  [Advanced View](https://pcd.wordpress.org/plugins/custom-fields-for-jwt-authentication-for-wp-rest-api/advanced/)

## Ratings

 5 out of 5 stars.

 *  [  3 5-star reviews     ](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/reviews/?filter=5)
 *  [  0 4-star reviews     ](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/reviews/?filter=4)
 *  [  0 3-star reviews     ](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/reviews/?filter=3)
 *  [  0 2-star reviews     ](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/reviews/?filter=2)
 *  [  0 1-star reviews     ](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/reviews/#new-post)

[See all reviews](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/reviews/)

## Contributors

 *   [ Ahmed Hnewa ](https://profiles.wordpress.org/ahmedriyadh/)

## Support

Got something to say? Need help?

 [View support forum](https://wordpress.org/support/plugin/custom-fields-for-jwt-authentication-for-wp-rest-api/)