Php rest api authorization: bearer

so, i have a problem here. i already make the provider and requestor. it runs okay and success, then i want to make the authentication with bearer token but there is no example of it. i try to search any documentation about it but i cant find any. is anyone know how to do that? i just have this kind of example about auth using bearer token but i dont know how to do it

this is the example of the auth with bearer token


is anyone know how to do that?

this is my requestor








    $.getJSON["//localhost/webservice/webprovider.php", function[result]{
        console.log[result];
        $.each[result.product,function[i] { 
            document.getElementById["rowProduct"].innerHTML +=
            "" + result.product[i].id +
            "" + result.product[i].kategori +
            "" + result.product[i].nama +
            "" + result.product[i].deskripsi +
            "" + result.product[i].berat +
            "" + result.product[i].harga +
            "" + result.product[i].stock +
            "" + result.product[i].attribut[0].warna + 
            "" + result.product[i].attribut[0].ukuran + 
            "" + result.product[i].attribut[0].jenis_bahan + 
            "" + result.product[i].attribut[0].motif + 
            "" + result.product[i].attribut[0].penutup + 
            "";
        }];
    }];



Data Product Wunjoess

ID Kategori Nama Deskripsi Berat Harga Stock Warna Ukuran Jenis Bahan Motif Penutup

Introduction

Here in this tutorial, PHP REST API authentication using JWT, you will see how to use JWT [JSON Web Token] to authorize users and allow them to continue their works once they are logged in using their regular credentials [usernames and passwords]. Users use their credentials to get the JWTs and continue their work until JWTs expire. In this example, I will not use any third party library to generate JWT.

You might have seen how to generate and validate JWT using PHP language without using any third party library. Here I will use the same concept to generate the JWT for individual user and allow him/her continue his/her work until JWT expires.

I will create REST APIs in PHP for individual functionality, such as, for login I will create a separate REST API, for registration I will craete a separate REST API.

Prerequisites

PHP 7.3.5 – 7.4.23, Apache 2.4 [Optional], MySQL 8.0.17 – 8.0.26, REST Client – Talend, Postman, Firefox, etc.

MySQL Table

Create a table user in MySQL server under roytuts database.

CREATE TABLE `user` [
  `id` int NOT NULL AUTO_INCREMENT,
  `username` varchar[45] DEFAULT NULL,
  `password` varchar[255] DEFAULT NULL,
  PRIMARY KEY [`id`]
] ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

I insert one row with sample data into the database to test the application right away:

insert into user[`username`, `password`] value[‘roy’, ‘roy’];

Project Directory

It’s assumed that you have setup Apache [Optional, you can use built-in PHP development server], PHP and MySQL in Windows system.

Now I will create a project root directory called php-jwt-rest-authentication under the Apache server’s htdocs folder. I may not mention the project root directory in subsequent sections and I will assume that I am talking with respect to the project root directory.

Database Configuration

Create db.php file for various database operations, such as, inserting data into MySQL database, selecting data from MySQL database, etc. Please do not forget to change the database credentials as per your database.

Chủ Đề