Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OAuth authentication #47

Merged
merged 46 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
dd0c828
Initial oAuth connect implementation.
iamdharmesh Aug 5, 2024
0c98dbb
UI updates and added loader on connect page.
iamdharmesh Aug 6, 2024
b69e650
Add verify access token logic.
iamdharmesh Aug 6, 2024
33cb1e4
Add encryption class.
iamdharmesh Aug 6, 2024
cec3d88
Show modal to users for blocked-popup.
iamdharmesh Aug 6, 2024
4124d36
Update API class to use access token if it is available.
iamdharmesh Aug 6, 2024
c9cf283
Fix spacing issue.
iamdharmesh Aug 6, 2024
416face
Remove existing login form.
iamdharmesh Aug 6, 2024
796e630
Fix js lint error.
iamdharmesh Aug 6, 2024
5daf4f3
Remove use of string template from js.
iamdharmesh Aug 7, 2024
54d1725
Display error message in case of lists API fail.
iamdharmesh Aug 7, 2024
896076b
Added admin notice for the invalid/revoked token.
iamdharmesh Aug 7, 2024
3f893f2
Display spinner on try-again popup.
iamdharmesh Aug 7, 2024
c520dd3
Increase request timeout to 10 seconds.
iamdharmesh Aug 7, 2024
23112f9
Apply suggestions from code review
iamdharmesh Aug 7, 2024
f4ae7f4
Addressed PR feedback.
iamdharmesh Aug 7, 2024
4073bbb
Add note in readme for the encryption constants.
iamdharmesh Aug 7, 2024
e7bc6f1
readme.txt updates.
iamdharmesh Aug 7, 2024
19e72d1
Wording updates on connect page.
iamdharmesh Aug 7, 2024
1198ebb
Show notice for re-connect incase of token decryption fail.
iamdharmesh Aug 7, 2024
c2c9189
Readme updates
dkotter Aug 7, 2024
ed0edf0
Minor formatting cleanup
dkotter Aug 7, 2024
3afeb88
Use oauth url from the server side.
iamdharmesh Aug 8, 2024
b433be3
Merge branch 'enhancement/9' of github.com:mailchimp/wordpress into e…
iamdharmesh Aug 8, 2024
01deb4b
Upgrade "@10up/cypress-wp-utils" to 0.4.0
iamdharmesh Aug 8, 2024
3aed9d2
Upgrade cypress to 13.13.2
iamdharmesh Aug 8, 2024
1b01593
Added admin tests.
iamdharmesh Aug 8, 2024
74fae4c
Added connect to mailchimp test.
iamdharmesh Aug 8, 2024
d61ab47
Add settings, shortcode and block tests.
iamdharmesh Aug 8, 2024
ee0884e
Added tests for remove CSS and custom styling.
iamdharmesh Aug 8, 2024
5bfe73e
Added some more settings tests.
iamdharmesh Aug 8, 2024
a63ad60
Add logout tests.
iamdharmesh Aug 8, 2024
91f09c2
Updated E2E workflow file.
iamdharmesh Aug 8, 2024
6e7dc08
Readme updates.
iamdharmesh Aug 8, 2024
a1c8102
Trigger E2E tests.
iamdharmesh Aug 8, 2024
554fa37
Add block name in insertBlock command.
iamdharmesh Aug 8, 2024
57c0058
Addressed improvements feedback.
iamdharmesh Aug 9, 2024
ab923bd
Merge branch 'enhancement/9' of github.com:mailchimp/wordpress into e…
iamdharmesh Aug 9, 2024
c633d39
Some improvements in settings tests.
iamdharmesh Aug 9, 2024
1caefec
Fix shortcode form create issue.
iamdharmesh Aug 9, 2024
86e9489
Add retry in run mode.
iamdharmesh Aug 9, 2024
3921ba6
Update E2E workflow to use zip built by generate zip action.
iamdharmesh Aug 9, 2024
4fe1d6e
Try fix connect tests in trunk env.
iamdharmesh Aug 9, 2024
8cb0929
Merge pull request #48 from mailchimp/enhancement/e2e-tests
dkotter Aug 12, 2024
4175774
Add admin notice for the API key deprecation.
iamdharmesh Aug 13, 2024
9de40f0
Update since statements
dkotter Aug 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ on:
- develop

jobs:
build:
uses: mailchimp/wordpress/.github/workflows/build-release-zip.yml@develop

cypress:
needs: build
name: ${{ matrix.core.name }}
runs-on: ubuntu-latest
env:
CYPRESS_MAILCHIMP_USERNAME: ${{ secrets.MAILCHIMP_USERNAME }}
CYPRESS_MAILCHIMP_PASSWORD: ${{ secrets.MAILCHIMP_PASSWORD }}
strategy:
matrix:
core:
Expand All @@ -24,15 +31,25 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Download build zip
uses: actions/download-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: ${{ github.event.repository.name }}

- name: Display structure of downloaded files
run: ls -R
working-directory: ${{ github.event.repository.name }}

- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install dependencies
run: npm ci

- name: Set the core version
run: ./tests/bin/set-core-version.js ${{ matrix.core.version }}
- name: Set the core version and plugins config
run: ./tests/bin/set-core-version.js --core=${{ matrix.core.version }} --plugins=./${{ github.event.repository.name }}

- name: Set up WP environment
run: npm run env:start
Expand All @@ -41,6 +58,7 @@ jobs:
run: npm run cypress:run

- name: Update summary
if: always()
run: |
npx mochawesome-merge ./tests/cypress/reports/*.json -o tests/cypress/reports/mochawesome.json
rm -rf ./tests/cypress/reports/mochawesome-*.json
Expand Down
38 changes: 35 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

> Add a Mailchimp signup form widget to your WordPress site.

[![Support Level](https://img.shields.io/badge/support-active-green.svg?label=Support)](#support-level) [![GPL-2.0-or-later License](https://img.shields.io/github/license/mailchimp/wordpress?label=License)](https://github.com/mailchimp/wordpress/blob/develop/LICENSE.md) ![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/mailchimp?label=Version) ![WordPress Minimum](https://img.shields.io/wordpress/plugin/wp-version/mailchimp?label=WordPress%20minimum) ![PHP Minimum](https://img.shields.io/wordpress/plugin/required-php/mailchimp?label=PHP%20minimum) ![WordPress Tested Up To](https://img.shields.io/wordpress/plugin/tested/mailchimp?label=WordPress) [![E2E Cypress Tests](https://github.com/mailchimp/wordpress/actions/workflows/e2e.yml/badge.svg)](https://github.com/mailchimp/wordpress/actions/workflows/e2e.yml) [![PHP Compatibility](https://github.com/mailchimp/wordpress/actions/workflows/php-compat.yml/badge.svg)](https://github.com/mailchimp/wordpress/actions/workflows/php-compat.yml) [![PHP Linting](https://github.com/mailchimp/wordpress/actions/workflows/phpcs.yml/badge.svg)](https://github.com/mailchimp/wordpress/actions/workflows/phpcs.yml) [![JS Linting](https://github.com/mailchimp/wordpress/actions/workflows/eslint.yml/badge.svg)](https://github.com/mailchimp/wordpress/actions/workflows/eslint.yml)
[![Support Level](https://img.shields.io/badge/support-active-green.svg?label=Support)](#support-level) [![GPL-2.0-or-later License](https://img.shields.io/github/license/mailchimp/wordpress?label=License)](https://github.com/mailchimp/wordpress/blob/develop/LICENSE.md) ![WordPress Plugin Version](https://img.shields.io/wordpress/plugin/v/mailchimp?label=Version) ![WordPress Minimum](https://img.shields.io/wordpress/plugin/wp-version/mailchimp?label=WordPress%20minimum) ![PHP Minimum](https://img.shields.io/wordpress/plugin/required-php/mailchimp?label=PHP%20minimum) ![WordPress Tested Up To](https://img.shields.io/wordpress/plugin/tested/mailchimp?label=WordPress) [![E2E Cypress Tests](https://github.com/mailchimp/wordpress/actions/workflows/e2e.yml/badge.svg)](https://github.com/mailchimp/wordpress/actions/workflows/e2e.yml) [![PHP Compatibility](https://github.com/mailchimp/wordpress/actions/workflows/php-compat.yml/badge.svg)](https://github.com/mailchimp/wordpress/actions/workflows/php-compat.yml) [![PHP Linting](https://github.com/mailchimp/wordpress/actions/workflows/phpcs.yml/badge.svg)](https://github.com/mailchimp/wordpress/actions/workflows/phpcs.yml) [![JS Linting](https://github.com/mailchimp/wordpress/actions/workflows/eslint.yml/badge.svg)](https://github.com/mailchimp/wordpress/actions/workflows/eslint.yml)

## Overview

Expand All @@ -18,6 +18,21 @@ WordPress.com compatibility is limited to Business tier users only. [How to add

![Configuring extra fields on your Signup Form (optional)](https://github.com/mailchimp/wordpress/blob/develop/.wordpress-org/screenshot-4.jpg?raw=true)

## Access Token Encryption

Starting in version 1.6.0, authentication has changed to use OAuth. As part of this process, we retrieve an access token that can be used to make API requests. To provide a high-level of security, this access token is encrypted before being stored in the WordPress database. In order to ensure this access token can be decrypted when used, the plugin relies on certain security constants that should remain unchanged.

With no additional configuration, we use the standard `LOGGED_IN_KEY` and `LOGGED_IN_SALT` constants that are normally set in your site's `wp-config.php` file. Some sites make use of security plugins that rotate these constants on a periodic basis. When this happens, we won't be able to decrypt the access token and you’ll need to reconnect your Mailchimp account to generate a new access token.

To prevent such issues, it is recommended to define two additional constants in your site's `wp-config.php` file: `MAILCHIMP_SF_ENCRYPTION_KEY` and `MAILCHIMP_SF_ENCRYPTION_SALT`. These constants should consist of a combination of characters, preferably at least 32 characters long. Once set, these values should not be changed. For strong values, you can copy some of the values from [here](https://api.wordpress.org/secret-key/1.1/salt/) and use them. You'll end up with additional code like the following in your `wp-config.php` file:

```php
define( 'MAILCHIMP_SF_ENCRYPTION_KEY', 'put your unique phrase here' );
define( 'MAILCHIMP_SF_ENCRYPTION_SALT', 'put your unique phrase here' );
```

If these constants are added after you've already authenticated with Mailchimp, you will need to reconnect your account. To avoid this, you can copy the values from `LOGGED_IN_KEY` and `LOGGED_IN_SALT` (if they exist) to `MAILCHIMP_SF_ENCRYPTION_KEY` and `MAILCHIMP_SF_ENCRYPTION_SALT` respectively.

## Frequently Asked Questions

### Can I have multiple forms on one page?
Expand All @@ -41,9 +56,9 @@ This section describes how to install the plugin and get started using it.

### Advanced

If you have a custom coded sidebar or bells and whistles that prevent enabling widgets through the WordPress GUI, complete these steps instead.
If you have a custom coded sidebar or bells and whistles that prevent enabling widgets through the WordPress GUI, complete these steps instead.

WordPress v2.8 or higher:
WordPress v2.8 or higher:
` [mailchimpsf_form] `

If you are adding it inside a php code block, pop this in:
Expand Down Expand Up @@ -89,6 +104,23 @@ Currently we have the plugin configured so it can be translated and the followin
* sv_SE - Swedish in Sweden (thanks to [Sebastian Johnsson](http://www.agiley.se/) for contributing)
* tr_TR - Turkish in Turkey (thanks to [Hakan E.](http://kazancexpert.com/) for contributing)

## E2E tests
The `tests` directory contains end-to-end tests for the project, utilizing Cypress to run tests in an environment created using wp-env.

### Pre-requisites
- Node.js v20
- Docker
- Create an account in [Mailchimp](https://mailchimp.com/)

### Run E2E tests in local
1. Run `npm install`.
2. Run `npm run build`.
3. Run `npm run env:start`.
4. Set Mailchimp credentials as environment variables:
- run `export CYPRESS_MAILCHIMP_USERNAME="your mailchimp username"`
- run `export CYPRESS_MAILCHIMP_PASSWORD="your mailchimp password"`
5. Run `npm run cypress:run`. You can also run `npm run cypress:open` to run tests in UI mode.

## Support Level

**Active:** Mailchimp is actively working on this, and we expect to continue work for the foreseeable future including keeping tested up to the most recent version of WordPress. Bug reports, feature requests, questions, and pull requests are welcome.
12 changes: 12 additions & 0 deletions css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,15 @@ th.mailchimp-connect {
#mc-message {
margin-top: 26px;
}

/**
* Mailchimp OAuth CSS
*/
.mailchimp-sf-oauth-section .oauth-error {
display: block;
color: #db3a1b;
}

.mailchimp-sf-oauth-connect-wrapper {
display: flex;
}
Loading
Loading