You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+67-48Lines changed: 67 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,9 @@ First off, to access the Toopher API you'll need to sign up for an account at th
14
14
### The Toopher Two-Step
15
15
Interacting with the Toopher web service involves two steps: pairing, and authenticating.
16
16
17
+
#### Step 0: Create an API Object
18
+
Using your consumer key and consumer secret, create a ToopherApi object which will be used to generate an authentication or user management url and process the postback data.
19
+
17
20
#### Step 1: Pair
18
21
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 web service and we'll return a pairing ID that you can use whenever you want to authenticate an action for that user.
19
22
@@ -26,7 +29,7 @@ This library makes it super simple to do the Toopher two-step. Check it out:
26
29
```python
27
30
from toopher import*
28
31
29
-
# Create an API Object Using Your Credentials
32
+
#Step 0 - Create an API Object Using Your Credentials
30
33
api = toopher.ToopherApi("<your consumer key>", "<your consumer secret>")
31
34
32
35
# Step 1 - Pair with their phone's Toopher app
@@ -106,60 +109,58 @@ $ nosetests test
106
109
```
107
110
108
111
#Using the Toopher IFRAME
109
-
Toopher's IFRAME-based authentication flow is the simplest way for web developers to integrate Toopher Two-Factor Authentication into an application.
112
+
Toopher's IFRAME-based flow is the simplest way for web developers to integrate Toopher Two-Factor Authentication into an application.
113
+
114
+
### Toopher IFRAME Overview
115
+
116
+
The IFRAME-based flow works by inserting an `<iframe>` element into the HTML displayed to the user after a successful username/password validation (but before they are actually logged-in to the service). The IFRAME URL is generated by our library and its content is served from the Toopher API server.
110
117
111
-
### ToopherIFRAME Authentication Overview
118
+
The Authentication IFRAME guides the user through the process of pairing (if the user is not paired already) and authenticating with Toopher. Once complete, the IFRAME will return the result of the authentication to your server by `POST`ing the response via HTML to an endpoint of your choice. Your server validates the cryptographic signature using our library which determines whether or not the user successfully authenticated.
112
119
113
-
The IFRAME-based authentication flow works by inserting an `<iframe>` element into the HTML displayed to the user after a successful username/password validation (but before they are actually logged-in to the service). The IFRAME URL is generated by our library and its content is served from the Toopher API server. The IFRAME guides the user through the process of pairing and authenticating with Toopher. Once complete, the IFRAME will return the result of the authentication to your server by `POST`ing the response via HTML to an endpoint of your choice. Your server validates the cryptographic signature using our library which determines whether or not the user successfully authenticated.
120
+
The User Management IFRAME is available if you would like to manage users separately from the authentication process. Once complete, the IFRAME will return the result of the pairing to your server by POSTing the response via HTML to an endpoint of your choice. Your server validates the cryptographic signature using our library which determines whether or not the user successfully paired.
114
121
115
-
Two distinct IFRAME flows are required:
122
+
### HTML Markup
123
+
There is no difference in the markup required for an authentication vs. a user management IFRAME request (the generated URL embeds all relevant information).
116
124
117
-
* the *Pairing* request is used to pair a user account with a particular mobile device (this is typically a one-time process)
118
-
* the *Authentication* request is used to authenticate a particular action on behalf of a user
125
+
The IFRAME element must have an id of `toopher_iframe`. Pages that include the Toopher IFRAME must include the accompanying javascript library `toopher-web.js` (located in `/assets/js/` in this repository). Toopher's IFRAME content is designed for a minimum size of 400x300 px. In the example below, `{{IFRAME_REQUEST_URL}}` is the authentication or user management URL generated by the ToopherIframe library. `{{POSTBACK_URL}}` is the path on your server where the Toopher-Iframe will submit the result of the authentication when it is finished.
126
+
127
+
```html
128
+
<!-- toopher-web.js requires jQuery. uncomment the following line to source it from CDNJS if it is not already included in your page -->
We recommend using some form of primary authentication before initiating a Toopher authentication request. Typical primary authentication methods involve verifying that the user has a valid username and password to access the resource being protected.
123
137
124
138
#### Step 1: Embed a request in an IFRAME
125
-
After verifying the user's primary authentication, but before Assuming the user's primary authentication checks out, the next step is to kickoff Toopher authentication.
139
+
After verifying the user's primary authentication, but before assuming the user's primary authentication checks out, the next step is to kickoff Toopher authentication.
140
+
141
+
1. Generate an authentication URL by specifying the request parameters to the library as detailed below
142
+
2. Display a webpage to your user that embeds this URL within an `<iframe>` element. The markup requirements for the IFRAME element are described in the "HTML Markup" section above.
126
143
127
-
1. Generate a URL by specifying the request parameters to the library as detailed below
128
-
2. Display a webpage to your user that embeds this URL within an `<iframe>` element. The markup requirements for the IFRAME element are described in the "HTML Markup" section.
144
+
#### Step 2: Validate the postback data
129
145
130
-
####Step 2a: Validate the result by processing the postback
146
+
##### Option 1: Process the postback
131
147
1. Toopher-IFRAME results posted back to server.
132
-
2. Call `ToopherIframe.process_postback()` to verify that result is valid. `process_postback()` returns one of the following:
148
+
2. Call `process_postback()` to verify that the result is valid. `process_postback()` returns one of the following:
133
149
* an AuthenticationRequest object if the signature is valid (authentication url)
134
-
* a Pairing or User if the signature is valid (user management url)
135
-
* a `ToopherAPIError` or `SignatureValidationError` if the server encounters an error while processing postback
150
+
* a `UserDisabledError`, `SignatureValidationError` or `ToopherAPIError` if the server encounters an error while processing postback
136
151
3. If no errors were returned, the result of the authentication can be checked by evaluating `not authentication_request.pending and authentication_request.granted`.
137
152
138
-
####Step 2b: Validate the result by checking the authentication request status
153
+
##### Option 2: Check the authentication request status
139
154
1. Toopher-IFRAME results posted back to server.
140
155
2. Call `ToopherIframe.is_authentication_granted` to check if the authentication request was granted.
141
156
142
157
143
-
### HTML Markup
144
-
The IFRAME element must have an id of `toopher_iframe`.
158
+
#### Examples
145
159
146
-
Pages that include the Toopher IFRAME must include the accompanying javascript library `toopher-web.js` (located in `/assets/js/` in this repository). Toopher's IFRAME content is designed for a minimum size of 400x300 px. In the example below, `{{IFRAME_REQUEST_URL}}` is the Authentication or Pairing URL generated by the ToopherIframe library. `{{POSTBACK_URL}}` is the path on your server where the Toopher-Iframe will submit the result of the authentication when it is finished.
160
+
##### Generating an Authentication IFRAME URL
161
+
Though it is not required, every Toopher Authentication session can include a unique `request_token` - a randomized string that is included in the signed request to the Toopher API and returned in the signed response from the Toopher IFRAME. To guard against potential replay attacks, your code should validate that the returned `request_token` is the same one used to create the request.
147
162
148
-
```html
149
-
<!-- toopher-web.js requires jQuery. uncomment the following line to source it from CDNJS if it is not already included in your page -->
There is no difference in the markup required for an authentication vs. a user management IFRAME request (the generated URL embeds all relevant information).
156
-
157
-
### Examples
158
-
159
-
#### Generating an Authentication IFRAME URL
160
-
Every Toopher Authentication session should include a unique `request_token` - a randomized string that is included in the signed request to the Toopher API and returned in the signed response from the Toopher IFRAME. To guard against potential replay attacks, your code should validate that the returned `request_token` is the same one used to create the request.
161
-
162
-
Creating a random request token and storing it in the server-side session using Django:
163
+
Here's an example of creating a random request token and storing it in the server-side session using Django:
#### Validating Postback Data from Authentication IFRAME & Parsing Errors
184
+
#####Validating Postback Data from Authentication IFRAME & Parsing Errors
184
185
In this example, `data` is a `dict` of the form data POSTed to your server from the Toopher Authentication IFRAME. You should replace the commented blocks in the `except` with code appropriate for the condition described in the comment.
185
186
186
-
There are two ways to validate postback data:
187
+
There are two ways to validate postback data from an authentication IFRAME:
187
188
188
-
#####Process Postback
189
+
######Process Postback
189
190
```python
190
191
try:
191
-
# Try to process the postback from the Toopher IFRAME
192
-
# and receive an AuthenticationRequest object.
192
+
# Try to process the postback from the Toopher IFRAME and receive an AuthenticationRequest object.
We recommend using some form of primary authentication before initiating a Toopher pairing. Typical primary authentication methods involve verifying that the user has a valid username and password to access the resource being protected.
221
+
222
+
#### Step 1: Embed a request in an IFRAME
223
+
After verifying the user's primary authentication, the next step is to kickoff Toopher pairing.
224
+
225
+
1. Generate a user management URL by specifying the request parameters to the library as detailed below
226
+
2. Display a webpage to your user that embeds this URL within an `<iframe>` element. The markup requirements for the IFRAME element are described in the "HTML Markup" section above.
227
+
228
+
#### Step 2: Validate the postback data
229
+
1. Toopher-IFRAME results posted back to server.
230
+
2. Call `process_postback()` to verify that the result is valid. `process_postback()` returns one of the following:
231
+
* a Pairing or User object if the signature is valid (authentication url)
232
+
* a `UserDisabledError`, `SignatureValidationError` or `ToopherAPIError` if the server encounters an error while processing postback
233
+
3. If no errors were returned and you received a Pairing object, the result of the pairing can be checked by evaluating `pairing.enabled`.
234
+
235
+
#### Examples
236
+
##### Generating a User Management IFRAME URL
219
237
The Toopher Authentication API provides the requester a rich set of controls over user management parameters.
#### Validating Postback Data from Pairing IFRAME & Parsing Errors
250
+
#####Validating Postback Data from User Management IFRAME & Parsing Errors
233
251
In this example, `data` is a `dict` of the form data POSTed to your server from the Toopher Pairing IFRAME. You should replace the commented blocks in the `except` with code appropriate for the condition described in the comment.
234
252
235
-
#####Process Postback
253
+
There is one way to validate postback data from a user management IFRAME:
254
+
255
+
######Process Postback
236
256
```python
237
257
try:
238
-
# Try to process the postback from the Toopher IFRAME
239
-
# and receive a Pairing or User object.
258
+
# Try to process the postback from the Toopher IFRAME and receive a Pairing or User object.
0 commit comments