From 881de6262f286638a45690a2945f202f52d53159 Mon Sep 17 00:00:00 2001 From: tomirons Date: Tue, 5 Sep 2023 10:07:02 -0400 Subject: [PATCH] refactor authentication classes --- src/Authentication/AuthenticationMethod.php | 10 +++++++++- src/Authentication/Basic.php | 4 ++-- src/Authentication/Bearer.php | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Authentication/AuthenticationMethod.php b/src/Authentication/AuthenticationMethod.php index 18137c6..6367ba2 100644 --- a/src/Authentication/AuthenticationMethod.php +++ b/src/Authentication/AuthenticationMethod.php @@ -6,5 +6,13 @@ abstract class AuthenticationMethod implements Arrayable { - // + public function toArray(): array + { + return [ + 'key' => 'Authorization', + 'value' => sprintf('%s {{token}}', $this->prefix()), + ]; + } + + abstract public function prefix(): string; } diff --git a/src/Authentication/Basic.php b/src/Authentication/Basic.php index 7fb5837..c35e380 100644 --- a/src/Authentication/Basic.php +++ b/src/Authentication/Basic.php @@ -4,8 +4,8 @@ class Basic extends AuthenticationMethod { - public function toArray(): array + public function prefix(): string { - return []; + return 'Basic'; } } diff --git a/src/Authentication/Bearer.php b/src/Authentication/Bearer.php index e63e63d..814ce58 100644 --- a/src/Authentication/Bearer.php +++ b/src/Authentication/Bearer.php @@ -4,8 +4,8 @@ class Bearer extends AuthenticationMethod { - public function toArray(): array + public function prefix(): string { - return []; + return 'Bearer'; } }