Authentication
How the WPLMS Authentication works.
The Version 4 comes with a JWT login system which means the authentication happens in a browser. Which means that when a page is loaded the WordPress is not aware of which user is accessing the page. Now, this means that the server will always render the page as a static and you will be able to host your sites 100% cached, or even static HTML pages.
The benefit of using JWT tokens is huge both in terms of Loading speed and scalability. The WPLMS can work as a part of your site without impacting the overall site performance. That is "Do not convert your entire site into an LMS instead chose only a specific part of your site to work as LMS". This is only possible if we migrate away from the WordPress cookie based authentication structure to a JWT based login system.
Generating the Token
The VibeBP plugin uses the function : vibebp_generate_token($user)
for generating the token for the user. The $user is the a user object see below
There is further possibility to process the token using the filter and modify the user object stored in the token. For example, course data can be added to the token. However as JWT tokens are sometimes sent in request header, we recommend keeping the size to a limited less than 8kb.
Expanding the Token
In almost all addon / plugins that you will create you will be required to expand the JWT token sent in the API request. You can expand the JWT token can capture the User making the request. There are 2 ways to expand the token :
Use the VibeBP Filter on the Token:
$user = apply_filters('vibebp_api_get_user_from_token','',$body['token']);
Use the
vibebp_expand_token($token)
function
Both above ways are correct. See following code snippet from our Vibe Zoom addon for expanding the token :
The token also have an expiry value that the administrator sets in the WP admin - VibeBP - Settings - General.
This token is also used in Amazon S3 uploads in S3 plugin, Vimeo Uploads in VideoVibe Plugin.
Last updated