Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions WebAuthn/WebAuthn.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,12 @@ public function prepareChallengeForRegistration($username, $userid, $crossPlatfo
* @param string $userwebauthn the exisitng webauthn field for the user from your
* database (it's actaully a JSON string, but that's entirely internal to
* this code)
* @param string $device_name the optional device name given by the user during
* the registration. The device name can be request with a prompt (check
* the example for an implementation)
* @return string modified to store in the user's webauthn field in your database
*/
public function register($info, $userwebauthn)
public function register($info, $userwebauthn, $device_name = '')
{
if (! is_string($info)) {
$this->oops('info must be a string', 1);
Expand Down Expand Up @@ -192,7 +195,11 @@ public function register($info, $userwebauthn)
$publicKey = (object)array();
$publicKey->key = $ao->attData->keyBytes;
$publicKey->id = $info->rawId;
//log($publicKey->key);
$publicKey->datetime = date('c');

if(is_string($device_name) && trim($device_name) != '') {
$publicKey->dname = trim($device_name);
}

if (empty($userwebauthn)) {
$userwebauthn = [$publicKey];
Expand Down
9 changes: 7 additions & 2 deletions example/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ function getuser($username){
if (empty($_SESSION['username'])) { oops('username not set'); }
$user = getuser($_SESSION['username']);

/* get a device name from the user */
$device_name = (isset($_POST['dname']) && $_POST['dname'] != '')
? $_POST['dname'] : '';

/* The heart of the matter */
$user->webauthnkeys = $webauthn->register($_POST['register'], $user->webauthnkeys);
$user->webauthnkeys = $webauthn->register($_POST['register'], $user->webauthnkeys, $device_name);

/* Save the result to enable a challenge to be raised agains this
newly created key in order to log in */
Expand Down Expand Up @@ -269,9 +273,10 @@ function getuser($username){
/* activate the key and get the response */
webauthnRegister(j.challenge, function(success, info){
if (success) {
var device_name = prompt('Provide a name for this device (e.g. "John\'s phone" o "Macbook Sandra")');
$.ajax({url: '/',
method: 'POST',
data: {register: info},
data: {register: info, dname: device_name},
dataType: 'json',
success: function(j){
$('#iregisterform,#iregisterdokey').toggle();
Expand Down