From 3a626202628b27fbe8500251cd609a9062a00f9e Mon Sep 17 00:00:00 2001 From: Marco <16927402+thtg88@users.noreply.github.com> Date: Thu, 25 Mar 2021 22:34:09 +0000 Subject: [PATCH] [Apple] Add support for a user as an associative array in Apple provider (#644) Co-authored-by: Marco Marassi --- Provider.php | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/Provider.php b/Provider.php index 8b60bc7..9115de4 100644 --- a/Provider.php +++ b/Provider.php @@ -202,19 +202,15 @@ public function user() */ protected function mapUserToObject(array $user) { - $value = trim((string) $this->request->input('user')); - - if ($value !== '') { - $userRequest = json_decode($value, true); - - if (isset($userRequest['name'])) { - $user['name'] = $userRequest['name']; - $fullName = trim( - ($user['name']['firstName'] ?? '') - .' ' - .($user['name']['lastName'] ?? '') - ); - } + $userRequest = $this->getUserRequest(); + + if (isset($userRequest['name'])) { + $user['name'] = $userRequest['name']; + $fullName = trim( + ($user['name']['firstName'] ?? '') + .' ' + .($user['name']['lastName'] ?? '') + ); } return (new User()) @@ -225,4 +221,21 @@ protected function mapUserToObject(array $user) 'email' => $user['email'] ?? null, ]); } + + private function getUserRequest(): array + { + $value = $this->request->input('user'); + + if (is_array($value)) { + return $value; + } + + $value = trim((string) $value); + + if ($value === '') { + return []; + } + + return json_decode($value, true); + } }