Skip to main content

gVerify

Overview

A python library for authenticating requests for various google services including gmail, youtube, drive and calendar.

Requirements

  • Python 3.10+
  • Works on Linux, Windows, macOS, BSD

Getting started

Getting an access key

To get started with this library, you need a google account in order to obtain access credentials. First, pick a service that you want to use, which could be: - gmail - youtube - drive - calendar

Installing the library

The next step is to instal the library from pypi:

pip install gverify

Authorizing a request

In this case we will use youtube as the service. We will authorize a request to search youtube for python programming videos:

from gverify import GoogleOAuth, YouTubeScopes

client_secret_file: str = 'client_secret.json'
api_service_name: str = 'youtube'
api_version: str = 'v3'
credentials_dir: str = '.youtube'
scopes: list[str] = [YouTubeScopes.youtube.value]
oauth: GoogleOAuth = GoogleOAuth(
    secrets_file=secret_file,
    scopes=scopes,
    api_service_name=api_service_name,
    api_version=api_version,
    credentials_dir=credentials_dir
)
youtube_client = oauth.authenticate_google_server()
youtube_find_request = youtube_client.search().list(q='python programming videos', part='id, snippet')
print(youtube_find_request.execute())

Using the Flask Framework

Currently, this library does not intergrate with web frameworks like Flask and fastAPI. To use flask, we use the underlying library:

from flask import Flask, url_for, redirect, request, session
from google_auth_oauthlib.flow import Flow
from google.oauth2.credentials import Credentials
import os


CLIENT_SECRETS_FILE = "client_secret.json"
SCOPES = [
    'https://www.googleapis.com/auth/youtube.force-ssl',
    'https://www.googleapis.com/auth/youtube'
]
API_SERVICE_NAME = 'youtube'
API_VERSION = 'v3'

app: Flask = Flask(__name__)
app.secret_key = 'secret-key'


@app.route('/')
def home():
    if not session['credentials']:
        redirect(url_for('authorize'))
    return 'Home'


@app.route('/authorize')
def authorize():
    flow = Flow.from_client_secrets_file(
      CLIENT_SECRETS_FILE,
      scopes=SCOPES
      )
    flow.redirect_uri = url_for('oauth2callback', _external=True)
    authorization_url, state = flow.authorization_url(
      access_type='offline',
      include_granted_scopes='true'
    )
    session['state'] = state
    return redirect(authorization_url)


def credentials_to_dict(credentials: Credentials) -> dict:
  return {
            'token': credentials.token,
          'refresh_token': credentials.refresh_token,
          'token_uri': credentials.token_uri,
          'client_id': credentials.client_id,
          'client_secret': credentials.client_secret,
          'scopes': credentials.scopes
          }


@app.route('/oauth2callback')
def oauth2callback():
    state = session['state']
    flow = Flow.from_client_secrets_file(
      CLIENT_SECRETS_FILE,
      scopes=SCOPES,
      state=state
    )
    flow.redirect_uri = url_for('oauth2callback', _external=True)
    authorization_response = request.url
    flow.fetch_token(authorization_response=authorization_response)
    credentials: Credentials = flow.credentials
    session['credentials'] = credentials_to_dict(credentials)
    return redirect('/')


if __name__ == '__main__':
    os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
    app.run('localhost', 5000, debug=True)

How to Contribute

To contribute, chack out the contribution guideline.

License

The API uses an MIT License

Developer

Lyle Okoth – @lyleokoth on twitter

lyle okoth on medium

My email is lyceokoth@gmail.com

Here is my GitHub Profile

You can also find me on Linkedin

Metadata

Release files for gverify 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gverify 0.2.2
File Size Uploaded Provenance
gverify-0.2.2.tar.gz 6.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gverify 0.2.2
File Interpreter ABI Platform
gverify-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 12.7 kB

Release files / gverify-0.2.2.tar.gz

Download URL gverify-0.2.2.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7dd5ab18000e4c321288b93dba70f4d3a68c096d3eb5b6688ec0d9f588ec3e30
BLAKE2b-256 checksum
How to use checksums
470aa4ea69849e479a8d623d5f6ba807362a7799231695c045ceefddf85e3d11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / gverify-0.2.2-py3-none-any.whl

Download URL gverify-0.2.2-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
788db33fa5504cc57c39d76ca53f9ea4699b8e63feb5289c60941a2dce12bd89
BLAKE2b-256 checksum
How to use checksums
ac850314cc7c7dac9f108d19fbfbd8f8af10ccb7f504d91c2e6b71131eb9ef19
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for gverify 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page