Skip to content

Commit

Permalink
Merge pull request #134 from warcooft/feat-29-7
Browse files Browse the repository at this point in the history
feat: Handles deauthentication actions by users.
  • Loading branch information
datamweb committed Jul 29, 2024
2 parents 1f36be9 + 0b5df6a commit 9b4e5db
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Controllers/OAuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

class OAuthController extends BaseController implements ControllersInterface
{
private const ACCESS_DENIED = 'access_denied';

public function redirectOAuth(string $oauthName): RedirectResponse
{
// if user login
Expand Down Expand Up @@ -50,11 +52,19 @@ public function redirectOAuth(string $oauthName): RedirectResponse
public function callBack(): RedirectResponse
{
// if user after callback request url
if (! session('oauth_name')) {
if (! $oauth_name = session('oauth_name')) {
return redirect()->to(config('Auth')->logoutRedirect())->with('error', lang('ShieldOAuthLang.Callback.oauth_class_not_set'));
}
$allGet = $this->request->getGet();

// if permission is denied or was cancelled by user.
if (isset($allGet['error']) && $allGet['error'] === self::ACCESS_DENIED) {
$OAuth = ucfirst($oauth_name);
$oauthName = lang("ShieldOAuthLang.{$OAuth}.{$oauth_name}");

return redirect()->to(config('Auth')->logoutRedirect())->with('error', lang('ShieldOAuthLang.Callback.access_denied', [$oauthName]));
}

// if api have error
if (isset($allGet['error'])) {
return redirect()->to(config('Auth')->logoutRedirect())->with('error', lang('ShieldOAuthLang.unknown'));
Expand Down
1 change: 1 addition & 0 deletions src/Language/en/ShieldOAuthLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'oauth_class_not_set' => 'An error occurred, it seems that the OAuth Class is not set.',
'anti_forgery' => 'Your request has been detected as fake. we are sorry!',
'account_not_found' => 'There is no account registered with the email "{0}".',
'access_denied' => 'Authentication cancelled! You declined {0} permissions.',
],

// ShieldOAuthButton in views
Expand Down
1 change: 1 addition & 0 deletions src/Language/fa/ShieldOAuthLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'oauth_class_not_set' => 'خطای رخ داد، به نظر میرسد کلاس OAuth مورد نظر به درستی تنظیم نشده است.',
'anti_forgery' => 'متاسفانه، تلاش شما ، یک درخواست جعلی تشخیص داده شد.',
'account_not_found' => 'هیچ حسابی با ایمیل "{0}" ثبت نشده است.',
'access_denied' => 'تأیید اعتبار لغو شد! شما دسترسی‌های {0} را رد کردید.',
],

// ShieldOAuthButton in views
Expand Down
1 change: 1 addition & 0 deletions src/Language/fr/ShieldOAuthLang.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'oauth_class_not_set' => 'Une erreur s’est produite, il semble que la classe OAuth n’est pas définie.',
'anti_forgery' => 'Votre demande a été détectée comme erronée. Nous sommes désolés!',
'account_not_found' => 'Il n\'y a pas de compte enregistré avec l\'email "{0}".',
'access_denied' => 'Authentification annulée ! Vous avez refusé les autorisations {0}.',
],

// ShieldOAuthButton in views
Expand Down
1 change: 1 addition & 0 deletions src/Language/id/ShieldOAuthLang.php