PHP Classes

PHP JWT Library API Base: Send authenticated API requests using JWT

Recommend this page to a friend!
  Info   View files Example   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 185 All time: 8,647 This week: 524Up
Version License PHP version Categories
jwtapibase 1.0.0GNU General Publi...5PHP 5, Web services
Description 

Author

This class can send authenticated API requests using JWT.

It takes a user name and password and obtains a JSON Web Token from a API Web server.

The class can also send authenticated requests to a specified API URL passing given parameters and the previously obtained JSON Web Token.

Innovation Award
PHP Programming Innovation award nominee
June 2017
Number 10
JWT (JSON Web Token) is an object represented as a JSON string that contains information to be transmitted securely between two parties.

This class can obtain a JSON Web Token from a server obtained by password based authenticated.

It will be use to send authenticated requests to an API server.

Manuel Lemos
Picture of andy honeycutt
Name: andy honeycutt <contact>
Classes: 5 packages by
Country: United States United States
Age: 43
All time rank: 1525228 in United States United States
Week rank: 295 Up34 in United States United States Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php
require_once("class.jwtapibase.php");

$url = 'http://api.somewhere.in.the.universe.com/';
$username = 'myUsername';
$password = 'myPassword';

$client = new JWTApiBase($url, $username, $password);


// Perhaps we want to update the email address of user at 1234
$data = json_encode(array(
 
'id' => '1234',
 
'email_address' => 'me@andyhoneycutt.com'
));

// append the endpoint "user/" to our client base url, send our data to it
$response = $client->apiRequest($data, $client->getUrl('user/'));

// print out the repsonse
print_r($response);
print_r(json_decode($response));


Details

README

JWT Api Base is a simple wrapper class for handling JWT auth and endpoint requests.

Configure

Modify the first few lines to define the api base auth URL for your JWT-auth enabled API, if needed change the username and password parameters to mirror the username and password fields required by your API provider.

For example:

define("URL_SUFFIX_AUTH", 'api-auth/');
define("PARAM_USERNAME", 'username');
define("PARAM_PASSWORD", 'password');

Changes to:

define("URL_SUFFIX_AUTH", 'jwt-auth/');
define("PARAM_USERNAME", 'user');
define("PARAM_PASSWORD", 'pass');

  Files folder image Files  
File Role Description
Plain text file class.jwtapibase.php Class Class source
Accessible without login Plain text file jwtclient_example.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
 100%
Total:185
This week:0
All time:8,647
This week:524Up
User Comments (1)
This is a bad and fake JWT library.
6 years ago (Andres Separ)
0%Star