Skip to content

cocart-headless/cocart-jwt-authentication

Repository files navigation

CoCart - JWT Authentication

Licence WordPress Plugin Downloads

JWT Authentication for CoCart.

Minimum Requirements

You will need CoCart v3.8.1 or above to use this plugin.

Enable PHP HTTP Authorization Header

Shared Hosts

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}]

WPEngine

To enable this option you'll need to edit your .htaccess file by adding the following (see this issue):

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1

Configuration

  1. Set a unique secret key in your wp-config.php file defined to COCART_JWT_AUTH_SECRET_KEY.
  2. Install and activate plugin.

Token Expiration

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
});

Usage

  1. Authenticate via basic method with the login endpoint to get your token.
  2. Store the given token under jwt_token in your application.
  3. Now authenticate any cart route with Bearer authentication with the token given.

Bugs

If you find an issue, please report the issue. Thank you.


CoCart Channels

We have different channels at your disposal where you can find information about the CoCart project, discuss it and get involved:

Twitter: cocartapi CoCart GitHub Stars

  • 📖 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.

License

License

Released under GNU General Public License v3.0.

Credits

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