OAuth 2.0 Provider Implementation Tutorial¶
Activate the virtual environment
$ . ./venv/bin/activate
Add the new provider to functional tests¶
Change directory to
$(venv) cd ./tests/functional_tests/
Create the expected values module for the new provider by copying the
tests/functional_tests/expected_values/new_provider.py.template file to
$(venv) cp expected_values/new_provider.py.template expected_values/eventbrite.py
Create the functional tests config from the template
$(venv) cp config-template.py config.py
Add a new provider slug to the
INCLUDE_PROVIDERS list in the config in
correct alphabetical order and comment out all the other providers.
# tests/functional_tests/config.py # Only providers included here will be tested. # This is a convenience to easily exclude providers from tests by commenting # them out. INCLUDE_PROVIDERS = [ # 'behance', # 'bitly', # 'deviantart', 'eventbrite', # 'facebook', # 'foursquare', # 'google', # 'github', # 'linkedin', # 'paypal', # 'reddit', # 'vk', # 'windowslive', # 'yammer', # 'yandex', ]
Run the test. Make sure that you have the virtual environment active.
$(venv) py.test -vv
The test should fail with the
No record for the provider "provider_slug" was not found in the config!
exception. Replace the
'provider_slug' value on line 7 with the slug of the
# tests/functional_tests/expected_values/eventbrite.py # (...) conf = fixtures.get_configuration('eventbrite')
Run the test again.
$(venv) py.test -vv
It should fail again, this time with this exception:
No record for the provider "eventbrite" was not found in the config!.
We need to add a record for the new provider to the actual config dictionary.
- Register by the provider and fill out ALL possible user profile fields.
- Register an OAuth 2.0 application by the provider.
- Find the OAuth 2.0 flow and user info endpoints in the provider’s API documentation.
- Make a domain alias for localhost.
- Launch the
- Create a new class for the provider.
- Override the OAuth 2.0 enpoints.
- Add the provider to functional tests.
- Add an entry to the functional tests config.
- Comment out all other providers in the
- Refresh the functional tests app and click on the link of the new provider.
- On the consent page open the browser inspector and copy the login, password and consent button(s) xpaths to the expected values file.
- If there was a problem debug, identify the problem and handle it in the
- If everything went good there should be a syntax highlighted json response.
- If the json response has any properties which were not automatically parsed to the user object you need to override the
- Stop the functional tests app.
py.test -vv tests/functional_tests
- A Firefox window should open and the tests should fill out the consent form and hit the consent button.
- Add the provider’s OAuth 2.0, API and app dashboard links if any to the docstring.