Skip to content

Commit 6295969

Browse files
committed
Update readme.md
1 parent 563c2db commit 6295969

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

README.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ should be changed to:
1616
"phpfui/constantcontact": ">=22.3",
1717
```
1818

19-
## New OAuth2 PKCE Authentication effective April 1, 2022
20-
As of March 31, 2022, Constant Contact will no longer be supporting versions of this library before 22.3. You must upgrade you app on the Constant Contact site. A new secret is also suggested. You must also upgrade to the 22.3 version of this library. The only code change needed is to pass the parameter array ($_GET) to acquireAccessToken instead of the single code parameter.
21-
22-
This library now requires PHP Session support for authentication. See [PHP Manual](https://www.php.net/manual/en/session.security.php) and [a good best practices article](https://www.phparch.com/2018/01/php-sessions-in-depth/). You can provide your own session management by specifying a callback with **setSessionCallback**.
19+
## Requirements
20+
This library requires PHP Session support for authentication. See [PHP Manual](https://www.php.net/manual/en/session.security.php) and [a good best practices article](https://www.phparch.com/2018/01/php-sessions-in-depth/). You can provide your own session management by specifying a callback with **setSessionCallback**.
2321

2422
## Namespaces
2523
This library normalizes the [Constant Contact API](https://v3.developer.constantcontact.com/api_guide/index.html) to modern PHP class standards. All endpoints are first character capitialized. Underscores are removed and followed by a capital letter. Each end point is a class with methods matching the standard REST methods (ie. put, post, delete, put, etc.). The methods take required and optional parameters matching the name specified in the Constant Contact YAML API. In addition, this library supports all definitions of types in the API. See below.
@@ -57,29 +55,43 @@ You will need to set up a web page where your user can enter the *API Key* and *
5755

5856
## The Authorization control flow is as follows:
5957

60-
1. Create a Client with the API Key and Secret and specify a Redirect URI which will receive a code from Constant Contact.
61-
2. Redirect to $client->getAuthorizationURL(); User will authorize and redirected back to the $redirectURI you provide.
62-
3. Retrieve the code and save access and refresh tokens for later use. Redirect back to where ever.
63-
64-
### 1. Create A Client
58+
### 1. Create A Client and Redirect to Authorization URL
6559
```php
66-
$client = new \PHPFUI\ConstantContact\Client($apiKey, $secret, $tokenURL);
60+
$redirectURI = 'http://yourdomain/php_script_in_step2.php';
61+
$client = new \PHPFUI\ConstantContact\Client($apiKey, $secret, $redirectURI);
6762
// set any scopes here, defaults to all scopes. Your user will need to accept what ever scopes you specify.
68-
```
69-
### 2. Redirect to Authorization URL
70-
```php
7163
\header('location: ' . $client->getAuthorizationURL());
7264
```
7365
The above will ask the user to authorize the app for the scopes you specified. The default is all scopes, but you can specify different scopes after constructing the client and before you authorize.
7466

75-
### 3. Retrieve the Code sent to the $redirectURI
67+
### 2. Retrieve the Code sent to the $redirectURI
7668
```php
7769
$client->acquireAccessToken($_GET);
7870
// Save $client->accessToken and $client->refreshToken to the database
79-
// redirect back to where ever
71+
// redirect back to your businesss logic (Step 3)
8072
```
73+
You have now recieved authorization to access the API according to the scopes you requested.
8174

82-
You should now be authorized to use the API. Make sure you save and restore the access token and refresh tokens every time you access the API.
75+
### 3. Use in your code
76+
```php
77+
$client = new \PHPFUI\ConstantContact\Client($apiKey, $secret, $redirectURI);
78+
$client->accessToken = $accessTokenFromDatabase;
79+
$client->refreshToken = $refreshTokenFromDatabase;
80+
$listEndPoint = new \PHPFUI\ConstantContact\V3\ContactLists($client);
81+
$lists = $listEndPoint->get();
82+
do {
83+
print_r($lists);
84+
$lists = $listEndPoint->next();
85+
} while ($lists);
86+
```
87+
You can now access the API with the scopes you requested.
88+
89+
### 4. Refresh the token on a regular basis
90+
```php
91+
$client->refreshToken();
92+
// save $client->accessToken and $client->refreshToken to database.
93+
```
94+
The token will expire requiring your user to reauthorize your app unless you refresh the token. You should refresh the token on a regular basis to avoid reauthorization.
8395

8496
## Versioning
8597
Since the [Constant Contact API](https://v3.developer.constantcontact.com/api_guide/index.html) is constantly being updated, this library will track all updates on a calendar based versioning schema. The major version will be the last two digits of the year the update was released. The minor version will be the month it was released. Any bug fixes will be a patch version. So V21.8.0 would be the first August 2021 version, and V21.8.1 would be a bug fix to V21.8. All bug fixes will be included in subsequent versions, so V21.9.0 would include all fixes from the V21.8 version. YAML changes are tracked nightly and a new version will be generated automatically. Multiple YAML changes in a month will be tracked as patch versions.

0 commit comments

Comments
 (0)