From 738cb29be97e909997cc6727f7d6b85af539a23a Mon Sep 17 00:00:00 2001
From: lukasmatusiewicz <77617779+lukasmatusiewicz@users.noreply.github.com>
Date: Mon, 24 Jan 2022 15:31:07 +0100
Subject: [PATCH] Add multiple webauthn challenges (#8)

* Add multiple webauthn challenges

* rename

* fix multi webauthn
---
 README.md                                         |  2 +-
 composer.json                                     |  6 +++---
 src/PIResponse.php                                | 15 +++++++++++----
 .../TestEnrollToken.php                           |  0
 .../TestGetAuthToken.php                          |  0
 .../TestPollTransaction.php                       |  0
 .../TestTriggerChallenge.php                      |  0
 .../TestValidateCheck.php                         |  2 +-
 8 files changed, 16 insertions(+), 9 deletions(-)
 rename test/{privacyidea-php-sdk => privacyidea-php-client}/TestEnrollToken.php (100%)
 rename test/{privacyidea-php-sdk => privacyidea-php-client}/TestGetAuthToken.php (100%)
 rename test/{privacyidea-php-sdk => privacyidea-php-client}/TestPollTransaction.php (100%)
 rename test/{privacyidea-php-sdk => privacyidea-php-client}/TestTriggerChallenge.php (100%)
 rename test/{privacyidea-php-sdk => privacyidea-php-client}/TestValidateCheck.php (98%)

diff --git a/README.md b/README.md
index 30b4294..d560c1a 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ You can add our library to your repository as a submodule or install it using Co
 
 To install our repository with Composer, run this command in Terminal:
 
-`composer require privacyidea/privacyidea-php-sdk`
+`composer require privacyidea/privacyidea-php-client`
 
 Next, you have to run:
 
diff --git a/composer.json b/composer.json
index eae14d6..ed7165a 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
 {
-  "name": "privacyidea/privacyidea-php-sdk",
-  "description": "This is the privacyIDEA-PHP-SDK. The library that will help you to connect your plugin to the privacyIDEA server using REST APIs.",
+  "name": "privacyidea/privacyidea-php-client",
+  "description": "This is the privacyIDEA-PHP-Client. The library that will help you to connect your plugin to the privacyIDEA server using REST APIs.",
   "minimum-stability": "stable",
   "authors": [
     {
@@ -11,7 +11,7 @@
   "repositories": [
     {
       "type": "vcs",
-      "url": "https://github.com/privacyidea/sdk-php"
+      "url": "https://github.com/privacyidea/sdk-client"
     }
   ],
   "require": {
diff --git a/src/PIResponse.php b/src/PIResponse.php
index 573e00b..93da798 100644
--- a/src/PIResponse.php
+++ b/src/PIResponse.php
@@ -184,16 +184,23 @@ class PIResponse
      */
     public function webAuthnSignRequest()
     {
-        $ret = "";
+        $arr = [];
+        $webauthn = "";
         foreach ($this->multiChallenge as $challenge)
         {
             if ($challenge->type === "webauthn")
             {
-                $ret = $challenge->webAuthnSignRequest;
-                break;
+                $t = json_decode($challenge->webAuthnSignRequest);
+                if (empty($webauthn))
+                {
+                    $webauthn = $t;
+                }
+                $arr[] = $challenge->attributes['webAuthnSignRequest']['allowCredentials'][0];
             }
         }
-        return $ret;
+        $webauthn->allowCredentials = $arr;
+
+        return json_encode($webauthn);
     }
 
     public function u2fSignRequest()
diff --git a/test/privacyidea-php-sdk/TestEnrollToken.php b/test/privacyidea-php-client/TestEnrollToken.php
similarity index 100%
rename from test/privacyidea-php-sdk/TestEnrollToken.php
rename to test/privacyidea-php-client/TestEnrollToken.php
diff --git a/test/privacyidea-php-sdk/TestGetAuthToken.php b/test/privacyidea-php-client/TestGetAuthToken.php
similarity index 100%
rename from test/privacyidea-php-sdk/TestGetAuthToken.php
rename to test/privacyidea-php-client/TestGetAuthToken.php
diff --git a/test/privacyidea-php-sdk/TestPollTransaction.php b/test/privacyidea-php-client/TestPollTransaction.php
similarity index 100%
rename from test/privacyidea-php-sdk/TestPollTransaction.php
rename to test/privacyidea-php-client/TestPollTransaction.php
diff --git a/test/privacyidea-php-sdk/TestTriggerChallenge.php b/test/privacyidea-php-client/TestTriggerChallenge.php
similarity index 100%
rename from test/privacyidea-php-sdk/TestTriggerChallenge.php
rename to test/privacyidea-php-client/TestTriggerChallenge.php
diff --git a/test/privacyidea-php-sdk/TestValidateCheck.php b/test/privacyidea-php-client/TestValidateCheck.php
similarity index 98%
rename from test/privacyidea-php-sdk/TestValidateCheck.php
rename to test/privacyidea-php-client/TestValidateCheck.php
index 3c6d2fc..479d097 100644
--- a/test/privacyidea-php-sdk/TestValidateCheck.php
+++ b/test/privacyidea-php-client/TestValidateCheck.php
@@ -1,6 +1,6 @@
 <?php
 
-require_once('../../src/privacyidea-php-sdk/SDK-Autoloader.php');
+require_once('../../src/privacyidea-php-client/SDK-Autoloader.php');
 require_once('../../vendor/autoload.php');
 
 use PHPUnit\Framework\TestCase;
-- 
GitLab