Title: GS JWT Authentication for WP REST API
Author: Gaurav Sharma
Published: <strong>11.01.2022</strong>
Last modified: 13.01.2022

---

Поиск плагинов

![](https://ps.w.org/gs-jwt-auth-and-otp-varification/assets/banner-772x250.png?
rev=2656993)

Этот плагин **не тестировался с последними 3 основными выпусками WordPress**. Скорее
всего, он уже не поддерживается и может быть несовместим с текущими версиями WordPress.

![](https://ps.w.org/gs-jwt-auth-and-otp-varification/assets/icon.svg?rev=2656993)

# GS JWT Authentication for WP REST API

 Автор: [Gaurav Sharma](https://profiles.wordpress.org/gauravin213/)

[Скачать](https://downloads.wordpress.org/plugin/gs-jwt-auth-and-otp-varification.1.0.0.zip)

 * [Детали](https://ru.wordpress.org/plugins/gs-jwt-auth-and-otp-varification/#description)
 * [Отзывы](https://ru.wordpress.org/plugins/gs-jwt-auth-and-otp-varification/#reviews)
 * [Разработка](https://ru.wordpress.org/plugins/gs-jwt-auth-and-otp-varification/#developers)

 [Поддержка](https://wordpress.org/support/plugin/gs-jwt-auth-and-otp-varification/)

## Описание

Extends the WP REST API using JSON Web Tokens as an authentication method.
 GS JWT
plugin provides to encode and decode JSON Web Tokens (JWT), conforming to RFC 7519.

GET OTP and send notification by mail or SMS service

**Support and Requests please in Github:** https://github.com/gauravin213/gs-jwt

### REQUIREMENTS

### PHP

**Minimum PHP version: 5.3.0**

### PHP HTTP Authorization Header enable

Most of the shared hosting has disabled the **HTTP Authorization Header** by default.

To enable this option you’ll need to edit your **.htaccess** file adding the following

    ```
    RewriteEngine on
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
    ```

#### WPENGINE

To enable this option you’ll need to edit your **.htaccess** file adding the following

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

#### CONFIGURATION

The JWT needs to Add constant in the wp-confige.php file

    ```
    define( 'GS_WP_JWT_SECRET_KEY', 'your-top-secret-key' );
    define( 'GS_WP_JWT_ALGO', 'HS256' );
    define( 'GS_WP_JWT_EXPIRY', (60 * 60) ); //seconds * minuts
    define( 'GS_WP_OTP_EXPIRY', 10);  //minuts
    ```

### Namespace and Endpoints

When the plugin is activated, a new namespace is added

    ```
    /gs-jwt/v1
    ```

Also, two new endpoints are added to this namespace

Endpoint | HTTP Verb

_/wp-json/gs-jwt/v1/login_ | POST

_/wp-json/gs-jwt/v1/token/validate_ | POST

_/wp-json/gs-jwt/v1/get-otp_ | POST

_/wp-json/gs-jwt/v1/verify-otp_ | POST

_/wp-json/gs-jwt/v1/register\_user_ | POST

_/wp-json/gs-jwt/v1/register\_userbymobile_ | POST

### USAGE

 1. Get JSON web token

#### Request method:

    ```
    POST /wp-json/gs-jwt/v1/login

    Body{
        "username": "enter username",
        "password": "enter password"
    }
    ```

#### Reponse

    ```
    {
        "data": {
            "id": "1",
            "user_login": "admin",
            "user_pass": null,
            "user_nicename": "admin",
            "user_email": "example@gmail.com",
            "user_url": "",
            "user_registered": "2020-08-11 07:35:37",
            "user_activation_key": "",
            "user_status": "0",
            "display_name": "admin",
            "roles": [
                "administrator"
            ],
            "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjFcL3dvcmRwcmVzcyIsImlhdCI6MTY0MTk3MDIwNSwibmJmIjoxNjQxOTcwMjA1LCJleHAiOjE2NDE5NzM4MDUsImRhdGEiOnsidXNlciI6eyJpZCI6IjEifX19.gRF_aNsmhQ8kqXYdKbm6dIA7zTlhcCU-e_cpP9pQDyM"
        }
    }
    ```

 1. Validate JSON web token

#### Request method:

    ```
    POST /wp-json/gs-jwt/v1/token/validate

    Make a POST request sending the Authorization header
    Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjFcL3dvcmRwcmVzcyIsImlhdCI6MTY0MTk3MDIwNSwibmJmIjoxNjQxOTcwMjA1LCJleHAiOjE2NDE5NzM4MDUsImRhdGEiOnsidXNlciI6eyJpZCI6IjEifX19.gRF_aNsmhQ8kqXYdKbm6dIA7zTlhcCU-e_cpP9pQDyM
    ```

#### Reponse

    ```
    {
        "code": "jwt_auth_valid_token",
        "data": {
            "status": 200
        }
    }
    ```

 1. Get otp by billing mobile number

#### Request method:

    ```
    POST /wp-json/gs-jwt/v1/get-otp

    Body{
        "mobile": "enter mobile number"
    }
    ```

#### Reponse

    ```
    {
        "data": {
            "otp": 249225,
            "message": "SUCCESS",
            "otp_use_staus": "0",
            "notification": {
                "mail_send_status": 0,
                "sms_send_status": 0
            }
        }
    }
    ```

 1. Verify otp and mobile number to login

#### Request method:

    ```
    POST /wp-json/gs-jwt/v1/verify-otp

    Body{
        "otp": "enter otp",
        "mobile": "enter mobile number"
    }
    ```

#### Reponse

    ```
    {
        "data": {
            "id": "1",
            "user_login": "admin",
            "user_pass": null,
            "user_nicename": "admin",
            "user_email": "example@gmail.com",
            "user_url": "",
            "user_registered": "2020-08-11 07:35:37",
            "user_activation_key": "",
            "user_status": "0",
            "display_name": "admin",
            "roles": [
                "administrator"
            ],
            "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC8xMjcuMC4wLjFcL3dvcmRwcmVzcyIsImlhdCI6MTY0MTk3MDIwNSwibmJmIjoxNjQxOTcwMjA1LCJleHAiOjE2NDE5NzM4MDUsImRhdGEiOnsidXNlciI6eyJpZCI6IjEifX19.gRF_aNsmhQ8kqXYdKbm6dIA7zTlhcCU-e_cpP9pQDyM"
        }
    }
    ```

 1. Register user

#### Request method:

    ```
    POST /wp-json/gs-jwt/v1/register_user

    Body{
        "username": "example",
        "password": "example@123",
        "email": "example@gmail.com",
        "mobile": "1122336699"
    }
    ```

#### Reponse

    ```
    {
        "data": {
            "id": 29,
            "user_login": "example",
            "user_pass": null,
            "user_nicename": "example",
            "user_email": "example@gmail.com",
            "user_url": "",
            "user_registered": "2022-01-12 07:45:29",
            "user_activation_key": "",
            "user_status": "0",
            "display_name": "example",
            "roles": [
                "customer"
            ],
            "billing_phone": "1122336699"
        },
        "code": 200,
        "message": "Registration was Successful"
    }
    ```

 1. Register user by mobile number

#### Request method:

    ```
    POST /wp-json/gs-jwt/v1/register_userbymobile

    Body{
        "mobile": "1122336699"
    }
    ```

#### Reponse

    ```
    {
        "data": {
            "id": 32,
            "user_login": "1144556638",
            "user_nicename": "1144556638",
            "user_registered": "2022-01-13 06:29:30",
            "display_name": "1144556638",
            "roles": [
                "customer"
            ],
            "billing_phone": "1144556638"
        },
        "code": 200,
        "message": "Registration was Successful"
    }
    ```

#### Sample add SMS and email notification

    ```
    /*
    * Send notification 
    * Default mail_send_status = 0, sms_send_status = 0
    */
    function gs_wp_jwt_send_notification_fun( $data, $user_id, $otp, $mobile ) {

      //Write mail send code here
      $from = get_option('admin_email');
      $to = get_user_meta($user_id, 'billing_email', true);
      $subject = "OTP Verification";
      $message = "OTP number: {$opt} will expire in 10 min";
      $headers = "From: ".$from;
      $result = wp_mail( $to, $subject, $message, $headers);

      if ($result) { 

        $data['mail_send_status'] = 1;

      } //end mail send


      //Write sms send api code here
      /*if ($sms_send_status) { 

        $data['sms_send_status'] = 1;

      } //ens sms send*/

      return $data;
    }
    add_filter( 'gs_wp_jwt_send_notification', 'gs_wp_jwt_send_notification_fun', 10, 4 );
    ```

## Скриншоты

[[

[[

[[

## Отзывы

Нет отзывов об этом плагине.

## Участники и разработчики

«GS JWT Authentication for WP REST API» — проект с открытым исходным кодом. В развитие
плагина внесли свой вклад следующие участники:

Участники

 *   [ Gaurav Sharma ](https://profiles.wordpress.org/gauravin213/)

[Перевести «GS JWT Authentication for WP REST API» на ваш язык.](https://translate.wordpress.org/projects/wp-plugins/gs-jwt-auth-and-otp-varification)

### Заинтересованы в разработке?

[Посмотрите код](https://plugins.trac.wordpress.org/browser/gs-jwt-auth-and-otp-varification/),
проверьте [SVN репозиторий](https://plugins.svn.wordpress.org/gs-jwt-auth-and-otp-varification/),
или подпишитесь на [журнал разработки](https://plugins.trac.wordpress.org/log/gs-jwt-auth-and-otp-varification/)
по [RSS](https://plugins.trac.wordpress.org/log/gs-jwt-auth-and-otp-varification/?limit=100&mode=stop_on_copy&format=rss).

## Журнал изменений

#### 1.0.0

 * jwt jsonwebtoken encoding user_id.
 * added new endpoint validate token.
 * added new endpoint register user.

#### 1.0.0

 * added new endpoint register_userbymobile.

## Мета

 *  Версия **1.0.0**
 *  Обновление: **5 лет назад**
 *  Активных установок: **10+**
 *  Версия WordPress ** 4.2 или выше **
 *  Совместим вплоть до: **5.8.18**
 *  Версия PHP ** 5.3.0 или выше **
 *  Язык
 * [English (US)](https://wordpress.org/plugins/gs-jwt-auth-and-otp-varification/)
 * Метки:
 * [json web authentication](https://ru.wordpress.org/plugins/tags/json-web-authentication/)
   [jwt](https://ru.wordpress.org/plugins/tags/jwt/)[otp](https://ru.wordpress.org/plugins/tags/otp/)
   [wp-api](https://ru.wordpress.org/plugins/tags/wp-api/)[wp-json](https://ru.wordpress.org/plugins/tags/wp-json/)
 *  [Дополнительно](https://ru.wordpress.org/plugins/gs-jwt-auth-and-otp-varification/advanced/)

## Оценки

Пока что нет ни одного отзыва.

[Ваш отзыв](https://wordpress.org/support/plugin/gs-jwt-auth-and-otp-varification/reviews/#new-post)

[Посмотреть всеотзывы](https://wordpress.org/support/plugin/gs-jwt-auth-and-otp-varification/reviews/)

## Участники

 *   [ Gaurav Sharma ](https://profiles.wordpress.org/gauravin213/)

## Поддержка

Есть что сказать? Нужна помощь?

 [Перейти в форум поддержки](https://wordpress.org/support/plugin/gs-jwt-auth-and-otp-varification/)