diff --git a/Docs/Documentation/SocialAuthentication.md b/Docs/Documentation/SocialAuthentication.md index adc8d2b5..850c7477 100644 --- a/Docs/Documentation/SocialAuthentication.md +++ b/Docs/Documentation/SocialAuthentication.md @@ -9,6 +9,7 @@ We currently support the following providers to perform login as well as to link * Instagram * Amazon * LinkedIn (deprecated, it's not working with the OAuth 2.0 provider. They switched to OpenID-Connect.) +* Github Please [contact us](https://cakedc.com/contact) if you need to support another provider. diff --git a/config/users.php b/config/users.php index f5f7a305..8376d678 100644 --- a/config/users.php +++ b/config/users.php @@ -91,7 +91,7 @@ 'messagesList' => [ __d('cake_d_c/users', 'Empty password'), __d('cake_d_c/users', 'Too simple'), - __d('cake_d_c/users','Simple'), + __d('cake_d_c/users', 'Simple'), __d('cake_d_c/users', 'That\'s OK'), __d('cake_d_c/users', 'Great password!') ], @@ -170,8 +170,8 @@ ], 'Webauthn2fa' => [ 'enabled' => false, - 'appName' => null,//App must set a valid name here - 'id' => null,//default value is the current domain + 'appName' => null, //App must set a valid name here + 'id' => null, //default value is the current domain 'checker' => \CakeDC\Auth\Authentication\DefaultWebauthn2FAuthenticationChecker::class, ], 'TwoFactorProcessors' => [ @@ -380,6 +380,17 @@ 'callbackLinkSocialUri' => Router::fullBaseUrl() . '/callback-link-social/azure', ], ], + 'github' => [ + 'service' => 'CakeDC\Auth\Social\Service\OAuth2Service', + 'className' => 'League\OAuth2\Client\Provider\Github', + 'mapper' => 'CakeDC\Auth\Social\Mapper\Github', + 'skipSocialAccountValidation' => false, + 'options' => [ + 'redirectUri' => Router::fullBaseUrl() . '/auth/github', + 'linkSocialUri' => Router::fullBaseUrl() . '/link-social/github', + 'callbackLinkSocialUri' => Router::fullBaseUrl() . '/callback-link-social/github', + ], + ], ], ], ]; diff --git a/src/Loader/AuthenticationServiceLoader.php b/src/Loader/AuthenticationServiceLoader.php index b71a913c..6b3e9e0b 100644 --- a/src/Loader/AuthenticationServiceLoader.php +++ b/src/Loader/AuthenticationServiceLoader.php @@ -55,7 +55,7 @@ protected function loadIdentifiers($service) foreach ($identifiers as $key => $item) { [$identifier, $options] = $this->_getItemLoadData($item, $key); - $service->loadIdentifier($identifier, $options); + $service->identifiers()->load($identifier, $options); } } diff --git a/src/View/Helper/UserHelper.php b/src/View/Helper/UserHelper.php index 3ef18d35..306e28d7 100644 --- a/src/View/Helper/UserHelper.php +++ b/src/View/Helper/UserHelper.php @@ -17,6 +17,7 @@ use Cake\Utility\Hash; use Cake\Utility\Inflector; use Cake\View\Helper; +use Cake\View\StringTemplateTrait; use CakeDC\Users\Utility\UsersUrl; use InvalidArgumentException; @@ -29,12 +30,19 @@ */ class UserHelper extends Helper { + use StringTemplateTrait; + protected array $helpers = ['Html', 'Form', 'CakeDC/Users.AuthLink']; /** * @inheritDoc */ - protected array $_defaultConfig = []; + protected array $_defaultConfig = [ + 'templates' => [ + 'socialButton' => '{{icon}}{{title}}', + 'icon' => '', + ], + ]; /** * Social login link @@ -48,9 +56,6 @@ public function socialLogin(string $name, array $options = []): string if (empty($options['label'])) { $options['label'] = __d('cake_d_c/users', 'Sign in with'); } - $icon = $this->Html->tag('i', '', [ - 'class' => 'fa fa-' . strtolower($name), - ]); if (isset($options['title'])) { $providerTitle = $options['title']; @@ -58,14 +63,20 @@ public function socialLogin(string $name, array $options = []): string $providerTitle = $options['label'] . ' ' . Inflector::camelize($name); } - $providerClass = 'btn btn-social btn-' . strtolower($name); - $optionClass = $options['class'] ?? null; - if ($optionClass) { - $providerClass .= " $optionClass"; + $icon = $this->templater()->format('icon', [ + 'name' => strtolower($name), + ]); + + $className = ''; + if (isset($options['class'])) { + $className = " {$options['class']}"; } - return $this->Html->link($icon . $providerTitle, "/auth/$name", [ - 'escape' => false, 'class' => $providerClass, + return $this->templater()->format('socialButton', [ + 'name' => strtolower($name), + 'icon' => $icon, + 'title' => $providerTitle, + 'class' => $className, ]); }