Skip to content

Commit

Permalink
Minimal structure with no external library
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankit Gade committed May 31, 2021
1 parent 13f8c1a commit 2055fcd
Show file tree
Hide file tree
Showing 808 changed files with 7,007 additions and 126,074 deletions.
428 changes: 225 additions & 203 deletions LICENSE

Large diffs are not rendered by default.

187 changes: 65 additions & 122 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,131 +1,74 @@
<p align="center">
<a href="https://rtcamp.com/?ref=wp-menu-custom-fields-repo" target="_blank"><img width="200"src="https://rtcamp.com/wp-content/themes/rtcamp-v9/assets/img/site-logo-black.svg"></a>
</p>

# Log in with Google

<a href="https://www.repostatus.org/#active"><img src="https://www.repostatus.org/badges/latest/active.svg" alt="Project Status: Active – The project has reached a stable, usable state and is being actively developed."></a>

Minimal plugin that allows WordPress users to log in using Google.

**Author:** rtCamp

**Tags:** Google login, sign in, sso, oauth, authentication, sign-in, single sign-on, log in

**Requires at least:** 5.0

**Tested up to:** 5.7

**Requires PHP version:** 7.0

**Stable tag:** 1.0.10

**License:** GPLv2 or later (of course!)

**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

## Setup

1. If you're cloning repo, then after cloning run `composer install --no-dev` to install dependencies. GitHub release zip and WordPress.org download can skip this step.
2. Create a project from [Google Developers Console](https://console.developers.google.com/apis/dashboard) if none exists.
3. Go to **Credentials** tab, then create credential for OAuth client.
* Application type will be **Web Application**
* Add `YOUR_DOMAIN/wp-login.php` in **Authorized redirect URIs**
4. This will give you **Client ID** and **Secret key**.
5. Input these values either in `WP Admin > Settings > WP Google Login`, or in `wp-config.php` using the following code snippet:

```php
define( 'WP_GOOGLE_LOGIN_CLIENT_ID', 'YOUR_GOOGLE_CLIENT_ID' );
define( 'WP_GOOGLE_LOGIN_SECRET', 'YOUR_SECRET_KEY' );
```

### How to enable automatic user registration?

You can enable user registration either by
- Checking `Settings > WP Google Login > Enable Google Login Registration`
OR
- Adding `define( 'WP_GOOGLE_LOGIN_USER_REGISTRATION', 'true' );` in wp-config.php file.

Note: If the checkbox is ON then, it will register valid Google users even when WordPress default setting, under `Settings > General Settings > Membership > Anyone can register` checkbox is OFF.

### How to restrict user registration to one or more domain(s)?

By default, when you enable user registration via constant `WP_GOOGLE_LOGIN_USER_REGISTRATION` or enable `Settings > WP Google Login > Enable Google Login Registration`, it will create a user for any Google login (including gmail.com users). If you are planning to use this plugin on a private, internal site, then you may like to restrict user registration to users under a single Google Suite organization. This configuration variable does that.

Add your domain name, without any schema prefix and `www,` as the value of `WP_GOOGLE_LOGIN_WHITELIST_DOMAINS` constant or in the settings `Settings > WP Google Login > Whitelisted Domains`. You can whitelist multiple domains. Please separate domains with commas. See the below example to know how to do it via constants:

```php
define( 'WP_GOOGLE_LOGIN_WHITELIST_DOMAINS', 'example.com,sample.com' );
# Login with Github

> WordPress plugin to login/register with github
1. [Overview](#overview)
2. [Installation](#installation)
3. [Usage Instructions](#usage-instructions)
4. [Shortcode](#shortcode)
5. [Minimum Requirements](#minimum-requirements)
6. [License](#license)

## Overview

Login with github provides seamless experience for users to login in to WordPress
sites using their github 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.

## Usage Instructions

1. You will need to register a new application at https://github.com/settings/applications/new

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 github` 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 github primary
email like `[email protected]` will be able to register on website. Contrary to this, users with emails like
`[email protected]` would not be able to register here.

## Shortcode

You can add the github login button to any page/post using shortcode: `gh_login`

**Example:**
```php
[gh_login button_text="Github Login" force_display="yes" /]
```

**Note:** If a user already exists, they **will be allowed to login with Google** regardless of whether their domain is whitelisted or not. Whitelisting will only prevent users from **registering** with email addresses from non-whitelisted domains.


## Hooks

### 1. Action `wp_google_login_token`

This action provides access token received after Google login.
**Parameters:**
* `token` (Array): Converted token using `fetchAccessTokenWithAuthCode` method of `Google_Client` class.
* `user_info` (Array): Details of user after login.
* `client` (Object): `Google_Client` object in use.

### 2. Filter `wp_google_login_scopes`

This filter can be used to filter existing scope used in Google Sign in.
You can ask for additional permission while user logs in.

This filter will provide 1 parameter `scopes` in callback, which contains array of scopes.


## wp-config.php parameters list

| | 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. |


## Contribute

### Reporting a bug 🐞

Before creating a new issue, do browse through the [existing issues](https://github.com/rtCamp/login-with-google/issues) for resolution or upcoming fixes.

If you still need to [log an issue](https://github.com/rtCamp/login-with-google/issues/new), 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](https://github.com/rtCamp/login-with-google/issues).

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

1. Browse through the [existing issues](https://github.com/rtCamp/login-with-google/issues) for anything related to what you want to work on. If you don't find any related issues, open a new one.

1. Fork this repository.

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

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

1. Open a pull request and that's it! We'll with feedback as soon as possible (Isn't collaboration a great thing? 😌)

1. 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
**Supported attributes for shortcode**

- Setup local unit test environment by running script from terminal
| Parameter | Description | Values | Default |
| -------------- | --------------------------------------------------------------| -------| ------------------ |
| button_text | Text to show for login button | string | Login with github |
| 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` |

```./bin/install-wp-tests.sh <db-name> <db-user> <db-pass> [db-host] [wp-version] [skip-database-creation]```

- Execute `phpunit` in terminal from repository to run all test cases.
## Minimum Requirements

- Execute `phpunit ./tests/inc/test-class.php` in terminal with file path to run specific tests.
WordPress >= 5.4.0

PHP >= 7.1

## BTW, We're Hiring!
## License

<a href="https://rtcamp.com/"><img src="https://rtcamp.com/wp-content/uploads/2019/04/[email protected]" alt="Join us at rtCamp, we specialize in providing high performance enterprise WordPress solutions"></a>
This library is released under
["GPL 2.0 or later" License](LICENSE).
1 change: 0 additions & 1 deletion assets/.nvmrc

This file was deleted.

1 change: 0 additions & 1 deletion assets/build/css/login.css

This file was deleted.

Binary file removed assets/build/images/google_light.png
Binary file not shown.
1 change: 0 additions & 1 deletion assets/build/js/login.js

This file was deleted.

66 changes: 66 additions & 0 deletions assets/css/login.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
.login form#loginform {
padding: 26px 24px 115px !important;
position: relative;
}

.login .wp_github_login {
position: absolute;
bottom: 10px;
width: 85%;
left: 50%;
text-align: center;
transform: translateX(-50%);
z-index: 99;
}

.login .wp_github_login__button-container {
position: relative;
}

.login .wp_github_login__button-container::before {
content: 'OR';
position: absolute;
top: -19px;
width: 40px;
left: 50%;
background: #fff;
z-index: 9;
transform: translateX(-50%);
font-weight: 700;
}

.login .wp_github_login__button-container::after {
content: '';
width: 100%;
background: #ddd;
height: 1px;
position: absolute;
left: 0;
top: -10px;
}

.wp_github_login__button {
display: inline-block;
color: #f1f1f1;
text-decoration: none;
font-size: 16px;
padding: 10px 20px 10px 52px;
border-radius: 4px;
margin: 12px 0;
letter-spacing: 0.5px;
border: 1px solid #333333;
transition: all 0.3s ease-in-out;
background: url(../images/GitHub-mark-light.png) no-repeat scroll 20px center #333333;
background-size: 25px;
}

.wp_github_login__button:hover {
color: #333333;
border: 1px solid #333333;
background: url(../images/GitHub-mark.png) no-repeat scroll 20px center transparent;
background-size: 25px;
}

.wp_github_login__button:focus, .wp_github_login__button:active {
outline: none;
}
Binary file added assets/images/GitHub-mark-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/GitHub-mark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions assets/mix-manifest.json

This file was deleted.

Loading

0 comments on commit 2055fcd

Please sign in to comment.