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 + } } } 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/Azure.php b/src/Social/Mapper/Azure.php new file mode 100644 index 0000000..9304e35 --- /dev/null +++ b/src/Social/Mapper/Azure.php @@ -0,0 +1,40 @@ + '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 '#'; + } +} 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); + } +}