This document describes HootSuite's implementation of the OAuth 2 standard and how you can use it to make authenticated requests against the HootSuite Engagement API. The implementation is based on the OAuth 2.0 Draft 23 and the specific implementation details are outlined within the scope of this document.
This implementation is designed to use the Authorization Grant type Authorization Code:
The HootSuite user first grants authorization to the Client (i.e. your app), which then presents the authorization
code to a token endpoint in order to receive an access token.
Refresh tokens are currently not supported.
Every Client (app) needs to be registered with HootSuite before being issued a Client ID and secret key (apply here). The Client ID is required when asking for the user's authorization; When requesting an access token, the Client has to authenticate using its ID and secret key via basic HTTP authentication.
(A) The Client redirects the HootSuite user's user-agent to HootSuite's Authorization Endpoint, which displays an HTML page containing a form that asks the HootSuite user to allow the Client to access their account data (Authorization Grant).
(B) Once the HootSuite user approves or denies the Client, the Authorization Endpoint redirects the user-agent back to the Client's redirect_uri along with the parameters outlined below (which include an Authorization Grant code if the user approved the Client).
GET http://hootsuite.com/oauth2/authorize
| Parameter | Accepted Values | |
|---|---|---|
| response_type | REQUIRED | "code" |
| client_id | REQUIRED | As provided by HootSuite |
| redirect_uri | OPTIONAL | Absolute URL |
| state | RECOMMENDED | Unique hash (e.g. session ID) provided by client. Will be passed back in grant response. |
Example:
GET redirect_uri ("302 Found" redirect)
The HootSuite user has authorized the Client, and the user-agent is redirected to the redirect_uri which contains these parameters:
| Parameter | Value |
|---|---|
| code | Authorization Grant code. Unique hash, valid for 10 minutes |
| state | As provided by client in step (A) |
GET redirect_uri ("302 Found" redirect)
The HootSuite user has denied the Client or an unexpected error occured. The user-agent is redirected to the redirect_uri which contains these parameters:
| Parameter | Value | ||||
|---|---|---|---|---|---|
| error |
|
||||
| error_description | Human-readable description of error (optional) | ||||
| state | As provided by client in step (A) |
Once the Client has obtained authorization from the HootSuite user, it requests an Access Token at the Token Endpoint. It needs to authenticate itself using HTTP Basic Auth and present the Authorization Grant code.
This endpoint requires HTTPS.
POST https://hootsuite.com/oauth2/token
Requires client authentication (ID and secret key) via HTTP Basic Auth.
| Parameter | Accepted Values | |
|---|---|---|
| grant_type | REQUIRED | "authorization_code" |
| code | REQUIRED | Authorization Grant code issued in step A |
| redirect_uri | OPTIONAL/REQUIRED | REQUIRED, if the redirect_uri parameter was included in the authorization request (A), and their values MUST be identical. |
Sample Code:
| Parameter | Value |
|---|---|
| access_token | Unique hash |
| token_type | "bearer" |
| expires_in | Token lifetime in seconds. Currently defaults to 1 year (3600*24*365 sec). |
Response format: JSON. For example:
If the request is malformed, contains invalid values, or if the provided Authorization Grant can not be validated (e.g. invalid code, it expired), the server responds with the appropriate HTTP status code (400 or 401) as well as an error code as outlined below, and may contain a human-readable error message.
| Parameter | Value | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| error |
|
||||||||||||
| error_description | Human-readable description of error (optional) |
Response format: JSON. For example:
The Access Token can now be used to run requests against the API on behalf of the HootSuite user.
All such requests require HTTPS.
In accordance with the Bearer Token specifications (http://tools.ietf.org/html/draft-ietf-oauth-v2-bearer-08#section-2), the Access Token is included with the request in the "Authorization" header as follows:
where vF9dft4qmT is the actual Access Token.
This is currently the only supported authentication method.
Sample cURL command:
Note: For more code samples refer to the API documentation.
If the request is malformed, contains invalid values, or if the provided Access Token can not be validated (e.g. invalid code, it expired), the server responds with the appropriate HTTP status code (400 or 401) as well as a "WWW-Authenticate" header, which may contain an error code and message as outlined below.
| Parameter | Value | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| error |
|
|||||||||
| error_description | Human-readable description of error |
For example, in response to a protected resource request without authentication:
And in response to a protected resource request with an authentication attempt using an expired access token:
Rich media content has become king. And as quality imagery and video pick up marketing...
Read More
It’s the worst nightmare of many C-suite executives. Someone has control of your social media...
Read More
A growing number of governments, from municipal to federal, are increasing their engagement through social...
Read More
An article by HootSuite CEO Ryan Holmes was recently featured in Business Insider. Take a look at...
Read More