Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
66 lines (49 sloc) 1.58 KB
title tags keywords last_update summary sidebar permalink folder fa_icon complexity toc
Authentication Guide
guide authentication
October, 27, 2016
Describe how to perform authentication.

User Session Authentication

You can request API by being authenticated as a real OnCrawl user. You first need to request POST /api/session to retrieve a session token that will be valid during one week.

The Python code snippets below performs such authenticate and then list the user's projects:

{% include snippets/v1/ %}

Below what the output of this program may be:

{% include snippets/v1/ %}

User Session Token Reusability

A user session token a valid during one week. For your tests, you can for instance store the token in a file to prevent authenticating over and over again. Below is the same example than above, but with more class:

{% include snippets/v1/ %}

OAuth Token

Once you have obtained an OAuth token, it must be passed in the Authorization header of your requests:

curl -H "Authorization: Bearer OAUTH-TOKEN"

or in Python:

import requests
# List projects
resp = requests.get('',
                    headers=dict(Authorization='Bearer ' + TOKEN)
for project in resp.json()['projects']:
    print '{id}: {start_url}'.format(**project)