destruidorpt/laravel-sqrl-auth

Laravel和SQRL之间认证的包

v1.0.1 2020-06-10 09:36 UTC

This package is auto-updated.

Last update: 2024-09-10 19:36:48 UTC


README

Issues Stars License

简介

SQRL(安全、快速、可靠的登录)是一种开放的草稿标准,用于匿名和安全地识别和认证网站和Web应用的用户,旨在消除对远程网站的username和password认证。用户只需提供一个密码来解锁他们的签名密钥,这些密钥存储在他们的设备上,永远不会透露给任何网站。密码在存储签名密钥的设备上进行本地验证。

Laravel是一个免费、开源的PHP Web框架,由Taylor Otwell创建,旨在根据MVC(模型-视图-控制器)架构模式开发Web应用,并基于Symfony。Laravel的一个特点是具有专用依赖管理器的模块化包装系统。

以下项目包含一个laravel模块,用于将SQRL认证系统集成到任何laravel项目中。

支持的SQRL版本

此包支持的SQRL版本列表以及开发的功能。

我们建议阅读以下文档

SQRL版本1

  • SQRL认证;
  • SQRL问题(通过SQRL功能提出问题);
  • IP地址验证;
  • SQRL禁用(如果SQRL客户端这样要求,则在用户账户中禁用所有SQRL);
  • SQRL仅允许(如果SQRL客户端这样要求,则阻止任何普通登录,只允许通过SQRL认证);
  • SQRL硬锁(如果SQRL客户端这样要求,则阻止任何类型的恢复密码或账户);

要求

  • PHP >= 7.2.0
  • Laravel >= 6.0.0

安装

您可以在安装和演示视频中检查安装过程。

首先,安装laravel,并确保数据库连接设置正确。

composer require destruidorpt/laravel-sqrl-auth

然后运行以下命令创建必要的表:

php artisan migrate

将以下行添加到该文件 .env

APP_URL=https://sqrl.test               # This one already exists in the .env file is the URL of your aplicacion 

SQRL_KEY_DOMAIN=sqrl.test               # URL to yours SQRL Server without http:// and https://
SQRL_ROUTE_TO_SQRL_AUTH=/api/sqrl       # Route to SQRL Server API, it must be pointed to the controller `SQRLControllerAPI` in the function `sqrl()`
SQRL_URL_LOGIN=https://sqrl.test/login  # URL to your login page
SQRL_NONCE_MAX_AGE_MINUTES=5            # Max age in minutes of the valid nonce
SQRL_NONCE_SALT=RANDOM                  # Generate a random salt value to calculate the nonce

请确认在配置在 SQRL_ROUTE_TO_SQRL_AUTH(文件 .env)中的路由中未验证csrf token(可以禁用在 app/Http/Middleware/VerifyCsrfToken.php 的变量 $except 中,通过添加SQRL_ROUTE_TO_SQRL_AUTH中的信息)。(如果未禁用,则SQRL客户端将无法与SQRL服务器通信)。

下一步是将下面的路由复制到 routes/api.php,并在本例中将其粘贴到 SQRL_ROUTE_TO_SQRL_AUTH(文件 .env)的 SQRL_ROUTE_TO_SQRL_AUTH=/api/sqrl 下方。

Route::group(['namespace'=>'\DestruidorPT\LaravelSQRLAuth\App\Http\Controllers'], function() {
    Route::post('/sqrl', 'SQRL\SQRLControllerAPI@sqrl');                # Route of API SQRL
});

目前Laravel对每个用户的API调用有限制,如果你的Laravel项目限制了API调用,考虑调整以下文件。

App\Http\Kernel.php

$middlewareGroups 中编辑 apithrottle:60,1 值,如果你不希望Laravel锁定API调用,则取消注释 throttle:60,1

protected $middlewareGroups = [
        'api' => [
            'throttle:60,1', #edit this value 
            'bindings',
        ],
    ];

开发项目时的注意事项:SQRL只与https一起工作,这意味着你必须有证书正常工作。

配置日志系统

此配置为可选配置,但在出现任何问题时应强烈建议用于调试目的。如果您想在SQRL服务器和SQRL客户端之间注册或记录信息,这有助于调试,请按照以下步骤操作。

将以下代码放入 config\logging.php 文件中的 channels 数组中,这将按日分隔日志文件。

'LaravelSQRLAuth' => [
    'driver' => 'daily',
    'path' => storage_path('logs/LaravelSQRLAuth/' . date('Y/m/') . 'sqrl.log'), // add dynamic folder structure
    'level' => 'debug',
    'days' => 31, // set the maximum number of days in a month
]

关于使项目完全功能性的详细说明

以下我们将讨论如何逐步应用所有可用功能,如果您不理解,您始终可以查看 示例安装 章节,在那里您可以安装示例并查看如何实现,同时能够看到SQRL的工作。

它将分为以下部分

SQRL认证

这是将用户认证到网站的功能。第一步,为认证用户创建一个nonce并发送到您的登录视图,如下面的代码所示

return view('LaravelSQRLAuthExemples.login', SQRLController::getNewAuthNonce());

更多详细信息请参阅 生成认证nonce函数

第二步,检查您是否在 routes/api.php 中有下面的代码,这将与SQRL服务器通信并检查nonce是否已认证。

Route::group(['namespace'=>'\DestruidorPT\LaravelSQRLAuth\App\Http\Controllers'], function() {
    Route::get('/sqrl', 'SQRL\SQRLControllerAPI@checkIfisReady');       # Route to check if the nonce is verified
    Route::post('/sqrl', 'SQRL\SQRLControllerAPI@sqrl');                # Route of API SQRL
});

更多详细信息请参阅 SQRL API函数检查nonce是否准备就绪的API函数

第三步,在您的登录页面的任何位置放置下面的示例代码,这将作为用户使用SQRL客户端的链接和QR码。

<a class="mx-auto" id="sqrl" href="{{$url_login_sqrl}}" onclick="sqrlLinkClick(this);return true;" encoded-sqrl-url="{{$encoded_url_login_sqrl}}" tabindex="-1">
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/SQRL_icon_vector_outline.svg/1200px-SQRL_icon_vector_outline.svg.png" style="margin-left:30px;margin-top:30px" class="card-img sqrl-logo" border="0" alt=" SQRL Code - Click to authenticate your SQRL identity ">
    <p style="margin-left:30px;margin-top:20px"> {!! QrCode::size(100)->generate($url_login_sqrl); !!} </p>
</a>

有关 QR码生成器 的更多详细信息。

第四步,将脚本复制到您的HTML页面中,这将通过nonce值验证下一页是否准备就绪,它将每500毫秒检查一次(建议更改此值)。

<script>
    var syncQuery = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP.3.0');
    var url = '{{$check_state_on}}';	// the location of the SQRL server
    var newSync, lastSync, encodedSqrlUrl = false, sqrlScheme = true;
    var gifProbe = new Image(); 					// create an instance of a memory-based probe image
    var localhostRoot = 'https://:25519/';	// the SQRL client listener

    gifProbe.onload = function() {  // define our load-success function
        sqrlScheme = false;			// prevent retriggering of the SQRL QR code.
        document.location.href = localhostRoot + encodedSqrlUrl;
    };
    gifProbe.onerror = function() { // define our load-failure function
        setTimeout( function(){ gifProbe.src = localhostRoot + Date.now() + '.gif';	}, 250 );
    }
    function pollForNextPage() {
        if (document.hidden) {					// before probing for any page change, we check to 
            setTimeout(pollForNextPage, 5000);	// see whether the page is visible. If the user is 
            return;								// not viewing the page, check again in 5 seconds.
        }
        syncQuery.open( 'GET', url);	// the page is visible, so let's check for any update
        syncQuery.onreadystatechange = function() {
            if ( syncQuery.readyState === 4 ) {
                if ( syncQuery.status === 200 ) {
                    console.log(syncQuery.response);
                    var response = JSON.parse(syncQuery.response);
                    if(response.isReady == true) {
                        document.location.href = response.nextPage;
                    } else {
                        if(response.msg === "Time out, reload nonce!" || response.msg === "IP Doesnt Match!" || response.msg === "SQRL is disable for this user!") {
                            console.log(response.msg);
                            var div = document.getElementById("ErroMessage");
                            div.innerHTML = response.msg+" Reload The Page and try again! If you want to Authenticate by SQRL";
                            div.removeAttribute("hidden"); 
                        } else {
                            setTimeout(pollForNextPage, 500); // next check in 500 milliseconds 
                        }
                    }
                } else {
                    setTimeout(pollForNextPage, 500); // next check in 500 milliseconds 
                }
            }	
        };
        syncQuery.send(); // initiate the query to the 'sync.txt' object.
    };
    function sqrlLinkClick(e) {
        encodedSqrlUrl = e.getAttribute('encoded-sqrl-url');
        // if we have an encoded URL to jump to, initiate our GIF probing before jumping
        if ( encodedSqrlUrl ) { gifProbe.onerror(); };	// trigger the initial image probe query
    }
    pollForNextPage();
</script>

第五步是放置以下代码

if(isset($_GET["nut"]) && !empty($_GET["nut"])) { // Check if the nut exist or if it's past on URL https://site.test?nut=<nonce value>
    $object = SQRLController::getUserByOriginalNonceIfCanBeAuthenticated($_GET["nut"]); //Get the user by the original nonce
    if(isset($object)) { //Will be null if the nonce expired or is invalid
        if($object instanceof Sqrl_pubkey) { // This only happen when no SQRL Client is associated to the user, then Sqrl_pubkey from SQRL CLient is returned
            //new user
            return view('LaravelSQRLAuthExemples.newsqrl');//View for the user to create account or associate to one already created
        } else if($object > 0) { //This happen when SQRL Client is associated to a user, so the value is number and is the id of the user
            Auth::loginUsingId($object); //This is for authenticate the user with that id
        }
    }
}

在变量 SQRL_URL_LOGIN(文件 .env)所指的函数上(你可以在 routes/web.php 中看到函数名和控制器的名称)。你可以在下面的示例中看到 SQRL_URL_LOGIN(文件 .env)。

SQRL_URL_LOGIN=https://sqrl.test/login  # URL to your login page

routes/web.php:

Route::get('/login', 'LaravelSQRLAuthExemples\ExempleController@getAuthPage')->name('login');

完成,现在它将准备就绪以供使用和测试。

SQRL问题

这是SQRL应用程序询问用户的功能。第一步,创建一个nonce来询问用户并发送到您的登录视图,如下面的代码所示

$data = SQRLController::getNewQuestionNonce("https://sqrl.test/okbutton", "https://sqrl.test/cancelbutton", "Do you confirm 5$ tranfering?", "I accept", https://sqrl.test/iacceptbutton", "Cancel", https://sqrl.test/cancelbutton");
return view('LaravelSQRLAuthExemples.transfer', $data);

更多详细信息请参阅 生成问题nonce函数

第二步,检查您是否在 routes/api.php 中有下面的代码,这将与SQRL服务器通信并检查nonce是否已认证。

Route::group(['namespace'=>'\DestruidorPT\LaravelSQRLAuth\App\Http\Controllers'], function() {
    Route::get('/sqrl', 'SQRL\SQRLControllerAPI@checkIfisReady');       # Route to check if the nonce is verified
    Route::post('/sqrl', 'SQRL\SQRLControllerAPI@sqrl');                # Route of API SQRL
});

更多详细信息请参阅 SQRL API函数检查nonce是否准备就绪的API函数

第三步,在您的页面的任何位置放置下面的示例代码,这将作为用户使用SQRL客户端的链接和QR码。

<a class="mx-auto" id="sqrl" href="{{$url_question_sqrl}}" onclick="sqrlLinkClick(this);return true;" encoded-sqrl-url="{{$encoded_url_question_sqrl}}" tabindex="-1">
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/SQRL_icon_vector_outline.svg/1200px-SQRL_icon_vector_outline.svg.png" style="margin-left:30px;margin-top:30px" class="card-img sqrl-logo" border="0" alt=" SQRL Code - Click to authenticate your SQRL identity ">
    <p style="margin-left:30px;margin-top:20px"> {!! QrCode::size(100)->generate($url_question_sqrl); !!} </p>
</a>

有关 QR码生成器 的更多详细信息。

第四步,将脚本复制到您的HTML页面中,这将通过nonce值验证下一页是否准备就绪,它将每500毫秒检查一次(建议更改此值)。

<script>
    var syncQuery = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP.3.0');
    var url = '{{$check_state_on}}';	// the location of the SQRL server
    var newSync, lastSync, encodedSqrlUrl = false, sqrlScheme = true;
    var gifProbe = new Image(); 					// create an instance of a memory-based probe image
    var localhostRoot = 'https://:25519/';	// the SQRL client listener

    gifProbe.onload = function() {  // define our load-success function
        sqrlScheme = false;			// prevent retriggering of the SQRL QR code.
        document.location.href = localhostRoot + encodedSqrlUrl;
    };
    gifProbe.onerror = function() { // define our load-failure function
        setTimeout( function(){ gifProbe.src = localhostRoot + Date.now() + '.gif';	}, 250 );
    }
    function pollForNextPage() {
        if (document.hidden) {					// before probing for any page change, we check to 
            setTimeout(pollForNextPage, 500);	// see whether the page is visible. If the user is 
            return;								// not viewing the page, check again in 5 seconds.
        }
        syncQuery.open( 'GET', url);	// the page is visible, so let's check for any update
        syncQuery.onreadystatechange = function() {
            if ( syncQuery.readyState === 4 ) {
                if ( syncQuery.status === 200 ) {
                    console.log(syncQuery.response);
                    var response = JSON.parse(syncQuery.response);
                    if(response.isReady == true) {
                        if(response.btn) {
                            var div = document.getElementById("ErroMessage");
                            div.innerHTML = "Button "+response.btn+": "+response.msg;
                            if(response.nextPage) {
                                var a = document.createElement('a');
                                var linkText = document.createTextNode("Click here to go to button reference.");
                                a.appendChild(linkText);
                                a.title = "Button href";
                                a.href = response.nextPage;
                                div.appendChild(a);
                            }
                            div.removeAttribute("hidden"); 
                        }
                    } else {
                        if(response.msg === "Time out, reload nonce!" || response.msg === "IP Doesnt Match!" || response.msg === "SQRL is disable for this user!") {
                            console.log(response.msg);
                            var div = document.getElementById("ErroMessage");
                            div.innerHTML = response.msg+" Reload The Page and try again! If you want to Authenticate by SQRL";
                            div.removeAttribute("hidden"); 
                        } else {
                            setTimeout(pollForNextPage, 500);
                        }
                    }
                } else {
                    setTimeout(pollForNextPage, 500);
                }
            }	
        };
        syncQuery.send(); // initiate the query to the 'sync.txt' object.
    };
    function sqrlLinkClick(e) {
        encodedSqrlUrl = e.getAttribute('encoded-sqrl-url');
        // if we have an encoded URL to jump to, initiate our GIF probing before jumping
        if ( encodedSqrlUrl ) { gifProbe.onerror(); };	// trigger the initial image probe query
    }
    pollForNextPage();
</script>

第五步是在您的个人控制器中注册用户的选择,因为当用户选择选项时,它将被重定向到该URL,在该URL中您保存用户的选择。下一个URL取决于选择和第一步函数中提交的URL。

完成,现在它将准备就绪以供使用和测试。

IP地址验证

这是验证第一个nonce请求的IP地址与该nonce周围后续请求的IP地址是否相同的功能。在某些情况下,此检查未执行,例如SQRL客户端移动应用,因为这是一个没有相同IP地址的另一个设备,所以它被保存在请求中以便创建nonce。不需要实现,但了解您已经在项目中插入了这个功能是好的,因此在创建nonce时始终使用包中的函数,您可以在Sqrl_nonce->ip_address中检查IP地址。更多详细信息请参阅Sqrl_nonce

SQRL禁用

此功能用于SQRL客户端禁用SQRL身份验证或禁用SQRL客户端密钥。不需要实现,但了解您已经在项目中插入了这个功能是好的,要检查公钥是否已禁用,您可以检查Sqrl_pubkey->disabled,'0'表示未禁用,'1'表示已禁用。更多详细信息请参阅Sqrl_pubkey

SQRL仅允许

可选功能

此功能允许用户通过SQRL客户端应用程序阻止用户名和密码登录功能。

为了知道用户是否仅允许通过SQRL登录,您可以执行此功能

SQRLController::checkIfUserCanAuthByNormalLogin($user_id);

更多详细信息请参阅检查用户是否可以通过常规登录进行身份验证的功能。例如,您可以在允许用户身份验证之前添加此代码,检查是否允许

if(isset($user)){ //Check if the user exists
    if(!SQRLController::checkIfUserCanAuthByNormalLogin($user->id)) { //Check if the user can not be authentication by normal login authentication
        return redirect()->intended('login')->withErrors(['SQRL Only Allowed!!!']);//If returned false then the user only can authenticate by SQRL
    }
}

SQRL硬锁

可选功能

此功能允许用户锁定密码恢复功能,此功能由SQRL客户端应用程序启用。

为了知道用户是否已启用SQRL硬锁定,您可以执行此功能

SQRLController::checkIfUserCanUseRecoverPassword($user_id);

更多详细信息请参阅检查用户是否可以使用恢复密码的功能。例如,您可以在允许用户恢复其密码之前添加此代码,检查是否允许

if(isset($user)){ //Check if the user exists
    if(!SQRLController::checkIfUserCanUseRecoverPassword($user->id)) { //Check if the user can not recovery the password
        return redirect()->intended('resetpw')->withErrors(['SQRL not Allowed recovery account!!!']); //This means that the account as hardlocked by SQRL Client that not Allowed recovery password by email or personal questions
    }
}

示例安装

在继续此主题之前,您需要先遵循安装主题。

确保遵循以下步骤,以便您可以安装此示例。要开始,请运行以下命令。

php artisan vendor:publish --provider="DestruidorPT\LaravelSQRLAuth\LaravelSQRLAuthServiceProvider"

下一步是将以下路由复制到routes/api.php

Route::group(['namespace'=>'\DestruidorPT\LaravelSQRLAuth\App\Http\Controllers'], function() {
    Route::get('/sqrl', 'SQRL\SQRLControllerAPI@checkIfisReady');       # Route to check if the nonce is verified
    Route::post('/sqrl', 'SQRL\SQRLControllerAPI@sqrl');                # Route of API SQRL
});

最后,为了完成安装,您只需将以下路由复制到routes/web.php

Route::get('/', function () {
    return redirect('login');
});

Route::get('/login', 'LaravelSQRLAuthExemples\ExempleController@getAuthPage')->name('login');
Route::post('/login', 'LaravelSQRLAuthExemples\ExempleController@login');
Route::post('/logout', 'LaravelSQRLAuthExemples\ExempleController@logout')->name('logout');

Route::get('/dashboard', 'LaravelSQRLAuthExemples\ExempleController@getDashboardPage')->name('dashboard');

Route::post('/transfer', 'LaravelSQRLAuthExemples\ExempleController@getTransferConfirmation');

Route::get('/resetpw', 'LaravelSQRLAuthExemples\ExempleController@getResetPWPage')->name('resetpw');
Route::post('/resetpw', 'LaravelSQRLAuthExemples\ExempleController@resetPW');

Route::post('/newlogin', 'LaravelSQRLAuthExemples\ExempleController@newlogin');
Route::post('/newaccount', 'LaravelSQRLAuthExemples\ExempleController@newAcc');

类和数据

以下是数据库中保存的所有信息和使用的类。

类列表

Sqrl_nonce (DestruidorPT\LaravelSQRLAuth\App\Sqrl_nonce)

类Sqrl_nonce包含创建与SQRL服务器和SQRL客户端之间通信所需的所有信息。以下您可以找到所有数据

Sqrl_pubkey (DestruidorPT\LaravelSQRLAuth\App\Sqrl_pubkey)

类Sqrl_pubkey包含了解与用户相关的SQRL客户端所需的所有信息,换句话说,它包含了所有关于SQRL客户端密钥和用户相关的信息。以下您可以找到数据

可用函数

所有可用的功能列表,以实现所有可用的SQRL功能。

SQRLController (DestruidorPT\LaravelSQRLAuth\App\Http\Controllers\SQRL\SQRLController)

仅在您的服务器上使用此控制器。

生成认证nonce的函数

要生成已验证的nonce,您需要调用以下函数。

SQRLController::getNewAuthNonce();

此函数将返回此数组

[
    'nonce',                  <-- Nonce value,
    'check_state_on',         <-- Route to check if nonce was verified
    'url_login_sqrl',         <-- Url for sqrl client to receive
    'encoded_url_login_sqrl', <-- Endoded Base 64 URL(url for sqrl client to receive)
]

生成问题nonce的函数

要生成问题随机数,您需要调用以下函数。

SQRLController::getNewQuestionNonce($url, $can, $question, $btn1 = null, $url1 = null, $btn2 = null, $url2 = null);

此函数需要以下值

(
    $url,       <-- Url to Rederect user if he press ok
    $can,       <-- Url to Rederect user if he press cancel
    $question,  <-- String the question you want
    $btn1,      <-- Name of the first button opcion for user (is opcional, only requered if url1 is not null)
    $url1,      <-- Url to Rederect user if he press btn1 (is opcional)
    $btn2,      <-- Name of the secound button opcion for user (is opcional, only requered if url2 is not null)
    $url2       <-- Url to Rederect user if he press btn2 (is opcional)
)

此函数将返回此数组

[
    'nonce',                     <-- Nonce value
    'check_state_on',            <-- Route to check if nonce was verified
    'url_question_sqrl',         <-- Url for sqrl client to receive
    'encoded_url_question_sqrl', <-- Endoded Base 64 URL(url for sqrl client to receive)
]

检查用户是否可以通过普通登录进行认证的函数

要检查用户是否可以正常登录,您需要调用以下函数。

SQRLController::checkIfUserCanAuthByNormalLogin($user_id);

此函数需要此值

(
    $user_id <-- The user id you want to check, if this is null or not number > 0 function will return false
)

此函数将返回此布尔值

    true    <-- Can do a normal login (username and password)
    false   <-- SQRL Authentication Only Allowed

检查用户是否可以使用恢复密码的函数

要检查用户是否可以恢复其密码,您需要调用以下函数。

SQRLController::checkIfUserCanUseRecoverPassword($user_id);

此函数需要以下值

(
    $user_id <-- The user id you want to check, if this is null or not number > 0 function will return false
)

此函数将返回此布尔值

    true    <-- Can do a normal login (username and password)
    false   <-- SQRL Authentication Only Allowed

检查用户是否可以通过SQRL进行认证的函数

要检查用户是否可以进行SQRL身份验证,您需要调用以下函数。

SQRLController::checkIfUserCanAuthBySQRL($user_id);

此函数需要此值

(
    $user_id <-- The user id you want to check, if this is null or not number > 0 function will return false
)

此函数将返回此布尔值

    true    <-- Can do a normal login (username and password)
    false   <-- SQRL Authentication Only Allowed

检查随机数是否准备就绪的函数

此函数在用户使用SQRL客户端移动应用或某些不能重定向到用户浏览器的SQRL客户端时是必要的。当这种情况发生时,用户的浏览器需要不时检查随机数,当随机数有效且为身份验证类型时,需要调用通过原始随机数获取用户(如果可以验证)函数。函数名称如下。

SQRLController::checkIfisReady($nut);

此函数需要此值

(
    $nut       <-- Is the nonce you want to validate
)

如果随机数为空或为null,此函数将返回null,如果随机数有效,它将返回此数组

[
    'isReady',  <-- False mean that nonce was not valid or verified
    'msg',      <-- This is msg of error and successful, and can be one of this one:
                    'Time out, reload nonce!' -- When this happen, you need to create new nonce because this exceed is valid time;
                    'IP Doesnt Match!' -- This happen when IP Adress of the nonce was created for, is not equal to the IP Address of the request made;
                    'Not Ready!' -- This happen when nonce is valid but still no SQRL Client checked the nonce;
                    'SQRL is disable for this user!' -- This happen when user was SQRL disable;
                    'Can be authenticated!' -- Successful authenticated message;
                    'The button selected is '.<--Here is number of button selected-->.'!' -- Successful question answer message;
                    'Button is invalid!' -- Successful question answer message but invalid button was received;
    'nextPage', <-- Url to Next Page (Only appear for Authenticated Nonces, when 'isReady' is true and when 'msg' is 'Can be authenticated!')
    'btn'      <-- the selected button question (Only appear for Question Nonces, when 'isReady' is true and when 'msg' is 'The button selected is <?>!' or 'Button is invalid!')
                   The text value of the btn parameter will be the character ‘0’ to “OK” button, ‘1’ to the first button or ‘2’ to the secound button.
] 

如果可以认证,通过原始nonce获取用户的函数

此函数用于获取随机数有效时的用户。函数名称如下。

SQRLController::getUserByOriginalNonceIfCanBeAuthenticated($orig_nonce);

此函数需要此值

(
    $orig_nonce <-- The nonce value given on from function getNewAuthNonce()
)

此函数将返回以下值之一

    null                <-- If nonce is no longer valid or doesn't exist
    Class Sqrl_pubkey   <-- Return the Class Sqrl_pubkey this happen when no user is associated to the Sqrl_pubkey, means is maybe a new user or he need to   associate is user account to this Sqrl_pubkey
    Int user_id         <-- Return the user id when Sqrl_pubkey was found associated to a user

SQRLControllerAPI (DestruidorPT\LaravelSQRLAuth\App\Http\Controllers\SQRL\SQRLControllerAPI)

此控制器能够将其他站点与您的SQRL服务器集成,并且SQRL客户端可以与之通信。

向SQRL的API函数

这是最重要的函数之一,它必须使用,没有此函数,SQRL服务器将无法工作。要进行配置,您需要创建一个API路由并将其放入文件.env中的变量SQRL_ROUTE_TO_SQRL_AUTH。然后所有来自SQRL客户端的通信都将发送到此API函数,要查看发生了什么,请检查日志,您可以在配置日志系统中查看更多信息。

SQRLController::sqrl();

此函数将返回此数组

[
    'nonce',                  <-- Nonce value,
    'check_state_on',         <-- Route to check if nonce was verified
    'url_login_sqrl',         <-- Url for sqrl client to receive
    'encoded_url_login_sqrl', <-- Endoded Base 64 URL(url for sqrl client to receive)
]

检查随机数是否准备就绪的API函数

当用户使用SQRL客户端移动应用或某些不能将用户浏览器重定向的SQRL客户端时,此函数是必要的。当这种情况发生时,用户的浏览器需要不时检查随机数,当随机数有效且为身份验证类型时,需要调用通过原始随机数获取用户(如果可以验证)函数。函数名称如下。

SQRLController::checkIfisReady();

此函数需要此值

(
    $nut       <-- Is the nonce you want to validate, you pass this value by adding to url `?nut=<nonce_value>`
)

如果$_GET["nut"]为空或为null,此函数将返回404,如果随机数有效,它将返回此数组

[
    'isReady',  <-- False mean that nonce was not valid or verified
    'msg',      <-- This is msg of error and successful, and can be one of this one:
                    'Time out, reload nonce!' -- When this happen, you need to create new nonce because this exceed is valid time;
                    'IP Doesnt Match!' -- This happen when IP Adress of the nonce was created for, is not equal to the IP Address of the request made;
                    'Not Ready!' -- This happen when nonce is valid but still no SQRL Client checked the nonce;
                    'SQRL is disable for this user!' -- This happen when user was SQRL disable;
                    'Can be authenticated!' -- Successful authenticated message;
                    'The button selected is '.<--Here is name and the number of button selected-->.'!' -- Successful question answer message;
                    'Button is invalid!' -- Successful question answer message but invalid button was received;
    'nextPage', <-- Url to Next Page, appears when authentication was successfull and the url to the button was selected if was configurade
    'btn'      <-- the selected button question (Only appear for Question Nonces, when 'isReady' is true and when 'msg' is 'The button selected is <?>!' or 'Button is invalid!')  
] 

安装和演示视频

点击此处访问YouTube上的视频

Click here to go to the video on YouTube

联系方式