JWT Authentication for CoCart.
You will need CoCart v3.8.1 or above to use this plugin.
Most shared hosts have disabled the HTTP Authorization Header by default.
To enable this option you'll need to edit your .htaccess file by adding the following:
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
or
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
To enable this option you'll need to edit your .htaccess file by adding the following (see this issue):
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
- Set a unique secret key in your
wp-config.php
file defined toCOCART_JWT_AUTH_SECRET_KEY
. - Install and activate plugin.
By default, the token expires after two full days but can be filtered to change to your preference using this hook cocart_jwt_auth_expire
.
Here is an example changing it to expire after just 2 hours.
add_filter( 'cocart_jwt_auth_expire', function() {
return MINUTE_IN_SECONDS * 120
});
- Authenticate via basic method with the login endpoint to get your token.
- Store the given token under
jwt_token
in your application. - Now authenticate any cart route with
Bearer
authentication with the token given.
If you find an issue, please report the issue. Thank you.
We have different channels at your disposal where you can find information about the CoCart project, discuss it and get involved:
- 📖 Docs: this is the place to learn how to use CoCart API. Get started!
- 🧰 Resources: this is the hub of all CoCart resources to help you build a headless store. Get resources!
- 👪 Community: use our Discord chat room to share any doubts, feedback and meet great people. This is your place too to share how are you planning to use CoCart!
- 🐞 GitHub: we use GitHub for bugs and pull requests, doubts are solved with the community.
- 🐦 Social media: a more informal place to interact with CoCart users, reach out to us on Twitter.
- 💌 Newsletter: do you want to receive the latest plugin updates and news? Subscribe here.
Released under GNU General Public License v3.0.
Website cocartapi.com · GitHub @co-cart · Twitter @cocartapi
CoCart JWT Authentication is developed and maintained by Sébastien Dumont. Founder of CoCart Headless, LLC.
Website sebastiendumont.com · GitHub @seb86 · Twitter @sebd86