Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
e7e55d7
Update pair()
Feb 2, 2015
3999c7d
Update authenticate()
Feb 2, 2015
66988cf
Add AdvancedApiUsageFactory, ApiRawRequester, and update get() and po…
Feb 2, 2015
549da75
Add Pairing class
Feb 2, 2015
e3dd31e
Add Pairings and getById
Feb 2, 2015
6aed300
Add AuthenticationRequest
Feb 2, 2015
cea5c36
Add AuthenticationRequests and getById
Feb 2, 2015
7065247
Add Pairing.refreshFromServer()
Feb 2, 2015
61a0157
Add AuthenticationRequest.refreshFromServer()
Feb 2, 2015
4c63b39
Add Pairing->getResetLink()
Feb 2, 2015
a7ae0f0
Add Pairing->emailResetLink()
Feb 2, 2015
fb7d1cd
Add AuthenticationRequest->grantWithOtp()
Feb 11, 2015
89e1732
Update composer.lock for new packages
Feb 19, 2015
189528d
Rename terminal_name_extra to requester_specified_terminal_id
Feb 19, 2015
f2c0b34
Add User and update
Feb 19, 2015
051ddc6
Update Pairing.__construct and update()
Feb 19, 2015
5b181bb
Add UserTerminal and update
Feb 19, 2015
5735f4a
Update AuthenticationRequest.__construct and update()
Feb 19, 2015
283a53c
Add Action and update
Feb 19, 2015
e55e164
Rename grant_with_otp to grantWithOtp to be consistent with other fun…
Feb 19, 2015
48c19de
Add Users.getById
Feb 19, 2015
07a9bbe
Add Users.getByName
Feb 19, 2015
325590b
Fix spacing
Feb 19, 2015
3b73d34
Add Users.create
Feb 19, 2015
6e2fc44
Add ToopherApi.AdvancedApiUsageFactory.UserTerminals
Feb 19, 2015
f585e37
Add UserTerminals.create
Feb 19, 2015
b900d00
Add setUp to tests to create HTTP_Request2_Adapter_Mock
Feb 20, 2015
a85265e
Cleanup tests
Feb 20, 2015
a576092
Add Pairing.getQrCodeImage
Feb 20, 2015
19b6304
Add ToopherObjectFactory for Users, UserTerminals, AuthenticationRequ…
Feb 20, 2015
3b7b365
Reorder classes
Feb 20, 2015
8652e31
Add User.refreshFromServer
Feb 20, 2015
b8a5826
Add User.enableToopherAuthentication
Feb 20, 2015
338c484
Cleanup test assertion messages
Feb 20, 2015
af9c1a3
Add User.disableToopherAuthentication
Feb 20, 2015
3cd8aac
Add ToopherAPITests.compareToDefaultUserTerminal
Feb 20, 2015
4647496
Cleanup HTTP_Request2_Response URLs
Feb 20, 2015
c5d4566
Refactor ApiRawRequester.request
Feb 20, 2015
f8bafe1
Add UserTerminal.refreshFromServer
Feb 20, 2015
1090187
Rename ToopherAPI to ToopherApi
Feb 20, 2015
c347ec5
Add ToopherIframe.validatePostback
Feb 23, 2015
482092a
Add test for UserTerminal.refreshFromServer
Feb 23, 2015
33d7c2d
Add constants and cleanup tests
Feb 23, 2015
eded331
Add PHP OAuth to create oauth signed urls for ToopherIframe
Feb 23, 2015
a7312c7
Add ToopherIframe.getAuthenticationUrl and getUserManagementUrl
Feb 23, 2015
47fc57e
Bump ToopherApi version to 2.0.0
Feb 23, 2015
0876115
Move ToopherIframe tests into own file and cleanup
Feb 23, 2015
3de8865
Rename ToopherApi test file to ToopherApiTest
Feb 23, 2015
51d7111
Move Pairing tests into own file and cleanup
Feb 24, 2015
7d14edd
Move AuthenticationRequest tests into own file and cleanup
Feb 24, 2015
c2b1a4e
Move UserTerminal tests into own file and cleanup
Feb 24, 2015
b0a04ad
Move User tests into own file and cleanup
Feb 24, 2015
079c0ed
Add test assertions for last called method
Feb 24, 2015
9553032
Move Action tests into own file
Feb 24, 2015
a431fab
Add and cleanup tests
Feb 24, 2015
a322f59
Use camelCase for variables
Feb 24, 2015
9ef5792
Refactor ToopherApi.authenticate
Feb 24, 2015
d2e69be
Update PHP demo
Feb 24, 2015
449b03d
Update PHP README
Feb 25, 2015
bc6d68a
Update composer
Feb 25, 2015
cb3b2e6
Use composer package for ToopherIframe OAuth
Feb 25, 2015
5312e6d
Remove old demo code
Feb 25, 2015
ec7f170
Try to fix coveralls
Feb 25, 2015
5980ab6
Simplify Pairing test
Feb 26, 2015
4eb86f1
Fix spacing in tests
Feb 26, 2015
00b299e
Move classes into separate files
Feb 26, 2015
1d60951
Cleanup error mesages in demo
Feb 27, 2015
b59ba18
Little edits
Feb 27, 2015
05216ce
Refactor demo
Feb 27, 2015
cf38c40
Use constant for ToopherIframe version
Feb 27, 2015
353c6de
Use 4-space tabs
Feb 27, 2015
7abd1c8
Default to single quotes and not double
Feb 27, 2015
51bcf0b
Rename tests to be more descriptive
Feb 27, 2015
85ff932
Update test commands in README
Feb 27, 2015
c1f5e6b
Throw ToopherRequestException when Action json is incomplete
Feb 27, 2015
9897c40
Throw ToopherRequestException when AuthenticationRequest json is inco…
Feb 27, 2015
e0c2244
Throw ToopherRequestException when Pairing json is incomplete
Feb 27, 2015
c75f12f
Throw ToopherRequestException when UserTerminal json is incomplete
Feb 27, 2015
a5fdcac
Throw ToopherRequestException when User json is incomplete
Feb 27, 2015
776007b
Remove ToopherApi from Action tests
Feb 27, 2015
24400a2
Add tests for ToopherApi and reorder
Feb 27, 2015
b45917b
Refactor validatePostback
Mar 19, 2015
5396084
Reorder getOauthSignedUrl methods
Mar 20, 2015
89d66e0
Replace validatePostback with processPostback
Mar 20, 2015
6a09775
Add expires and iframe version to query params in getOauthSignedUrl
Mar 20, 2015
defe946
Refactor getAuthenticationUrl and add tests
Mar 20, 2015
13f0c1c
Refactor getUserManagementUrl and add tests
Mar 20, 2015
061cb85
Add ToopherIframe.isAuthenticationGranted and tests
Mar 20, 2015
fec0d5d
Improve tests for ToopherApi.authenticate
Mar 20, 2015
88416eb
Add js for ToopherIframe
Mar 23, 2015
2cf03ed
Update demo to match toopher-python
Mar 24, 2015
6972418
Simplify AuthenticationRequest.grantWithOtp
Mar 24, 2015
cd3bd50
Simplify Pairing.emailResetLink
Mar 24, 2015
91cbb50
Make default base url a constant
Mar 24, 2015
e674bb3
Cleanup ToopherApi
Mar 24, 2015
64eaf75
Throw InvalidArgumentException if key or secret is missing for Toophe…
Mar 24, 2015
b00820c
Use switch to evaluate resourceType in processPostback
Mar 24, 2015
f361f09
Include baseUrl when creating new instance of ToopherApi
Mar 24, 2015
6ff2635
Cleanup ToopherIframe
Mar 24, 2015
49c9e76
Add MIT license
Mar 25, 2015
6ae30c7
Include parameters in GET request
Mar 25, 2015
620ef88
Improve tests by checking urls and parameters
Mar 25, 2015
884e6a5
Add tests for ToopherRequestException in ToopherApi.request
Mar 26, 2015
89ae870
Add license and cleanup intro
Mar 26, 2015
d93de8f
Add tests for ToopherIframe creation InvalidArgumentException
Mar 26, 2015
ee6b458
Update processPostback test to use and test default timestamp
Mar 26, 2015
a28b280
Add test for SignatureValidationError while calculating signature in …
Mar 26, 2015
e3cc2be
Add processPostback test for keys with empty values
Mar 30, 2015
d7a7dcc
Simplify README and add iframe info
Mar 31, 2015
590a127
Add tests for ApiRawRequester.json_error_to_string
Mar 31, 2015
f78a621
Update tests for ApiRawRequester.request
Mar 31, 2015
6301c3c
Remove unnecessary else in ApiRawRequester.request
Mar 31, 2015
bb940b4
Little edits to ApiRawRequester.request
Mar 31, 2015
f416069
Try to fix ApiRawRequester.request
Mar 31, 2015
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -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.
119 changes: 71 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -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("<your consumer key>", "<your consumer secret>");

// 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 `<iframe>` element.

```php
require_once("toopher_api.php")

// Create an API object using your credentials
$iframeApi = new ToopherIframe("<your consumer key>", "<your consumer secret>");

$authIframeUrl = $iframeApi->getAuthenticationUrl("username@yourservice.com");

// Add an <iframe> element to your HTML:
// <iframe id="toopher-iframe" src=authIframeUrl />
```

### Step 2: Validate the postback data

The simplest way to validate the postback data is to call `isAuthenticationGranted` to check if the authentication request was granted.

```php
// Retrieve the postback data as a string from POST parameter 'iframe_postback_data'

// Returns boolean indicating if authentication request was granted by user
$authenticationRequestGranted = $iframeApi->isAuthenticationGranted(postback_data)

if ($authenticationRequestGranted) {
// Success!
}
```
from the root directory the package (the same directory that this README is located in)

#### Handling Errors
### Handling Errors
If any request runs into an error a `ToopherRequestException` will be thrown with more details on what went wrong.

#### Example code
Check out demo/toopher_demo.php for an example program that walks you through the whole process! Simply execute the script as follows:
### Demo
Check out `demo/toopher_demo.php` for an example program that walks you through the whole process! Simply run the command below:
```shell
$ php demo/toopher_demo.php
```
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

#### Tests
To run all unit tests:
## Contributing
### Dependencies
Toopher manages dependencies with [composer](http://getcomposer.org). To ensure all dependencies are up-to-date run the command below from the root directory:
```shell
$ composer install
```

### Tests
To run the tests enter:
```shell
$ phpunit test/test_toopher_api.php
$ phpunit test
```
Note: `phpunit` may be found in `vendor/bin/php` so your test command
would be
*Note: `phpunit` may be found in `vendor/bin/php` so your test command
would be:*
```shell
$ vendor/bin/phpunit test/test_toopher_api.php
$ vendor/bin/phpunit test
```

## License
ToopherPHP is licensed under the MIT License. See LICENSE.txt for the full text.
43 changes: 43 additions & 0 deletions assets/js/toopher-web.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(function(window, $){
var postToUrl = function (path, params, method){
method = method || 'POST';
var form = $('<form />').attr('method', method).attr('action', path);
for (var key in params){
if (params.hasOwnProperty(key)){
var hiddenField = $('<input />').attr('type', 'hidden').attr('name', key).attr('value', params[key]);
form.append(hiddenField);
}
}
$('body').append(form);
form.submit();
}

var handleMessage = function(e){
var msgData = JSON.parse(e.data);
if (msgData.status === 'toopher-api-complete'){
var iframe = $('#toopher_iframe');
var frameworkPostArgsJSON = iframe.attr('framework_post_args');
var frameworkPostArgs = {};
if(frameworkPostArgsJSON){
frameworkPostArgs = $.parseJSON(frameworkPostArgsJSON);
}
var postData = $.extend({}, msgData.payload, frameworkPostArgs);
var toopherData = {'toopher_iframe_data': $.param(postData)};

if(iframe.attr('use_ajax_postback')){
$.post(iframe.attr('toopher_postback'), toopherData)
.done(function(data){
data = $.parseJSON(data);
});
} else {
postToUrl(iframe.attr('toopher_postback'), toopherData, 'POST');
}
}
}

if (window.addEventListener) {
window.addEventListener('message', handleMessage, false);
} else {
window.attachEvent('onmessage', handleMessage);
}
})(window, jQuery);
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
"require":{
"php": ">=5.3.0",
"ext-json": "*",
"vclayton/unpecl-oauth": "dev-master",
"pear-pear.php.net/HTTP_Request2": ">=2.1.1",
"pear-pear.php.net/HTTP_OAuth": ">=0.2.3"
},
"require-dev" : {
"phpunit/phpunit": "3.7.*",
"satooshi/php-coveralls": "dev-master"
"satooshi/php-coveralls": "dev-master",
"rhumsaa/uuid": ">=2.8"
},
"autoload":{
"classmap": ["lib"]
Expand Down
Loading