Authenticating requests with OAuth

We now have enough information for authenticating requests. Twitter uses an authentication standard called OAuth, version 2.0. It's described in detail at http://oauth.net/.

OAuth credentials comprise of two main elements, consumer and access. The consumer element identifies our application and the access element proves that the account the access credentials came from authorized our app to act on its behalf. Twitter lets us acquire the access credentials directly from the dev.twitter.com interface.

The OAuthLib library (https://oauthlib.readthedocs.io/en/latest) is a library that allows authentication to a server using the OAuth protocol. Sites such as Facebook, Twitter, LinkedIn, GitHub, and Google, among others, use this protocol.

The Requests module has a library called requests-oauthlib (http://requests-oauthlib.readthedocs.io/en/latest), which can handle most of the complexity for us. This is available on PyPI, so we can download and install it with pip. This library allows access to sites that use this protocol using OAuthLib:

$ pip install requests-oauthlib

This authentication process is demonstrated in the Requests-OAuthlib documentation, which can be found at: https://requests-oauthlib.readthedocs.org/en/latest/oauth1_workflow.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset