Skip to content

Commit d7a7dcc

Browse files
author
Grace Yim
committed
Simplify README and add iframe info
1 parent e3cc2be commit d7a7dcc

1 file changed

Lines changed: 61 additions & 44 deletions

File tree

README.md

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,34 @@
1-
# ToopherPHP [![Build
2-
Status](https://travis-ci.org/toopher/toopher-php.png?branch=master)](https://travis-ci.org/toopher/toopher-php)
1+
# ToopherPHP [![Build Status](https://travis-ci.org/toopher/toopher-php.png?branch=master)](https://travis-ci.org/toopher/toopher-php)
32

4-
#### Introduction
53
ToopherPHP is a Toopher API library that simplifies the task of interfacing with the Toopher API from PHP code. This project includes all the dependency libraries and handles the required OAuth and JSON functionality so you can focus on just using the API.
64

7-
#### Learn the Toopher API
8-
Make sure you visit [http://dev.toopher.com](http://dev.toopher.com) to get acquainted with the Toopher API fundamentals. The documentation there will tell you the details about the operations this API wrapper library provides.
5+
### PHP Version
6+
\>=5.3.0
97

10-
#### OAuth Authentication
8+
### Documentation
9+
Make sure you visit [https://dev.toopher.com](https://dev.toopher.com) to get acquainted with the Toopher API fundamentals. The documentation there will tell you the details about the operations this API wrapper library provides.
1110

12-
The first step to accessing the Toopher API is to sign up for an account at the development portal [http://dev.toopher.com](http://dev.toopher.com) and create a "requester". When that process is complete, your requester is issued OAuth 1.0a credentials in the form of a consumer key and secret. Your key is used to identify your requester when Toopher interacts with your customers, and the secret is used to sign each request so that we know it is generated by you. This library properly formats each request with your credentials automatically.
11+
## ToopherApi Workflow
1312

14-
#### The Toopher Two-Step
15-
Interacting with the Toopher web service involves two steps: pairing, and authenticating.
16-
17-
##### Pair
18-
Before you can enhance your website's actions with Toopher, your customers will need to pair their phone's Toopher app with your website. To do this, they generate a unique, nonsensical "pairing phrase" from within the app on their phone. You will need to prompt them for a pairing phrase as part of the Toopher enrollment process. Once you have a pairing phrase, just send it to the Toopher API along with your requester credentials and we'll return a pairing ID that you can use whenever you want to authenticate an action for that user.
19-
20-
##### Authenticate
21-
You have complete control over what actions you want to authenticate using Toopher (for example: logging in, changing account information, making a purchase, etc.). Just send us the user's pairing ID, a name for the terminal they're using, and a description of the action they're trying to perform and we'll make sure they actually want it to happen.
22-
23-
#### Librarified
24-
This library makes it super simple to do the Toopher two-step. Check it out:
13+
### Step 1: Pair
14+
Before you can enhance your website's actions with Toopher, your customers will need to pair their mobile device's Toopher app with your website. To do this, they generate a unique pairing phrase from within the app on their mobile device. You will need to prompt them for a pairing phrase as part of the Toopher enrollment process. Once you have a pairing phrase, just send it to the Toopher web service along with your requester credentials and we'll return a pairing ID that you can use whenever you want to authenticate an action for that user.
2515

2616
```php
2717
require_once("toopher_api.php");
2818

2919
// Create an API object using your credentials
3020
$toopherApi = new ToopherApi("<your consumer key>", "<your consumer secret>");
3121

32-
// Step 1 - Pair with their phone's Toopher app
33-
// With pairing phrase
22+
// Step 1 - Pair with their mobile device's Toopher app
3423
$pairing = $toopherApi->pair("username@yourservice.com", "pairing phrase");
35-
// With SMS
36-
$pairing = $toopherApi->pair("username@yourservice.com", "555-555-5555");
37-
// With QR code
38-
$pairing = $toopherApi->pair("username@yourservice.com");
24+
```
3925

26+
### Step 2: Authenticate
27+
You have complete control over what actions you want to authenticate using Toopher (logging in, changing account information, making a purchase, etc.). Just send us the username or pairing ID and we'll make sure they actually want it to happen. You can also choose to provide the following optional parameters: terminal name, requester specified ID and action name (*default: "Log in"*).
4028

29+
```php
4130
// Step 2 - Authenticate a log in
42-
// With a pairing id and terminal name
43-
$authRequest = $toopherApi->authenticate($pairing->id, "my computer");
44-
// With a username, terminal name and requester specified terminal id
45-
$authRequest = $toopherApi->authenticate("username", "my computer", "requester specified id");
46-
31+
$authRequest = $toopherApi->authenticate("username", "my computer");
4732

4833
// Once they've responded you can then check the status
4934
$authRequest->refreshFromServer();
@@ -52,33 +37,65 @@ if ($authRequest->pending == false && $authRequest->granted == true) {
5237
}
5338
```
5439

55-
#### Dependencies
56-
Toopher manages dependencies with [composer](http://getcomposer.org). To ensure all dependencies are up-to-date, execute the following command:
57-
```shell
58-
$ composer install
40+
## ToopherIframe Workflow
41+
42+
### Step 1: Embed a request in an IFRAME
43+
1. Generate an authentication URL by providing a username.
44+
2. Display a webapage to your user that embeds this URL within an `<iframe>` element.
45+
46+
```php
47+
require_once("toopher_api.php")
48+
49+
// Create an API object using your credentials
50+
$iframeApi = new ToopherIframe("<your consumer key>", "<your consumer secret>");
51+
52+
$authIframeUrl = $iframeApi->getAuthenticationUrl("username@yourservice.com");
53+
54+
// Add an <iframe> element to your HTML:
55+
// <iframe id="toopher-iframe" src=authIframeUrl />
5956
```
60-
from the root directory the package (the same directory that this README is located in)
6157

62-
#### Handling Errors
58+
### Step 2: Validate the postback data
59+
60+
The simplest way to validate the postback data is to call `isAuthenticationGranted` to check if the authentication request was granted.
61+
62+
```php
63+
// Retrieve the postback data as a string from POST parameter 'iframe_postback_data'
64+
65+
// Returns boolean indicating if authentication request was granted by user
66+
$authenticationRequestGranted = $iframeApi->isAuthenticationGranted(postback_data)
67+
68+
if ($authenticationRequestGranted) {
69+
// Success!
70+
}
71+
```
72+
73+
### Handling Errors
6374
If any request runs into an error a `ToopherRequestException` will be thrown with more details on what went wrong.
6475

65-
#### Example code
66-
Check out demo/toopher_demo.php for an example program that walks you through the whole process! Simply execute the script as follows:
76+
### Demo
77+
Check out `demo/toopher_demo.php` for an example program that walks you through the whole process! Simply run the command below:
6778
```shell
6879
$ php demo/toopher_demo.php
6980
```
70-
To avoid being prompted for your Toopher API key and secret, you can define them in the $TOOPHER_CONSUMER_KEY and $TOOPHER_CONSUMER_SECRET environment variables
7181

72-
#### Tests
73-
To run all unit tests:
82+
## Contributing
83+
### Dependencies
84+
Toopher manages dependencies with [composer](http://getcomposer.org). To ensure all dependencies are up-to-date run the command below from the root directory:
85+
```shell
86+
$ composer install
87+
```
88+
89+
### Tests
90+
To run the tests enter:
7491
```shell
7592
$ phpunit test
7693
```
77-
Note: `phpunit` may be found in `vendor/bin/php` so your test command
78-
would be
94+
*Note: `phpunit` may be found in `vendor/bin/php` so your test command
95+
would be:*
7996
```shell
8097
$ vendor/bin/phpunit test
8198
```
8299

83-
#### License
84-
ToopherPHP is licensed under the MIT License. See LICENSE.txt for the full license text.
100+
## License
101+
ToopherPHP is licensed under the MIT License. See LICENSE.txt for the full text.

0 commit comments

Comments
 (0)