rtCamp / login-with-google

Minimal plugin which allows WordPress user to login with google.

Home Page:https://wordpress.org/plugins/login-with-google/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Login with Google

WordPress plugin to login/register with google

  1. Overview

  2. Installation

  3. Usage Instructions

    Plugin Constants Hooks

  4. Shortcode

  5. Minimum Requirements

  6. License

Overview

Login with google provides seamless experience for users to login in to WordPress sites using their google account. No need to manually create accounts, no need to remember quirky passwords. Just one click and land into the site!

Installation

  1. Clone this repository.
  2. Run composer install --no-dev from inside the cloned directory.
  3. Upload the directory to wp-content/plugins directory.
  4. Activate the plugin from WordPress dashboard.

Browser support

These browsers are supported. Note, for example, that One Tap Login is not supported in Safari.

Usage Instructions

  1. You will need to register a new application at https://console.cloud.google.com/apis/dashboard

  2. Authorization callback URL should be like https://yourdomain.com/wp-login.php, where https://yourdomain.com will be replaced by your site URL.

  3. Once you create the app, you will receive the Client ID and Client Secret, add these credentials in Settings > Login with google settings page in their respective fields.

  4. Create new user enables new user registration irrespective of Membership settings in Settings > General; as sometimes enabling user registration can lead to lots of spam users. Plugin will take this setting as first priority and membership setting as second priority, so if any one of them is enabled, new users will be registered by this plugin after successful authorization.

  5. Whitelisted Domains allows users from specific domains (domain in email) to get registered on site. This will prevent unwanted registration on website. For Example: If you want users only from your organization (myorg.com) to get registered on the website, you enter myorg.com in whitelisted domains. Users with google email like abc@myorg.com will be able to register on website. Contrary to this, users with emails like something@gmail.com would not be able to register here.

Plugin Constants

Above mentioned settings can also be configured via PHP constants by defining them in wp-config.php file.

Refer following list of constants.

Type Description
WP_GOOGLE_LOGIN_CLIENT_ID String Google client ID of your application.
WP_GOOGLE_LOGIN_SECRET String Secret key of your application
WP_GOOGLE_LOGIN_USER_REGISTRATION Boolean (Optional) Set True If you want to enable new user registration. By default, user registration defers to Settings > General Settings > Membership if constant is not set.
WP_GOOGLE_LOGIN_WHITELIST_DOMAINS String (Optional) Domain name, if you want to restrict login with your custom domain. By default, It will allow all domains. You can whitelist multiple domains.

These constants can also be configured via wp-cli.

Note: If you have defined the constant in wp-config.php file, corresponding settings field will be disable (locked for editing) on the settings page.

Hooks

Filters

Filter Description Parameters
rtcamp.google_scope This filter can be used to filter existing scope used in Google Sign in.
You can ask for additional permission while user logs in.
  • scope - contains array of scopes.
rtcamp.google_login_modules Filter out active modules before modules are initialized.
  • active_modules - contains array of active modules.
rtcamp.google_login_button_display This filter is useful where we want to forcefully display login button, even when user is already logged-in in system.
  • display - contains a boolean value of whether to display the button or not.
rtcamp.google_default_redirect Filter the default redirect URL in case redirect_to param is not available.
Default to admin URL.
  • admin_url - contains the admin URL address which is used as redirect URL by default.
rtcamp.google_register_user Check if we need to register the user.
  • user - contains the user object from google.
rtcamp.google_client_args Filter the arguments for sending in query.
This is useful in cases for example: choosing the correct prompt.
  • client_args - contains the list of query arguments to send to Google OAuth.
rtcamp.google_login_state Filters the state to pass to the Google API.
  • state_data - contains the default state data.
rtcamp.default_algorithm Filters default algorithm for openssl signature verification
  • default_algo - Default algorithm.
  • algo - Algorithm from JWT header.

Actions

Action Description Parameters
rtcamp.google_login_services Define any additional services.
  • container - Container object.
rtcamp.google_user_authenticated Fires once the user has been authenticated via Google OAuth.
  • user - User object.
rtcamp.id_token_verified Do something when token has been verified successfully.
If we are here that means ID token has been verified.
rtcamp.google_user_logged_in Fires once the user has been authenticated.
  • user_wp - WP User data object.
  • user - User data object returned by Google.
rtcamp.google_user_created Fires once the user has been registered successfully.
  • uid - User ID
  • user - WP user object.
rtcamp.login_with_google_exception Fires when an exception is raised during token verification.
  • exception - The exception which is being raised.

Shortcode

You can add the google login button to any page/post using shortcode: google_login

Example:

[google_login button_text="Google Login" force_display="yes" /]

Supported attributes for shortcode

Parameter Description Values Default
button_text Text to show for login button string Login with google
force_display Whether to display button when user is already logged in yes/no no
redirect_to URL where user should be redirected post login URL wp-admin

Contribute

Reporting a bug ๐Ÿž

Before creating a new issue, do browse through the existing issues for resolution or upcoming fixes.

If you still need to log an issue, making sure to include as much detail as you can, including clear steps to reproduce your issue if possible.

Creating a pull request

Want to contribute a new feature? Start a conversation by logging an issue.

Once you're ready to send a pull request, please run through the following checklist:

  1. Browse through the existing issues for anything related to what you want to work on. If you don't find any related issues, open a new one.

  2. Fork this repository.

  3. Create a branch from develop for each issue you'd like to address and commit your changes.

  4. Push the code changes from your local clone to your fork.

  5. Open a pull request and that's it! We'll with feedback as soon as possible (Isn't collaboration a great thing? ๐Ÿ˜Œ)

  6. Once your pull request has passed final code review and tests, it will be merged into develop and be in the pipeline for the next release. Props to you! ๐ŸŽ‰

Unit testing

Unit tests can be run with simple command composer tests:unit. Please note that you'll need to do composer install (need to install dev dependencies) for running unit tests.

You should have PHP CLI > 7.1 installed. If you have Xdebug enabled with php, code coverage report will be generated at /tmp/report/html

Minimum Requirements

WordPress >= 5.5.0

PHP >= 7.4

License

This library is released under "GPL 2.0 or later" License.

BTW, We're Hiring!

Join us at rtCamp, we specialize in providing high performance enterprise WordPress solutions

About

Minimal plugin which allows WordPress user to login with google.

https://wordpress.org/plugins/login-with-google/

License:GNU General Public License v2.0


Languages

Language:PHP 61.6%Language:TypeScript 21.1%Language:JavaScript 16.7%Language:SCSS 0.6%