diff --git a/composer.json b/composer.json index bd9d0956..41d69d67 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "minimum-stability": "dev", "prefer-stable": true, "require": { - "php": ">=7.4,<=8.2.27", + "php": ">=7.4,<=8.2.28", "pimple/pimple": "3.5.*" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 61a7458b..1b5bee37 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1aecdde4e4e032f1ad8ff8545cdb99d6", + "content-hash": "c3b2ffa2070510f5cbd8dc28afd5dc6e", "packages": [ { "name": "pimple/pimple", @@ -341,26 +341,29 @@ }, { "name": "doctrine/deprecations", - "version": "1.1.4", + "version": "1.1.5", "source": { "type": "git", "url": "https://github.com/doctrine/deprecations.git", - "reference": "31610dbb31faa98e6b5447b62340826f54fbc4e9" + "reference": "459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/deprecations/zipball/31610dbb31faa98e6b5447b62340826f54fbc4e9", - "reference": "31610dbb31faa98e6b5447b62340826f54fbc4e9", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38", + "reference": "459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38", "shasum": "" }, "require": { "php": "^7.1 || ^8.0" }, + "conflict": { + "phpunit/phpunit": "<=7.5 || >=13" + }, "require-dev": { - "doctrine/coding-standard": "^9 || ^12", - "phpstan/phpstan": "1.4.10 || 2.0.3", + "doctrine/coding-standard": "^9 || ^12 || ^13", + "phpstan/phpstan": "1.4.10 || 2.1.11", "phpstan/phpstan-phpunit": "^1.0 || ^2", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6 || ^10.5 || ^11.5 || ^12", "psr/log": "^1 || ^2 || ^3" }, "suggest": { @@ -380,9 +383,9 @@ "homepage": "https://www.doctrine-project.org/", "support": { "issues": "https://github.com/doctrine/deprecations/issues", - "source": "https://github.com/doctrine/deprecations/tree/1.1.4" + "source": "https://github.com/doctrine/deprecations/tree/1.1.5" }, - "time": "2024-12-07T21:18:45+00:00" + "time": "2025-04-07T20:06:18+00:00" }, { "name": "doctrine/instantiator", @@ -595,16 +598,16 @@ }, { "name": "gettext/languages", - "version": "2.10.0", + "version": "2.12.1", "source": { "type": "git", "url": "https://github.com/php-gettext/Languages.git", - "reference": "4d61d67fe83a2ad85959fe6133d6d9ba7dddd1ab" + "reference": "0b0b0851c55168e1dfb14305735c64019732b5f1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-gettext/Languages/zipball/4d61d67fe83a2ad85959fe6133d6d9ba7dddd1ab", - "reference": "4d61d67fe83a2ad85959fe6133d6d9ba7dddd1ab", + "url": "https://api.github.com/repos/php-gettext/Languages/zipball/0b0b0851c55168e1dfb14305735c64019732b5f1", + "reference": "0b0b0851c55168e1dfb14305735c64019732b5f1", "shasum": "" }, "require": { @@ -614,7 +617,8 @@ "phpunit/phpunit": "^4.8 || ^5.7 || ^6.5 || ^7.5 || ^8.4" }, "bin": [ - "bin/export-plural-rules" + "bin/export-plural-rules", + "bin/import-cldr-data" ], "type": "library", "autoload": { @@ -653,7 +657,7 @@ ], "support": { "issues": "https://github.com/php-gettext/Languages/issues", - "source": "https://github.com/php-gettext/Languages/tree/2.10.0" + "source": "https://github.com/php-gettext/Languages/tree/2.12.1" }, "funding": [ { @@ -665,24 +669,24 @@ "type": "github" } ], - "time": "2022-10-18T15:00:10+00:00" + "time": "2025-03-19T11:14:02+00:00" }, { "name": "hamcrest/hamcrest-php", - "version": "v2.0.1", + "version": "v2.1.1", "source": { "type": "git", "url": "https://github.com/hamcrest/hamcrest-php.git", - "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3" + "reference": "f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", - "reference": "8c3d0a3f6af734494ad8f6fbbee0ba92422859f3", + "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487", + "reference": "f8b1c0173b22fa6ec77a81fe63e5b01eba7e6487", "shasum": "" }, "require": { - "php": "^5.3|^7.0|^8.0" + "php": "^7.4|^8.0" }, "replace": { "cordoval/hamcrest-php": "*", @@ -690,8 +694,8 @@ "kodova/hamcrest-php": "*" }, "require-dev": { - "phpunit/php-file-iterator": "^1.4 || ^2.0", - "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0" + "phpunit/php-file-iterator": "^1.4 || ^2.0 || ^3.0", + "phpunit/phpunit": "^4.8.36 || ^5.7 || ^6.5 || ^7.0 || ^8.0 || ^9.0" }, "type": "library", "extra": { @@ -714,9 +718,9 @@ ], "support": { "issues": "https://github.com/hamcrest/hamcrest-php/issues", - "source": "https://github.com/hamcrest/hamcrest-php/tree/v2.0.1" + "source": "https://github.com/hamcrest/hamcrest-php/tree/v2.1.1" }, - "time": "2020-07-09T08:09:16+00:00" + "time": "2025-04-30T06:54:44+00:00" }, { "name": "mck89/peast", @@ -902,16 +906,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.13.0", + "version": "1.13.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "024473a478be9df5fdaca2c793f2232fe788e414" + "reference": "1720ddd719e16cf0db4eb1c6eca108031636d46c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/024473a478be9df5fdaca2c793f2232fe788e414", - "reference": "024473a478be9df5fdaca2c793f2232fe788e414", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/1720ddd719e16cf0db4eb1c6eca108031636d46c", + "reference": "1720ddd719e16cf0db4eb1c6eca108031636d46c", "shasum": "" }, "require": { @@ -950,7 +954,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.13.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.13.1" }, "funding": [ { @@ -958,7 +962,7 @@ "type": "tidelift" } ], - "time": "2025-02-12T12:17:51+00:00" + "time": "2025-04-29T12:36:36+00:00" }, { "name": "nikic/php-parser", @@ -1342,22 +1346,22 @@ }, { "name": "phpcsstandards/phpcsextra", - "version": "1.2.1", + "version": "1.3.0", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", - "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489" + "reference": "46d08eb86eec622b96c466adec3063adfed280dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", - "reference": "11d387c6642b6e4acaf0bd9bf5203b8cca1ec489", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/46d08eb86eec622b96c466adec3063adfed280dd", + "reference": "46d08eb86eec622b96c466adec3063adfed280dd", "shasum": "" }, "require": { "php": ">=5.4", "phpcsstandards/phpcsutils": "^1.0.9", - "squizlabs/php_codesniffer": "^3.8.0" + "squizlabs/php_codesniffer": "^3.12.1" }, "require-dev": { "php-parallel-lint/php-console-highlighter": "^1.0", @@ -1414,9 +1418,13 @@ { "url": "https://opencollective.com/php_codesniffer", "type": "open_collective" + }, + { + "url": "https://thanks.dev/u/gh/phpcsstandards", + "type": "thanks_dev" } ], - "time": "2023-12-08T16:49:07+00:00" + "time": "2025-04-20T23:35:32+00:00" }, { "name": "phpcsstandards/phpcsutils", @@ -1561,16 +1569,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.6.1", + "version": "5.6.2", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8" + "reference": "92dde6a5919e34835c506ac8c523ef095a95ed62" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8", - "reference": "e5e784149a09bd69d9a5e3b01c5cbd2e2bd653d8", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/92dde6a5919e34835c506ac8c523ef095a95ed62", + "reference": "92dde6a5919e34835c506ac8c523ef095a95ed62", "shasum": "" }, "require": { @@ -1619,9 +1627,9 @@ "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.1" + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.6.2" }, - "time": "2024-12-07T09:39:29+00:00" + "time": "2025-04-13T19:20:35+00:00" }, { "name": "phpdocumentor/type-resolver", @@ -1683,29 +1691,29 @@ }, { "name": "phpspec/prophecy", - "version": "v1.20.0", + "version": "v1.22.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "a0165c648cab6a80311c74ffc708a07bb53ecc93" + "reference": "35f1adb388946d92e6edab2aa2cb2b60e132ebd5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/a0165c648cab6a80311c74ffc708a07bb53ecc93", - "reference": "a0165c648cab6a80311c74ffc708a07bb53ecc93", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/35f1adb388946d92e6edab2aa2cb2b60e132ebd5", + "reference": "35f1adb388946d92e6edab2aa2cb2b60e132ebd5", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2 || ^2.0", - "php": "^7.2 || 8.0.* || 8.1.* || 8.2.* || 8.3.* || 8.4.*", + "php": "^7.4 || 8.0.* || 8.1.* || 8.2.* || 8.3.* || 8.4.*", "phpdocumentor/reflection-docblock": "^5.2", - "sebastian/comparator": "^3.0 || ^4.0 || ^5.0 || ^6.0", - "sebastian/recursion-context": "^3.0 || ^4.0 || ^5.0 || ^6.0" + "sebastian/comparator": "^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0", + "sebastian/recursion-context": "^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.40", "phpspec/phpspec": "^6.0 || ^7.0", - "phpstan/phpstan": "^1.9", + "phpstan/phpstan": "^2.1.13", "phpunit/phpunit": "^8.0 || ^9.0 || ^10.0" }, "type": "library", @@ -1747,9 +1755,9 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/v1.20.0" + "source": "https://github.com/phpspec/prophecy/tree/v1.22.0" }, - "time": "2024-11-19T13:12:41+00:00" + "time": "2025-04-29T14:58:06+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -3185,16 +3193,16 @@ }, { "name": "sirbrillig/phpcs-variable-analysis", - "version": "v2.11.22", + "version": "v2.12.0", "source": { "type": "git", "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", - "reference": "ffb6f16c6033ec61ed84446b479a31d6529f0eb7" + "reference": "4debf5383d9ade705e0a25121f16c3fecaf433a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/ffb6f16c6033ec61ed84446b479a31d6529f0eb7", - "reference": "ffb6f16c6033ec61ed84446b479a31d6529f0eb7", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/4debf5383d9ade705e0a25121f16c3fecaf433a7", + "reference": "4debf5383d9ade705e0a25121f16c3fecaf433a7", "shasum": "" }, "require": { @@ -3238,20 +3246,20 @@ "source": "https://github.com/sirbrillig/phpcs-variable-analysis", "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" }, - "time": "2025-01-06T17:54:24+00:00" + "time": "2025-03-17T16:17:38+00:00" }, { "name": "squizlabs/php_codesniffer", - "version": "3.11.3", + "version": "3.12.2", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "ba05f990e79cbe69b9f35c8c1ac8dca7eecc3a10" + "reference": "6d4cf6032d4b718f168c90a96e36c7d0eaacb2aa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/ba05f990e79cbe69b9f35c8c1ac8dca7eecc3a10", - "reference": "ba05f990e79cbe69b9f35c8c1ac8dca7eecc3a10", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/6d4cf6032d4b718f168c90a96e36c7d0eaacb2aa", + "reference": "6d4cf6032d4b718f168c90a96e36c7d0eaacb2aa", "shasum": "" }, "require": { @@ -3318,11 +3326,11 @@ "type": "open_collective" }, { - "url": "https://thanks.dev/phpcsstandards", + "url": "https://thanks.dev/u/gh/phpcsstandards", "type": "thanks_dev" } ], - "time": "2025-01-23T17:04:15+00:00" + "time": "2025-04-13T04:10:18+00:00" }, { "name": "symfony/finder", @@ -3618,16 +3626,16 @@ }, { "name": "wp-cli/php-cli-tools", - "version": "v0.12.4", + "version": "v0.12.5", "source": { "type": "git", "url": "https://github.com/wp-cli/php-cli-tools.git", - "reference": "fbb9c6eb83c04ee99b0c01454b47f47ab0e432bc" + "reference": "34b83b4f700df8a4ec3fd17bf7e7e7d8ca5f28da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wp-cli/php-cli-tools/zipball/fbb9c6eb83c04ee99b0c01454b47f47ab0e432bc", - "reference": "fbb9c6eb83c04ee99b0c01454b47f47ab0e432bc", + "url": "https://api.github.com/repos/wp-cli/php-cli-tools/zipball/34b83b4f700df8a4ec3fd17bf7e7e7d8ca5f28da", + "reference": "34b83b4f700df8a4ec3fd17bf7e7e7d8ca5f28da", "shasum": "" }, "require": { @@ -3675,9 +3683,9 @@ ], "support": { "issues": "https://github.com/wp-cli/php-cli-tools/issues", - "source": "https://github.com/wp-cli/php-cli-tools/tree/v0.12.4" + "source": "https://github.com/wp-cli/php-cli-tools/tree/v0.12.5" }, - "time": "2025-03-05T14:35:01+00:00" + "time": "2025-03-26T16:13:46+00:00" }, { "name": "wp-cli/wp-cli", @@ -3685,12 +3693,12 @@ "source": { "type": "git", "url": "https://github.com/wp-cli/wp-cli.git", - "reference": "d323e5dee744444c8605f52303bdf37b5e65e717" + "reference": "98e8ec823fb5aeef6414304cd8c34ddb86fe996e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wp-cli/wp-cli/zipball/d323e5dee744444c8605f52303bdf37b5e65e717", - "reference": "d323e5dee744444c8605f52303bdf37b5e65e717", + "url": "https://api.github.com/repos/wp-cli/wp-cli/zipball/98e8ec823fb5aeef6414304cd8c34ddb86fe996e", + "reference": "98e8ec823fb5aeef6414304cd8c34ddb86fe996e", "shasum": "" }, "require": { @@ -3706,7 +3714,7 @@ "wp-cli/entity-command": "^1.2 || ^2", "wp-cli/extension-command": "^1.1 || ^2", "wp-cli/package-command": "^1 || ^2", - "wp-cli/wp-cli-tests": "^4.3.7" + "wp-cli/wp-cli-tests": "^4.3.10" }, "suggest": { "ext-readline": "Include for a better --prompt implementation", @@ -3747,7 +3755,7 @@ "issues": "https://github.com/wp-cli/wp-cli/issues", "source": "https://github.com/wp-cli/wp-cli" }, - "time": "2025-03-11T19:14:47+00:00" + "time": "2025-04-30T13:11:33+00:00" }, { "name": "wp-coding-standards/wpcs", @@ -3822,7 +3830,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": ">=7.4,<=8.2.27" + "php": ">=7.4,<=8.2.28" }, "platform-dev": {}, "plugin-api-version": "2.6.0" diff --git a/languages/login-with-google.pot b/languages/login-with-google.pot index 588d8bba..86a7da56 100644 --- a/languages/login-with-google.pot +++ b/languages/login-with-google.pot @@ -2,14 +2,14 @@ # This file is distributed under the GPLv2+. msgid "" msgstr "" -"Project-Id-Version: Login with Google 1.4.0\n" +"Project-Id-Version: Login with Google 1.3.7\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/login-with-google\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2025-05-02T11:17:56+00:00\n" +"POT-Creation-Date: 2025-04-29T04:00:23+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "X-Generator: WP-CLI 2.12.0-alpha\n" "X-Domain: login-with-google\n" @@ -52,11 +52,11 @@ msgstr "" msgid "Could not authenticate the user, please try again." msgstr "" -#: src/Modules/OneTapLogin.php:181 +#: src/Modules/OneTapLogin.php:176 msgid "Cannot verify the credentials" msgstr "" -#: src/Modules/OneTapLogin.php:223 +#: src/Modules/OneTapLogin.php:218 msgid "User not found to authenticate" msgstr "" @@ -121,7 +121,7 @@ msgstr "" msgid "Login with Google settings" msgstr "" -#: src/Modules/Shortcode.php:92 +#: src/Modules/Shortcode.php:91 msgid "Login with google" msgstr "" @@ -181,12 +181,12 @@ msgstr "" msgid "User data is stale! Please try again." msgstr "" -#: templates/google-login-button.php:14 +#: templates/google-login-button.php:12 #: assets/build/js/block-button.js:1 msgid "Log in with Google" msgstr "" -#: templates/google-login-button.php:24 +#: templates/google-login-button.php:22 msgid "Log out" msgstr "" diff --git a/login-with-google.php b/login-with-google.php index 7ed1f849..b98b0e4b 100644 --- a/login-with-google.php +++ b/login-with-google.php @@ -2,7 +2,7 @@ /** * Plugin Name: Login with Google * Description: Allow users to login/register via Google. - * Version: 1.4.0 + * Version: 1.3.7 * Author: rtCamp * Author URI: https://rtcamp.com * Text Domain: login-with-google diff --git a/readme.txt b/readme.txt index 339e5b56..70ef8a44 100644 --- a/readme.txt +++ b/readme.txt @@ -1,12 +1,12 @@ === Log in with Google === -Contributors: rtCamp, sh4lin, nikhiljoshua, mchirag2002, mi5t4n -Unlinked contributors: Jeppehimer, dev-alamin +Contributors: rtCamp, sh4lin, nikhiljoshua +Unlinked contributors: Jeppehimer Donate link: https://rtcamp.com/ Tags: Google login, sign in, sso, oauth, authentication, sign-in, single sign-on, log in Requires at least: 5.5 Tested up to: 6.7.2 Requires PHP: 7.4 -Stable tag: 1.4.0 +Stable tag: 1.3.7 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -141,15 +141,6 @@ Code snippets to extend and customize the plugin can be found [here](https://git == Changelog == -= 1.4.0 = -Update: Migrated One Tap Login to use FedCM. -Update: After a successful login or logout, users are now redirected to the page they originally intended to access. -Update: When the plugin performs a redirect, it now includes an x-redirect-by header. -Update: A settings page link has been added directly under the plugin name on the Plugins screen. -Fix: Resolved an issue with generating unique usernames. -Fix: Fixed a bug where JavaScript string translations were not being applied correctly. -Chore: Documentation update. - = 1.3.7 = * Compatible with WordPress 6.7.2 @@ -220,15 +211,6 @@ Chore: Documentation update. == Upgrade Notice == -= 1.4.0 = -Update: Migrated One Tap Login to use FedCM. -Update: After a successful login or logout, users are now redirected to the page they originally intended to access. -Update: When the plugin performs a redirect, it now includes an x-redirect-by header. -Update: A settings page link has been added directly under the plugin name on the Plugins screen. -Fix: Resolved an issue with generating unique usernames. -Fix: Fixed a bug where JavaScript string translations were not being applied correctly. -Chore: Documentation update. - = 1.3.7 = * Compatible with WordPress 6.7.2 diff --git a/src/Modules/Login.php b/src/Modules/Login.php index e2adce02..6683cd7b 100644 --- a/src/Modules/Login.php +++ b/src/Modules/Login.php @@ -129,17 +129,51 @@ public function authenticate( $user = null ) { $decoded_state = $state ? (array) ( json_decode( base64_decode( $state ) ) ) : null; // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode if ( ! is_array( $decoded_state ) || empty( $decoded_state['provider'] ) || 'google' !== $decoded_state['provider'] ) { + $this->log_failed_attempt( 'Invalid provider or state' ); return $user; } if ( empty( $decoded_state['nonce'] ) || ! wp_verify_nonce( $decoded_state['nonce'], 'login_with_google' ) ) { + $this->log_failed_attempt( 'Invalid nonce' ); return $user; } try { $this->gh_client->set_access_token( $code ); - $user = $this->gh_client->user(); - $user = $this->authenticator->authenticate( $user ); + $google_user = $this->gh_client->user(); + + // Handle developer mode + if ( get_option( 'google_login_dev_mode' ) ) { + // Log raw user data + error_log( 'Google Login Debug - Raw User Data: ' . print_r( $google_user, true ) ); + + // Add debug information to the login page + add_action( 'login_footer', function() use ( $google_user ) { + echo ''; + }); + } + + // Check if the email domain is allowed + $allowed_domains = get_option( 'google_login_allowed_domains' ); + if ( ! empty( $allowed_domains ) ) { + $email_domain = substr( strrchr( $google_user->email, '@' ), 1 ); + $allowed_domains = array_map( 'trim', explode( ',', $allowed_domains ) ); + + if ( ! in_array( $email_domain, $allowed_domains, true ) ) { + $this->log_failed_attempt( 'Domain not allowed: ' . $email_domain ); + return new WP_Error( + 'domain_not_allowed', + __( 'Your email domain is not allowed to login to this site.', 'login-with-google' ) + ); + } + } + + $user = $this->authenticator->authenticate( $google_user ); if ( $user instanceof WP_User ) { $this->authenticated = true; @@ -156,13 +190,35 @@ public function authenticate( $user = null ) { return $user; } + $this->log_failed_attempt( 'Could not authenticate user' ); throw new Exception( __( 'Could not authenticate the user, please try again.', 'login-with-google' ) ); } catch ( Throwable $e ) { + $this->log_failed_attempt( $e->getMessage() ); return new WP_Error( 'google_login_failed', $e->getMessage() ); } } + /** + * Log failed login attempts + * + * @param string $reason Reason for the failed attempt. + * @return void + */ + private function log_failed_attempt( string $reason ): void { + $logs = get_option( 'google_login_logs', [] ); + $log_entry = [ + 'timestamp' => current_time( 'mysql' ), + 'reason' => $reason, + ]; + + // Keep only the last 100 entries + array_unshift( $logs, $log_entry ); + $logs = array_slice( $logs, 0, 100 ); + + update_option( 'google_login_logs', $logs ); + } + /** * Add extra meta information about user. * @@ -199,13 +255,18 @@ public function redirect_url( string $url ): string { */ public function state_redirect( array $state ): array { $redirect_to = Helper::filter_input( INPUT_GET, 'redirect_to', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); + + // Get the default redirect URL from settings + $settings = plugin()->container()->get( 'settings' ); + $default_redirect = $settings->redirect_url; + /** * Filter the default redirect URL in case redirect_to param is not available. * Default to admin URL. * * @param string $admin_url Admin URL address. */ - $state['redirect_to'] = $redirect_to ?? apply_filters( 'rtcamp.google_default_redirect', admin_url() ); + $state['redirect_to'] = $redirect_to ?? ( $default_redirect ?: apply_filters( 'rtcamp.google_default_redirect', admin_url() ) ); return $state; } @@ -225,9 +286,19 @@ public function login_redirect(): void { $state = base64_decode( $state ); $state = $state ? json_decode( $state ) : null; - if ( ( $state instanceof stdClass ) && ! empty( $state->provider ) && 'google' === $state->provider && ! empty( $state->redirect_to ) ) { - wp_safe_redirect( $state->redirect_to, 302, 'Login with Google' ); - exit; + if ( ( $state instanceof stdClass ) && ! empty( $state->provider ) && 'google' === $state->provider ) { + // Check for the global redirect URL option first + $global_redirect = get_option( 'google_login_redirect_url' ); + if ( ! empty( $global_redirect ) ) { + wp_safe_redirect( $global_redirect, 302, 'Login with Google' ); + exit; + } + + // If no global redirect is set, use the state redirect + if ( ! empty( $state->redirect_to ) ) { + wp_safe_redirect( $state->redirect_to, 302, 'Login with Google' ); + exit; + } } } } diff --git a/src/Modules/Settings.php b/src/Modules/Settings.php index bf916d65..8422e660 100644 --- a/src/Modules/Settings.php +++ b/src/Modules/Settings.php @@ -23,6 +23,9 @@ * @property bool|null registration_enabled * @property bool|null one_tap_login * @property string one_tap_login_screen + * @property string|null redirect_url + * @property string|null allowed_domains + * @property bool|null dev_mode * * @package RtCamp\GoogleLogin\Modules */ @@ -47,6 +50,9 @@ class Settings implements ModuleInterface { 'WP_GOOGLE_LOGIN_WHITELIST_DOMAINS' => 'whitelisted_domains', 'WP_GOOGLE_ONE_TAP_LOGIN' => 'one_tap_login', 'WP_GOOGLE_ONE_TAP_LOGIN_SCREEN' => 'one_tap_login_screen', + 'WP_GOOGLE_LOGIN_REDIRECT_URL' => 'redirect_url', + 'WP_GOOGLE_LOGIN_ALLOWED_DOMAINS' => 'allowed_domains', + 'WP_GOOGLE_LOGIN_DEV_MODE' => 'dev_mode', ]; /** @@ -153,6 +159,33 @@ function () { 'wp_google_login_section', [ 'label_for' => 'whitelisted-domains' ] ); + + add_settings_field( + 'wp_google_login_redirect_url', + __( 'Default Redirect URL', 'login-with-google' ), + [ $this, 'redirect_url_field' ], + 'login-with-google', + 'wp_google_login_section', + [ 'label_for' => 'redirect-url' ] + ); + + add_settings_field( + 'wp_google_login_allowed_domains', + __( 'Allowed Email Domains', 'login-with-google' ), + [ $this, 'allowed_domains_field' ], + 'login-with-google', + 'wp_google_login_section', + [ 'label_for' => 'allowed-domains' ] + ); + + add_settings_field( + 'wp_google_login_dev_mode', + __( 'Developer Mode', 'login-with-google' ), + [ $this, 'dev_mode_field' ], + 'login-with-google', + 'wp_google_login_section', + [ 'label_for' => 'dev-mode' ] + ); } /** @@ -304,6 +337,51 @@ public function whitelisted_domains(): void { + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ display_login_logs(); ?> ' . esc_html__( 'No login attempts logged yet.', 'login-with-google' ) . '

'; + return; + } + ?> + + + + + + + + + + + + + + + +
+