Enable resize QRCode and calling js independantly of login
This commit is contained in:
parent
af1f125866
commit
a5e6caf8fe
@ -51,7 +51,7 @@ class SQRL
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function authNonce(): array
|
public static function authNonce(int $size=100): array
|
||||||
{
|
{
|
||||||
$url = config('sqrl.url');
|
$url = config('sqrl.url');
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ class SQRL
|
|||||||
'check_state_on'=>$route,
|
'check_state_on'=>$route,
|
||||||
'sqrl_url'=>$sqrl_url,
|
'sqrl_url'=>$sqrl_url,
|
||||||
'sqrl_url_encoded'=>self::base64_encode_url(sprintf('%s&can=%s',$sqrl_url,$o->can)),
|
'sqrl_url_encoded'=>self::base64_encode_url(sprintf('%s&can=%s',$sqrl_url,$o->can)),
|
||||||
'qrcode'=>SQRL::qrCode($sqrl_url,100),
|
'qrcode'=>SQRL::qrCode($sqrl_url,$size),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ class SQRLController extends Controller
|
|||||||
|
|
||||||
//Get the user by the original nonce
|
//Get the user by the original nonce
|
||||||
$o = SQRLAuth\Nonce::check($request->get('nut'),'orig_nonce');
|
$o = SQRLAuth\Nonce::check($request->get('nut'),'orig_nonce');
|
||||||
Log::debug(sprintf('User [%s]',serialize($o->getAttributes())));
|
Log::debug(sprintf('User [%s]',serialize($o ? $o->getAttributes() : NULL)));
|
||||||
|
|
||||||
if ($o && $o->verified) {
|
if ($o && $o->verified) {
|
||||||
if ($o->pubkey && ! $o->pubkey->disabled)
|
if ($o->pubkey && ! $o->pubkey->disabled)
|
||||||
|
@ -8,7 +8,7 @@ if (app() instanceof \Illuminate\Foundation\Application) {
|
|||||||
Route::get('/login','SQRLController@auth')->name('login');
|
Route::get('/login','SQRLController@auth')->name('login');
|
||||||
|
|
||||||
// Perform login
|
// Perform login
|
||||||
Route::post('/login','SQRLController@@login');
|
Route::post('/login','SQRLController@login');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::group(['prefix'=>'api','namespace'=>'Leenooks\SQRL'], function() {
|
Route::group(['prefix'=>'api','namespace'=>'Leenooks\SQRL'], function() {
|
||||||
|
@ -78,78 +78,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script>
|
@include('sqrl::login_js')
|
||||||
var syncQuery = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
|
||||||
var encodedSqrlUrl = false, sqrlScheme = true;
|
|
||||||
var gifProbe = new Image(); // create an instance of a memory-based probe image
|
|
||||||
var localhostRoot = 'http://localhost:25519/'; // the SQRL client listener
|
|
||||||
const poll = 500;
|
|
||||||
|
|
||||||
// define our load-success function
|
|
||||||
gifProbe.onload = function() {
|
|
||||||
sqrlScheme = false; // prevent retriggering of the SQRL QR code.
|
|
||||||
document.location.href = localhostRoot+encodedSqrlUrl;
|
|
||||||
};
|
|
||||||
|
|
||||||
// define our load-failure function
|
|
||||||
gifProbe.onerror = function() {
|
|
||||||
setTimeout(function() {
|
|
||||||
gifProbe.src = localhostRoot+Date.now()+'.gif';
|
|
||||||
},250);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Poll to see if authentication has proceeded
|
|
||||||
function pollForNextPage() {
|
|
||||||
if (document.hidden) { // before probing for any page change, we check to
|
|
||||||
setTimeout(pollForNextPage,poll); // see whether the page is visible. If the user is
|
|
||||||
return; // not viewing the page, check again in 5 seconds.
|
|
||||||
}
|
|
||||||
|
|
||||||
syncQuery.open('GET','{{ $check_state_on }}'); // the page is visible, so let's check for any update
|
|
||||||
syncQuery.onreadystatechange = function() {
|
|
||||||
if (syncQuery.readyState === 4 ) {
|
|
||||||
if (syncQuery.status === 200 ) {
|
|
||||||
|
|
||||||
var response = JSON.parse(syncQuery.response);
|
|
||||||
|
|
||||||
if (response.isReady) {
|
|
||||||
document.location.href = response.nextPage;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (response.msg === "Invalid Nonce, or Nonce expired"
|
|
||||||
|| response.msg === "IP Mismatch"
|
|
||||||
|| response.msg === "SQRL disabled for user")
|
|
||||||
{
|
|
||||||
var div = document.getElementById('error_message');
|
|
||||||
div.innerHTML = "<string>"+response.msg+"</strong><br><small>QR Code needs to be refresh - reload the page.<small>";
|
|
||||||
div.removeAttribute("hidden");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
setTimeout(pollForNextPage,poll);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
setTimeout(pollForNextPage,poll);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Send our request to check authenticated status
|
|
||||||
syncQuery.send();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if we have an encoded URL to jump to, initiate our GIF probing before jumping
|
|
||||||
function sqrlLinkClick(e) {
|
|
||||||
encodedSqrlUrl = e.getAttribute('encoded-sqrl-url');
|
|
||||||
|
|
||||||
if (encodedSqrlUrl) {
|
|
||||||
gifProbe.onerror();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pollForNextPage();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
|
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
|
||||||
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
|
||||||
|
72
src/views/login_js.blade.php
Normal file
72
src/views/login_js.blade.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<script>
|
||||||
|
var syncQuery = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject('MSXML2.XMLHTTP.3.0');
|
||||||
|
var encodedSqrlUrl = false, sqrlScheme = true;
|
||||||
|
var gifProbe = new Image(); // create an instance of a memory-based probe image
|
||||||
|
var localhostRoot = 'http://localhost:25519/'; // the SQRL client listener
|
||||||
|
const poll = 500;
|
||||||
|
|
||||||
|
// define our load-success function
|
||||||
|
gifProbe.onload = function() {
|
||||||
|
sqrlScheme = false; // prevent retriggering of the SQRL QR code.
|
||||||
|
document.location.href = localhostRoot+encodedSqrlUrl;
|
||||||
|
};
|
||||||
|
|
||||||
|
// define our load-failure function
|
||||||
|
gifProbe.onerror = function() {
|
||||||
|
setTimeout(function() {
|
||||||
|
gifProbe.src = localhostRoot+Date.now()+'.gif';
|
||||||
|
},250);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Poll to see if authentication has proceeded
|
||||||
|
function pollForNextPage() {
|
||||||
|
if (document.hidden) { // before probing for any page change, we check to
|
||||||
|
setTimeout(pollForNextPage,poll); // see whether the page is visible. If the user is
|
||||||
|
return; // not viewing the page, check again in 5 seconds.
|
||||||
|
}
|
||||||
|
|
||||||
|
syncQuery.open('GET','{{ $check_state_on }}'); // the page is visible, so let's check for any update
|
||||||
|
syncQuery.onreadystatechange = function() {
|
||||||
|
if (syncQuery.readyState === 4 ) {
|
||||||
|
if (syncQuery.status === 200 ) {
|
||||||
|
|
||||||
|
var response = JSON.parse(syncQuery.response);
|
||||||
|
|
||||||
|
if (response.isReady) {
|
||||||
|
document.location.href = response.nextPage;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (response.msg === "Invalid Nonce, or Nonce expired"
|
||||||
|
|| response.msg === "IP Mismatch"
|
||||||
|
|| response.msg === "SQRL disabled for user")
|
||||||
|
{
|
||||||
|
var div = document.getElementById('error_message');
|
||||||
|
div.innerHTML = "<string>"+response.msg+"</strong><br><small>QR Code needs to be refresh - reload the page.<small>";
|
||||||
|
div.removeAttribute("hidden");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setTimeout(pollForNextPage,poll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setTimeout(pollForNextPage,poll);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send our request to check authenticated status
|
||||||
|
syncQuery.send();
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we have an encoded URL to jump to, initiate our GIF probing before jumping
|
||||||
|
function sqrlLinkClick(e) {
|
||||||
|
encodedSqrlUrl = e.getAttribute('encoded-sqrl-url');
|
||||||
|
|
||||||
|
if (encodedSqrlUrl) {
|
||||||
|
gifProbe.onerror();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pollForNextPage();
|
||||||
|
</script>
|
Loading…
Reference in New Issue
Block a user