Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Docs/Documentation/SocialAuthentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
17 changes: 14 additions & 3 deletions config/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!')
],
Expand Down Expand Up @@ -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' => [
Expand Down Expand Up @@ -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',
],
],
],
],
];
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/AuthenticationServiceLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
31 changes: 21 additions & 10 deletions src/View/Helper/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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' => '<a href="/auth/{{name}}" class="btn btn-social btn-{{name}}">{{icon}}{{title}}</a>',
'icon' => '<i class="fa fa-{{name}}"></i>',
],
];

/**
* Social login link
Expand All @@ -48,24 +56,27 @@ 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'];
} else {
$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,
]);
}

Expand Down
Loading