Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit c410e78

Browse files
author
Grace Yim
committed
Reformat text and subheaders
1 parent 6502c86 commit c410e78

File tree

1 file changed

+67
-48
lines changed

1 file changed

+67
-48
lines changed

README.md

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ First off, to access the Toopher API you'll need to sign up for an account at th
1414
### The Toopher Two-Step
1515
Interacting with the Toopher web service involves two steps: pairing, and authenticating.
1616

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+
1720
#### Step 1: Pair
1821
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.
1922

@@ -26,7 +29,7 @@ This library makes it super simple to do the Toopher two-step. Check it out:
2629
```python
2730
from toopher import *
2831

29-
# Create an API Object Using Your Credentials
32+
# Step 0 - Create an API Object Using Your Credentials
3033
api = toopher.ToopherApi("<your consumer key>", "<your consumer secret>")
3134

3235
# Step 1 - Pair with their phone's Toopher app
@@ -106,60 +109,58 @@ $ nosetests test
106109
```
107110

108111
#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.
110117

111-
### Toopher IFRAME 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.
112119

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.
114121

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).
116124

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 -->
129+
<!-- <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> -->
130+
<script src="/js/toopher-web.js"></script>
131+
<iframe id="toopher_iframe" src="{{IFRAME_REQUEST_URL}}" toopher_postback="{{POSTBACK_URL}}" style="display:inline-block; height:300px; width:100%;"></iframe>
132+
```
119133

120134
### Authentication IFRAME Workflow
121135
#### Primary Authentication
122136
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.
123137

124138
#### 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.
126143

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
129145

130-
#### Step 2a: Validate the result by processing the postback
146+
##### Option 1: Process the postback
131147
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:
133149
* 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
136151
3. If no errors were returned, the result of the authentication can be checked by evaluating `not authentication_request.pending and authentication_request.granted`.
137152

138-
#### Step 2b: Validate the result by checking the authentication request status
153+
##### Option 2: Check the authentication request status
139154
1. Toopher-IFRAME results posted back to server.
140155
2. Call `ToopherIframe.is_authentication_granted` to check if the authentication request was granted.
141156

142157

143-
### HTML Markup
144-
The IFRAME element must have an id of `toopher_iframe`.
158+
#### Examples
145159

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.
147162

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 -->
150-
<!-- <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> -->
151-
<script src="/js/toopher-web.js"></script>
152-
<iframe id="toopher_iframe" src="{{IFRAME_REQUEST_URL}}" toopher_postback="{{POSTBACK_URL}}" style="display:inline-block; height:300px; width:100%;"></iframe>
153-
```
154-
155-
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:
163164

164165
```python
165166
import random, string
@@ -170,7 +171,7 @@ request.session['ToopherRequestToken'] = request_token
170171
The Toopher Authentication API provides the requester a rich set of controls over authentication parameters.
171172

172173
```python
173-
# optional parameters: reset_email, request_token, action_name, requester_metadata, automation_allowed, challenge_required, and ttl
174+
# Optional parameters: reset_email, request_token, action_name, requester_metadata, automation_allowed, challenge_required, and ttl
174175
auth_iframe_url = iframe_api.get_authentication_url(username, reset_email='email', request_token='token', action_name='action', requester_metadata, automation_allowed=automation_allowed, challenge_required=challenge_required, ttl=ttl);
175176
```
176177

@@ -180,16 +181,15 @@ For the simple case of authenticating a user at login, use `get_authentication_u
180181
login_iframe_url = iframe_api.get_authentication_url(username)
181182
```
182183

183-
#### Validating Postback Data from Authentication IFRAME & Parsing Errors
184+
##### Validating Postback Data from Authentication IFRAME & Parsing Errors
184185
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.
185186

186-
There are two ways to validate postback data:
187+
There are two ways to validate postback data from an authentication IFRAME:
187188

188-
#####Process Postback
189+
######Process Postback
189190
```python
190191
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.
193193
authentication_request = iframe_api.process_postback(form_data)
194194

195195
# If you got here, you just need to check the status of the authentication request.
@@ -206,37 +206,56 @@ except toopher.ToopherApiError as e:
206206
# The postback resource type was not valid.
207207
```
208208

209-
#####Check AuthenticationRequest Status
209+
######Check Authentication Request Status
210210
```python
211-
# returns boolean indicating if user should be granted access
211+
# Returns boolean indicating if user should be granted access
212212
authentication_request_granted = iframe_api.is_authentication_granted(form_data)
213213

214214
if authentication_request_granted:
215215
# Success!
216216
```
217217

218-
#### Generating a User Management IFRAME URL
218+
###User Management IFRAME Workflow
219+
#### Primary Authentication
220+
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
219237
The Toopher Authentication API provides the requester a rich set of controls over user management parameters.
220238

221239
```python
222-
# optional parameter: reset_email
240+
# Optional parameter: reset_email
223241
pair_iframe_url = iframe_api.get_user_management_url(username, 'email')
224242
```
225243

226-
For the simple case of pairing a user, use `get_user_management_url` in this simple way:
244+
For the simple case of pairing a user, use `get_user_management_url()` in this simple way:
227245

228246
```python
229247
pair_iframe_url = iframe_api.get_user_management_url(username)
230248
```
231249

232-
#### Validating Postback Data from Pairing IFRAME & Parsing Errors
250+
##### Validating Postback Data from User Management IFRAME & Parsing Errors
233251
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.
234252

235-
#####Process Postback
253+
There is one way to validate postback data from a user management IFRAME:
254+
255+
######Process Postback
236256
```python
237257
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.
240259
postback_object = iframe_api.process_postback(form_data)
241260

242261
# If you got here and you have a pairing object, you just need to check the status of the pairing.

0 commit comments

Comments
 (0)