承接 nicumicle/simple-jwt-login-client-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nicumicle/simple-jwt-login-client-php

Composer 安装命令:

composer require nicumicle/simple-jwt-login-client-php

包简介

Simple JWT Login Client composer package

README 文档

README

Latest Stable Version Total Downloads License PHP Version Require

The simple-jwt-login PHP client

This client will help you integrate your PHP Application with a WordPress website that is using the simple-jwt-login WordPress plugin.

Requirements

  • PHP : >=5.6
  • curl extension

Installation

    composer require nicumicle/simple-jwt-login-client-php

Simple Example

    $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com');
    
    $result = $simpleJwtLogin->registerUser('email@test.com', 'My-password');
    
    //var_dump($result); 

The output of result will be the actual API call result.

How to use it

Login User

In order to autologin, you will need to redirect to the WordPress website, with the generated URL:

    $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1');
    header('Location: ' . $simpleJwtLogin->getAutologinUrl('My JWT', 'AUTH CODE', 'https://test.com'));

The Auth Code parameter is optional. You can set it to null If you don't want to use it.

Register User

This will register a new user.

    $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1');
    $result = $simpleJwtLogin->registerUser('email@simplejwtlogin.com', 'password', 'AUTH CODE');

The Auth Code parameter is optional. You can set it to null If you don't want to use it.

The $result value is:

Array
(
    [success] => true
    [id] => 1
    [message] => User was successfully created.
    [user] => Array
        (
            [ID] => 1
            [user_login] => test@simplejwtlogin.com
            [user_nicename] => test@simplejwtlogin.com
            [user_email] => test@simplejwtlogin.com
            [user_url] => 
            [user_registered] => 2021-28-01 15:30:37
            [user_activation_key] => 
            [user_status] => 0
            [display_name] => test@simplejwtlogin.com
            [user_level] => 10
        )

    [jwt] => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
)

Delete User

This will delete a user.

    $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1');
    $result = $simpleJwtLogin->deleteUser('Your JWT here', 'AUTH CODE');

The Auth Code parameter is optional. You can set it to null If you don't want to use it.

The $result value is:

Array
(
    [message] => User was successfully deleted.
    [id] => 1
)

Reset Password

This will send the reset password email.

    $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1');
    $result = $simpleJwtLogin->resetPassword('email@simplejwtlogin.com', 'AUTH CODE');

The Auth Code parameter is optional. You can set it to null If you don't want to use it.

The $result value is:

Array
(
    [success] => true
    [message] => Reset password email has been sent.
)

Change password

This will send the reset password email. The Auth Code parameter is optional. You can set it to null If you don't want to use it.

The following code part, will change the user password, using the reset password code:

    $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1');
    $result = $simpleJwtLogin->changePassword('email@simplejwtlogin.com', 'new password', 'code', null, 'AUTH CODE');

The following code part, will change the user password, using a JWT:

    $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1');
    $result = $simpleJwtLogin->changePassword('email@simplejwtlogin.com', 'new password', null, 'Your JWT here', 'AUTH CODE');

The $result value is:

Array
(
    [success] => true
    [message] => User Password has been changed.
)

Authenticate User

The Auth Code parameter is optional. You can set it to null If you don't want to use it.

Authenticate

This will generate a JWT based on user credentials.

    $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1');
    $result = $simpleJwtLogin->authenticate('email@simplejwtlogin.com', 'your password', 'AUTH CODE');

The $result value is:

Array
(
    [success] => true
    [data] => Array
        (
            [jwt] => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
        )

)

Refresh token

+The following code will refresh an expired token:

    $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1');
    $result = $simpleJwtLogin->refreshToken('your JWT here', 'AUTH CODE');

The $result value is:

Array
(
    [success] => true
    [data] => Array
        (
            [jwt] => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
        )

)

Validate token

The following code will check if your JWT is valid or not:

   $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1');
    $result = $simpleJwtLogin->validateToken('your JWT here', 'AUTH CODE');

The $result value is:

Array
(
    [success] => true
    [data] => Array
        (
            [user] => Array
                (
                    [ID] => 1
                    [user_login] => test@simplejwtlogin.com
                    [user_nicename] => test@simplejwtlogin.com
                    [user_email] => test@simplejwtlogin.com
                    [user_url] => https://simplejwtlogin.com
                    [user_registered] => 2021-28-01 15:30:37
                    [user_activation_key] => 
                    [user_status] => 0
                    [display_name] => test@simplejwtlogin.com
                )

            [jwt] => Array
                (
                    [0] => Array
                        (
                            [token] => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
                            [header] => Array
                                (
                                    [typ] => JWT
                                    [alg] => HS256
                                )

                            [payload] => Array
                                (
                                    [iat] => 1638459037
                                    [email] => test@simplejwtlogin.com
                                    [id] => 1
                                    [site] => http://localhost
                                    [username] => test@simplejwtlogin.com
                                )

                        )

                )

        )

)

Revoke token

The following code will invalidate a JWT:

   $simpleJwtLogin = new SimpleJwtLoginClient('https://mydomain.com', '/simple-jwt-login/v1'); 
   $result = $simpleJwtLogin->revokeToken('your JWT here', 'AUTH CODE');

The $result value is:

Array
(
    [success] => true
    [message] => Token was revoked.
    [data] => Array
        (
            [jwt] => Array
                (
                    [0] => eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
                )
        )
)

统计信息

  • 总下载量: 2.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2021-12-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固