When the plugin is activated, a new namespace is added.
/jwt-auth/v1
Also, two new endpoints are added to this namespace.
Endpoint
HTTP Verb
/wp-json/jwt-auth/v1/token
POST
/wp-json/jwt-auth/v1/token/validate
POST
Usage
/wp-json/jwt-auth/v1/token
This is the entry point for the JWT Authentication.
Validates the user credentials, username and password, and returns a token to use in a future request to the API if the authentication is correct or error if the authentication fails.
Once you get the token, you must store it somewhere in your application, e.g. in a cookie or using localstorage.
From this point, you should pass this token to every API call.
Sample call using the Authorization header using AngularJS:
app.config( function( $httpProvider ) {$httpProvider.interceptors.push( [ '$q','$location','$cookies',function( $q, $location, $cookies ) {return {'request':function( config ) {config.headers =config.headers || {};//Assume that you store the token in a cookie.var globals =$cookies.getObject( 'globals' ) || {};//If the cookie has the CurrentUser and the token//add the Authorization header in each requestif ( globals.currentUser &&globals.currentUser.token ) {config.headers.Authorization ='Bearer '+globals.currentUser.token; }return config; } }; } ] );} );
The wp-api-jwt-auth will intercept every call to the server and will look for the authorization header, if the authorization header is present, it will try to decode the token and will set the user according with the data stored in it.
If the token is valid, the API call flow will continue as always.
Sample Headers
POST /resource HTTP/1.1
Host: server.example.com
Authorization: Bearer mF_s9.B5f-4.1JqM
Errors
If the token is invalid an error will be returned. Here are some samples of errors: