Skip to main content

A simple Python library for web-based GitHub authentication.

Project description

gh-auth

A simple Python library for web-based GitHub authentication using the device flow.

Installation

pip install gh-auth

Usage

  1. On GitHub, create a GitHub or OAuth app.

  2. In your code, import the authenticate_with_github() function and pass it your app's client ID.

from gh_auth import authenticate_with_github

authenticate_with_github(client_id)

That's it.

When called, the function will prompt users to visit https://github.com/login/device and enter an eight-character code, then continously ping GitHub for a response. Upon sucessful authentication, the function will return a token you can use to interact with the GitHub API via libraries such as PyGithub.

Scopes

If you're using an OAuth app, you'll probably also want to define what scopes you want your app to be granted. Simply pass a list of scopes into the authenticate_with_github() function alongside your client ID, like so:

authenticate_with_github(client_id, scopes=["example_scope", "another_scope"])

See a full list of available OAuth scopes here.

If you're using an OAuth app and don't define any scopes, GitHub will default to granting it read-only access to the public data associated with the account being authenticated and nothing more. (For GitHub apps, scopes are defined on GitHub and can't be changed from this module.)

License

gh-auth's source code is released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gh_auth-0.1.3.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

gh_auth-0.1.3-py3-none-any.whl (3.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page