Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating Wordpress Authorization and Sign in with Android

I am trying to build a native Android app for the Wordpress site. I am making use of WP REST API v2 (https://wordpress.org/plugins/rest-api/) to fetch the posts and other required attributes. I require authenticating the user, for which i have used JWT Authentication for WP REST API (https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/) API to Generate and Validate token works fine. However when i try to pass the generated token in the header i keep getting the below error.

{
    "code": "jwt_auth_bad_config",
    "message": "JWT is not configurated properly, please contact the admin",
    "data": {
        "status": 403
    }
}

Any suggestions as to what is going wrong? Requesting help to get this thing running.

like image 360
kay14 Avatar asked Dec 23 '22 15:12

kay14


1 Answers

TL;DR; Move the definition of JWT_AUTH_SECRET_KEY to the top of your wp-config.php file

Detailed solution :

As stated in the installation doc of the plugin, the JWT needs a secret key to sign the token this secret key must be unique and never revealed.

Thus, you must add this line into your wp-config.php file

define('JWT_AUTH_SECRET_KEY', 'your-top-secrect-key');

However, what the doc does not say, is that you should not put this at the end of the file. Insert this line just after the other definitions (AUTH_KEY, SECURE_AUTH_KEY, ... NONCE_SALT), and the 403 error should be gone.

I guess that's because the definition of JWT_AUTH_SECRET_KEY must be done before require_once(ABSPATH . 'wp-settings.php');

like image 108
Orabîg Avatar answered Jan 05 '23 07:01

Orabîg