Skip to content

Instantly share code, notes, and snippets.

@api-admin
Created April 25, 2014 20:33
Show Gist options
  • Save api-admin/11302313 to your computer and use it in GitHub Desktop.
Save api-admin/11302313 to your computer and use it in GitHub Desktop.
SurveyMonkey OAuth Developer Cheat Sheet

SurveyMonkey OAuth Developer Cheat Sheet

Authorization Flow

SurveyMonkey implements the authorization code grant framework of OAuth 2.0 as described in the RFC here: http://tools.ietf.org/html/rfc6749#page-24

 +-------------+ 
 |SurveyMonkey |   O
 |Account      |  /|\
 |Owner        |  / \
 +-------------+
       ^
       |
      (B)                                   http://api.surveymonkey.net/
 +-----|-------+          Client ID & API key    +----------------+
 |            -+----(A)-- & Redirection URI ---->|                |
 |    User-    |                                 |                |
 |    Agent   -+----(B)-- User authenticates --->|  SurveyMonkey  |
 |             |                                 |   API Server   |
 |   browser   |          302 redirect w/        |                |
 |            -+----(C)-- Authorization Code ---<|                |
 +---|----|----+          in query parameter     +----------------+
      |    |                                          ^      v
     (A)  (C)                                         |      |
      |    |                                          |      |
      ^    v                                          |      |
 +-------------+                                      |      |
 |             |>----(D)-- Authorization Code --------'      |
 |   Client    |           & Redirection URI                 |
 | Application |                                             |
 |             |<----(E)----- Access Token ------------------'
 +-------------+

The flow illustrated here includes the following steps:

(A) The client initiates the flow by directing the SurveyMonkey user's user-agent to the authorization endpoint URI. The client includes its client ID, API key and a redirection URI to which the authorization server will send the user-agent back once access is granted (or denied). The redirection URI encoded in the authorization URI must match the URI configured when the application was registered.

Authorization endpoint: https://api.surveymonkey.net/oauth/authorize

(B) SurveyMonkey's API server authenticates the SurveyMonkey account owner (via the user-agent/browser) and establishes whether the account owner grants or denies the client's access request.

(C) Whether the account owner grants access or not, the API server redirects the user-agent back to the client using the redirection URI provided earlier in the request and during application registration. The redirection URI includes an authorization code as a query parameter named "code" if access was granted and a parameter "error" if it was denied.

(D) The client requests an access token from the API server's token endpoint by including the authorization code received in the previous step. When making the request, the client authenticates with the API server by providing the API key as a query parameter "api_key" along with fields "client_secret" and "redirect_uri" in a from-encoded (Content-Type: application/x-www-form-urlencoded) POST. This is the only time the client secret is used. The form POST must also include the code obtained in step (C) as a field "code" and a field "grant_type" set to "authorization_code".

Code exchange endpoint: https://api.surveymonkey.net/oauth/token

(E) The API server authenticates the client, validates the authorization code, and ensures that the redirection URI received matches the URI used to redirect the client in step (C). If valid, the authorization server responds back with an access token in the JSON encode response body in value of a key named "access_token".

Essential values

Your client_id is your Mashery username

Your application name and redirect_uri can be found here:

https://developer.surveymonkey.com/apps/myapps

Your API key, client_secret and rate limits can be found here:

https://developer.surveymonkey.com/apps/mykeys

Examples

Here are some example links from our API console:

Authorization Link
https://api.surveymonkey.com/oauth/authorize?response_type=code&redirect_uri=https%3A%2F%2Fapi.surveymonkey.com%2Fapi_console%2Foauth2callback&client_id=SurveyMonkeyApiConsole&api_key=u366xz3zv6s9jje5mm3495fk

Access Authorized Callback
https://api.surveymonkey.com/api_console/oauth2callback?code=1Jq5p1Kbkwj1hPjKCXym0-Ltw9S4FUztS.ouiZ1SjZgUL7TlmsFirwA23m53TJq8.lmDLHY9-1fqPQGKA-TON5kdNynL5BSPLl0MlQKwZ8nRuv04.KYiR96l.YbF01d96fJKKUop3k6en037Qx4fabSmUjFUIo2C4OXovwW0ASxLDzL0q38y2oKHiU3sYDHY

Access Denied Callback
https://api.surveymonkey.com/api_console/oauth2callback?error_description=Resource+owner+canceled+the+request&error=access_denied

Python Example Application
https://github.com/SurveyMonkey/python_guides/blob/master/guides/authorization.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment