Skip to content

Generate GitHub App user access tokens (ghu_) via OAuth Device Flow — multi-language examples for CLI apps

License

Notifications You must be signed in to change notification settings

jusuchin85/github-app-device-flow

Repository files navigation

GitHub App User-to-Server Token (Device Flow)

Generate user access tokens (ghu_) via the OAuth Device Flow — ideal for CLI apps, no web server needed.

Warning

These scripts are for demonstration and testing purposes only. Do not use in production. The scripts print the access token to stdout which may expose it in logs or shell history.

Quick Start

Python:

python3 -m venv .venv && source .venv/bin/activate && pip install -r requirements.txt
python device_flow.py --client-id YOUR_CLIENT_ID

Node.js: (no dependencies!)

node device_flow.js --client-id YOUR_CLIENT_ID

Go: (no dependencies!)

go run device_flow.go --client-id YOUR_CLIENT_ID

Shell: (requires curl + jq)

./device_flow.sh --client-id YOUR_CLIENT_ID

Documentation

Guide Description
Setup GitHub App Create and configure a GitHub App for Device Flow
Python Setup and usage for Python script
Node.js Setup and usage for Node.js script
Go Setup and usage for Go script
Shell Setup and usage for Shell script
Common Issues Troubleshooting and token usage

Prerequisites

How It Works

  1. Script requests a device code from GitHub
  2. You visit github.com/login/device and enter the displayed code
  3. Script polls until you authorise
  4. You get a user access token (ghu_...) that acts on your behalf

Token Permissions

GitHub Apps define permissions in the App's settings (Permissions & events), not at authorisation time. This differs from OAuth Apps where you request scopes in the OAuth request.

See Also

About

Generate GitHub App user access tokens (ghu_) via OAuth Device Flow — multi-language examples for CLI apps

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published