From 5b5e88b44c41f02599961a16c8940f2bd1dcec8c Mon Sep 17 00:00:00 2001 From: Alberto Rodriguez Date: Fri, 12 Aug 2022 17:17:15 -0400 Subject: [PATCH 1/5] add microsoft mapper WIP --- src/Social/Mapper/Microsoft.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/Social/Mapper/Microsoft.php diff --git a/src/Social/Mapper/Microsoft.php b/src/Social/Mapper/Microsoft.php new file mode 100644 index 0000000..8479f6c --- /dev/null +++ b/src/Social/Mapper/Microsoft.php @@ -0,0 +1,31 @@ + 'pictureUrl', + 'first_name' => 'firstName', + 'last_name' => 'lastName', + 'email' => 'emailAddress', + 'bio' => 'headline', + 'link' => 'publicProfileUrl', + ]; +} From d8703f7a457d4f7ba9fd6203450bc97ca544a309 Mon Sep 17 00:00:00 2001 From: Alberto Rodriguez Date: Fri, 12 Aug 2022 18:01:15 -0400 Subject: [PATCH 2/5] update MS mapper --- src/Social/Mapper/Microsoft.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Social/Mapper/Microsoft.php b/src/Social/Mapper/Microsoft.php index 8479f6c..0277296 100644 --- a/src/Social/Mapper/Microsoft.php +++ b/src/Social/Mapper/Microsoft.php @@ -21,11 +21,8 @@ class Microsoft extends AbstractMapper * @var array */ protected $_mapFields = [ - 'avatar' => 'pictureUrl', - 'first_name' => 'firstName', - 'last_name' => 'lastName', - 'email' => 'emailAddress', - 'bio' => 'headline', - 'link' => 'publicProfileUrl', + 'full_name' => 'name', + 'username' => 'unique_name', + 'email' => 'upn', ]; } From 97da53b8d7e1998a5a20aa2280ef606135e1048d Mon Sep 17 00:00:00 2001 From: Alberto Rodriguez Date: Fri, 19 Aug 2022 15:53:53 -0400 Subject: [PATCH 3/5] add azure sso provider --- config/auth.php | 10 ++++++++++ src/Social/Mapper/{Microsoft.php => Azure.php} | 14 +++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) rename src/Social/Mapper/{Microsoft.php => Azure.php} (72%) diff --git a/config/auth.php b/config/auth.php index 76bc7cb..82fbef5 100644 --- a/config/auth.php +++ b/config/auth.php @@ -76,6 +76,16 @@ 'callbackLinkSocialUri' => Router::fullBaseUrl() . '/callback-link-social/amazon', ] ], + 'azure' => [ + 'service' => 'CakeDC\Auth\Social\Service\OAuth2Service', + 'className' => 'TheNetworg\OAuth2\Client\Provider\Azure', + 'mapper' => 'CakeDC\Auth\Social\Mapper\Azure', + 'options' => [ + 'redirectUri' => Router::fullBaseUrl() . '/auth/azure', + 'linkSocialUri' => Router::fullBaseUrl() . '/link-social/azure', + 'callbackLinkSocialUri' => Router::fullBaseUrl() . '/callback-link-social/azure', + ] + ], ], 'OneTimePasswordAuthenticator' => [ 'checker' => \CakeDC\Auth\Authentication\DefaultOneTimePasswordAuthenticationChecker::class, diff --git a/src/Social/Mapper/Microsoft.php b/src/Social/Mapper/Azure.php similarity index 72% rename from src/Social/Mapper/Microsoft.php rename to src/Social/Mapper/Azure.php index 0277296..9304e35 100644 --- a/src/Social/Mapper/Microsoft.php +++ b/src/Social/Mapper/Azure.php @@ -13,7 +13,7 @@ namespace CakeDC\Auth\Social\Mapper; -class Microsoft extends AbstractMapper +class Azure extends AbstractMapper { /** * Map for provider fields @@ -21,8 +21,20 @@ class Microsoft extends AbstractMapper * @var array */ protected $_mapFields = [ + 'id' => 'sub', 'full_name' => 'name', 'username' => 'unique_name', 'email' => 'upn', ]; + + /** + * Get link property value + * + * @param mixed $rawData raw data + * @return string + */ + protected function _link($rawData) + { + return '#'; + } } From 41b34537eb58bf90b6b9761e714563a1ac1e8d52 Mon Sep 17 00:00:00 2001 From: Alberto Rodriguez Date: Fri, 19 Aug 2022 16:22:39 -0400 Subject: [PATCH 4/5] add phpcodesniffer to save --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index ad66b64..f308a6c 100644 --- a/composer.json +++ b/composer.json @@ -75,5 +75,10 @@ "psalm": "php vendor/psalm/phar/psalm.phar --show-info=false src/ ", "stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:0.12.94 psalm/phar:~4.9.2 && mv composer.backup composer.json", "coverage-test": "phpunit --stderr --coverage-clover=clover.xml" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } From 3af4f50c9af5ad4d94129e62b2c93df9ba14375a Mon Sep 17 00:00:00 2001 From: Alberto Rodriguez Date: Fri, 19 Aug 2022 16:35:12 -0400 Subject: [PATCH 5/5] add azure mapper test --- tests/TestCase/Social/Mapper/AzureTest.php | 78 ++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/TestCase/Social/Mapper/AzureTest.php diff --git a/tests/TestCase/Social/Mapper/AzureTest.php b/tests/TestCase/Social/Mapper/AzureTest.php new file mode 100644 index 0000000..c2d3a8b --- /dev/null +++ b/tests/TestCase/Social/Mapper/AzureTest.php @@ -0,0 +1,78 @@ + 'test-token', + 'expires' => 1490988496, + ]); + $rawData = [ + 'token' => $token, + 'aud' => 'ef044865-c304-4707-bce2-2c8cb469f093', + 'iss' => 'https://sts.windows.net/b5a44686-40bd-47e2-8e01-e52f214f2c8f/', + 'iat' => 1660940688, + 'nbf' => 1660940688, + 'exp' => 1660944588, + 'amr' => [ ], + 'ipaddr' => '127.0.0.1', + 'name' => 'Test', + 'oid' => '8a27cdf6-50c6-455b-af9d-ec60381ee8b9', + 'rh' => '0.AQUAhkaktb1A4keOAeUvIU8sj2VIBO8EwwdHvOIsjLRp8JMFAJM.', + 'sub' => 'wsAdh5DgzKg_-dz9xap8P0Sqnar2-CKifp0noideBv4', + 'tid' => 'b5a44686-40bd-47e2-8e01-e52f214f2c8f', + 'unique_name' => 'test@gmail.com', + 'upn' => 'test@gmail.com', + 'ver' => '1.0', + ]; + $providerMapper = new Azure(); + $user = $providerMapper($rawData); + $this->assertEquals([ + 'id' => 'wsAdh5DgzKg_-dz9xap8P0Sqnar2-CKifp0noideBv4', + 'username' => 'test@gmail.com', + 'full_name' => 'Test', + 'first_name' => null, + 'last_name' => null, + 'email' => 'test@gmail.com', + 'avatar' => null, + 'gender' => null, + 'link' => '#', + 'bio' => null, + 'locale' => null, + 'validated' => true, + 'credentials' => [ + 'token' => 'test-token', + 'secret' => null, + 'expires' => 1490988496, + ], + 'raw' => $rawData, + ], $user); + } +}