diff --git a/.travis.yml b/.travis.yml index 0a7eb47..a991c74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,6 @@ php: before_script: composer install script: - mkdir -p build/logs - - php vendor/bin/phpunit -c phpunit.xml.dist + - php vendor/bin/phpunit test after_script: - php vendor/bin/coveralls -v diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..ac87d1c --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,7 @@ +Copyright (c) 2012 Toopher, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 0e13260..7aed739 100644 --- a/README.md +++ b/README.md @@ -1,78 +1,101 @@ -# ToopherAPI PHP Client +# ToopherPHP [![Build Status](https://travis-ci.org/toopher/toopher-php.png?branch=master)](https://travis-ci.org/toopher/toopher-php) -[![Build -Status](https://travis-ci.org/toopher/toopher-php.png?branch=master)](https://travis-ci.org/toopher/toopher-php) +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. -#### Introduction -ToopherAPI PHP Client 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. +### PHP Version +\>=5.3.0 -#### Learn the Toopher API -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. +### Documentation +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. -#### OAuth Authentication +## ToopherApi Workflow -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. - -#### The Toopher Two-Step -Interacting with the Toopher web service involves two steps: pairing, and authenticating. - -##### Pair -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. - -##### Authenticate -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. - -#### Librarified -This library makes it super simple to do the Toopher two-step. Check it out: +### Step 1: Pair +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. ```php require_once("toopher_api.php"); // Create an API object using your credentials -$toopherApi = new ToopherAPI($key, $secret); +$toopherApi = new ToopherApi("", ""); -// Step 1 - Pair with their phone's Toopher app -$pairing = $toopherApi->pair("pairing phrase", "username@yourservice.com"); +// Step 1 - Pair with their mobile device's Toopher app +$pairing = $toopherApi->pair("username@yourservice.com", "pairing phrase"); +``` + +### Step 2: Authenticate +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"*). +```php // Step 2 - Authenticate a log in -$authStatus = $toopherApi->authenticate($pairingStatus['id'], "my computer"); +$authRequest = $toopherApi->authenticate("username", "my computer"); // Once they've responded you can then check the status -while($authStatus['pending']){ - $authStatus = $toopherApi->getAuthenticationStatus($authStatus['id']); - sleep(1); -} -if($authStatus['granted']){ - // Success! -} else { - // user declined the authorization! +$authRequest->refreshFromServer(); +if ($authRequest->pending == false && $authRequest->granted == true) { + // Success! } ``` -#### Dependencies -Toopher manages dependencies with [composer](http://getcomposer.org). To ensure all dependencies are up-to-date, execute the following command: -```shell -$ composer install +## ToopherIframe Workflow + +### Step 1: Embed a request in an IFRAME +1. Generate an authentication URL by providing a username. +2. Display a webapage to your user that embeds this URL within an `