Skip to content

Commit

Permalink
fix hardcoded urls in SocialNetworkAuthenticateService
Browse files Browse the repository at this point in the history
  • Loading branch information
eluhr committed Mar 7, 2024
1 parent 5d8dadf commit e6d6965
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/User/Service/SocialNetworkAuthenticateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@
use Da\User\Model\User;
use Da\User\Query\SocialNetworkAccountQuery;
use Da\User\Query\UserQuery;
use Da\User\Traits\ModuleAwareTrait;
use Yii;
use yii\authclient\AuthAction;
use yii\helpers\Url;

class SocialNetworkAuthenticateService implements ServiceInterface
{
use ModuleAwareTrait;

protected $controller;
protected $authAction;
protected $client;
Expand All @@ -50,15 +53,15 @@ public function run()
$account = $this->socialNetworkAccountQuery->whereClient($this->client)->one();
if (!$this->controller->module->enableSocialNetworkRegistration && ($account === null || $account->user === null)) {
Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Registration on this website is disabled'));
$this->authAction->setSuccessUrl(Url::to(['/user/security/login']));
$this->authAction->setSuccessUrl(Url::to(['/' . $this->getModule()->id . '/security/login']));

return false;
}
if ($account === null) {
$account = $this->createAccount();
if (!$account) {
Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Unable to create an account.'));
$this->authAction->setSuccessUrl(Url::to(['/user/security/login']));
$this->authAction->setSuccessUrl(Url::to(['/' . $this->getModule()->id . '/security/login']));

return false;
}
Expand All @@ -72,7 +75,7 @@ public function run()
if ($account->user instanceof User) {
if ($account->user->getIsBlocked()) {
Yii::$app->session->setFlash('danger', Yii::t('usuario', 'Your account has been blocked.'));
$this->authAction->setSuccessUrl(Url::to(['/user/security/login']));
$this->authAction->setSuccessUrl(Url::to(['/' . $this->getModule()->id . '/security/login']));
} else {
$result = Yii::$app->user->login($account->user, $this->controller->module->rememberLoginLifespan);
if ($result) {
Expand Down

4 comments on commit e6d6965

@edegaudenzi
Copy link

@edegaudenzi edegaudenzi commented on e6d6965 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, this commit introduces possible regression with custom code since 2amigos/yii2-usuario version 1.6.3 included.
Class common\clients\YourCustomEndpoint contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Da\User\Contracts\AuthClientInterface::getUserId)

My existing Microsoft365 (for Organisations) custom integration:
class Microsoft365 extends \yii\authclient\OAuth2 implements \Da\User\Contracts\AuthClientInterface

for any other dev having the same problem, you can fix it in the same way @eluhr did for the official ones: use the Da\User\Traits\AuthClientUserIdTrait inside your class like:

class Microsoft365 extends \yii\authclient\OAuth2 implements  \Da\User\Contracts\AuthClientInterface
{
    use \Da\User\Traits\AuthClientUserIdTrait;

@edegaudenzi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS: if someone is interested in having the Microsoft365 client, I can create a PR. It looks something like:
image

@TonisOrmisson
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your error comes from a7e044f#diff-f52bc10204963b009c10f27211e4da5e2ddb02a01f767c07159d141431f435dfR36 instead from an earlier commit @edegaudenzi . But yes, changing the interface can break custom implementations, maybe should have been a 1.7.x release instead of minor 1.6.x version change indicating possible breaking changes. I think having MS365 integration included in the module is also a good idea

@maxxer
Copy link
Collaborator

@maxxer maxxer commented on e6d6965 Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference, this commit introduces possible regression with custom code since 2amigos/yii2-usuario version 1.6.3 included. Class common\clients\YourCustomEndpoint contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Da\User\Contracts\AuthClientInterface::getUserId)

Thank you for reporting, I added it to the 1.6.3 release notes!
For Office365 integrations, if you want to create a PR I'll merge it! Thanks again

Please sign in to comment.