Coder Social home page Coder Social logo

google-oauth's Introduction

Google OAuth Service

image

image

google-oauth aims to implement Google OAuth2.

Installation

Requires Python 2.7 or 3.3+.

Use pip:

$ pip install google-oauth

Or download code rom GitHub and install it manually with setuptools:

$ git clone https://github.com/miedzinski/google-oauth2-service.git $ cd google-oauth $ python setup.py install

In case of pyOpenSSL build failing, install openssl headers. On Debian based distributions:

$ apt-get install libssl-dev

Usage

At this moment, there is only Server to Server flow implemented.

OAuth2 for service accounts

First, create ServiceAccount object. The best way to achieve this is using one of two classmethods:

  • ServiceAccount.from_json
  • ServiceAccount.from_pkcs12

Google recommends JSON key format, so we will use it. Both methods are documented in source code.

>>> key = json.load(open('/path/to/credentials.json')) >>> auth = ServiceAccount.from_json(key=key, scopes=scope) >>> auth.access_token

And that's it - OAuth2 access token is available as access_token property. If you think token's lifetime will be longer than object's, you can cache it in file or database of your choice. Otherwise, you can use a GoogleService.authorized_request, which is a handy shortcut to requests.request with proper Authorization header. Subsequent calls to this method won't request new access tokens unless previous one expired.

Let's search for Guuido van Rossum on Google+

>>> scope = 'https://www.googleapis.com/auth/plus.login' >>> url = 'https://www.googleapis.com/plus/v1/people' >>> '?query=Guuido+van+Rossum' >>> resp = auth.authorized_request(method='get', url=url)

resp is now an instance of requests.Response, from which we can extract all the data we need.

Documentation

Source code is fully documented with docstrings.

TODO

  • Implement three-legged OAuth2 (for web server applications).

Contributing

All contributors are welcome! Make sure the tests pass and don't forget to write your own tests if you code new stuff. If you want to submit a patch, use GitHub pull requests.

google-oauth's People

Contributors

miedzinski avatar

Watchers

James Cloos avatar Mat Kelly avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.