google-oauth


Namegoogle-oauth JSON
Version 1.0.1 PyPI version JSON
download
home_pagehttps://github.com/miedzinski/google-oauth
SummaryOAuth2 for Google APIs
upload_time
maintainerNone
docs_urlNone
authorDominik Miedziński
requires_pythonNone
licenseMIT License
keywords google oauth oauth2 api service jwt
VCS
bugtrack_url
requirements pyopenssl requests six
Travis-CI
coveralls test coverage No coveralls.
            Google OAuth Service
********************

.. image:: https://img.shields.io/travis/miedzinski/google-oauth.svg
    :target: https://travis-ci.org/miedzinski/google-oauth/builds
.. image:: https://img.shields.io/codecov/c/github/miedzinski/google-oauth.svg
    :target: https://codecov.io/github/miedzinski/google-oauth

``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.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/miedzinski/google-oauth",
    "name": "google-oauth",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "google oauth oauth2 api service jwt",
    "author": "Dominik Miedzi\u0144ski",
    "author_email": "UNKNOWN",
    "download_url": "UNKNOWN",
    "platform": "UNKNOWN",
    "description": "Google OAuth Service\n********************\n\n.. image:: https://img.shields.io/travis/miedzinski/google-oauth.svg\n    :target: https://travis-ci.org/miedzinski/google-oauth/builds\n.. image:: https://img.shields.io/codecov/c/github/miedzinski/google-oauth.svg\n    :target: https://codecov.io/github/miedzinski/google-oauth\n\n``google-oauth`` aims to implement Google OAuth2.\n\nInstallation\n============\n\nRequires Python 2.7 or 3.3+.\n\nUse ``pip``:\n\n    $ pip install google-oauth\n\nOr download code rom GitHub and install it manually with ``setuptools``:\n\n    $ git clone https://github.com/miedzinski/google-oauth2-service.git\n    $ cd google-oauth\n    $ python setup.py install\n\nIn case of ``pyOpenSSL`` build failing, install openssl headers.\nOn Debian based distributions:\n\n    $ apt-get install libssl-dev\n\nUsage\n=====\n\nAt this moment, there is only `Server to Server` flow implemented.\n\nOAuth2 for service accounts\n---------------------------\n\nFirst, create ``ServiceAccount`` object. The best way to achieve this\nis using one of two classmethods:\n\n    - ServiceAccount.from_json\n    - ServiceAccount.from_pkcs12\n\nGoogle recommends JSON key format, so we will use it.\nBoth methods are documented in source code.\n\n    >>> key = json.load(open('/path/to/credentials.json'))\n    >>> auth = ServiceAccount.from_json(key=key, scopes=scope)\n    >>> auth.access_token\n\nAnd that's it - OAuth2 access token is available as ``access_token`` property.\nIf you think token's lifetime will be longer than object's, you can cache it\nin file or database of your choice.\nOtherwise, you can use a ``GoogleService.authorized_request``, which is\na handy shortcut to ``requests.request`` with proper ``Authorization`` header.\nSubsequent calls to this method won't request new access tokens unless\nprevious one expired.\n\nLet's search for Guuido van Rossum on Google+\n\n    >>> scope = 'https://www.googleapis.com/auth/plus.login'\n    >>> url = 'https://www.googleapis.com/plus/v1/people' \\\n    >>>         '?query=Guuido+van+Rossum'\n    >>> resp = auth.authorized_request(method='get', url=url)\n\n``resp`` is now an instance of ``requests.Response``, from which we can\nextract all the data we need.\n\nDocumentation\n=============\n\nSource code is fully documented with docstrings.\n\nTODO\n====\n\n- Implement three-legged OAuth2 (for web server applications).\n\nContributing\n============\n\nAll contributors are welcome! Make sure the tests pass and don't forget\nto write your own tests if you code new stuff.\nIf you want to submit a patch, use GitHub pull requests.",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "OAuth2 for Google APIs",
    "version": "1.0.1",
    "project_urls": {
        "Download": "UNKNOWN",
        "Homepage": "https://github.com/miedzinski/google-oauth"
    },
    "split_keywords": [
        "google",
        "oauth",
        "oauth2",
        "api",
        "service",
        "jwt"
    ],
    "urls": [],
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "miedzinski",
    "github_project": "google-oauth",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "pyopenssl",
            "specs": [
                [
                    ">=",
                    "0.11"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "six",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "google-oauth"
}
        
Elapsed time: 0.26010s