Skip to content

feat(examples): add bash-cli example using device code flow#3

Merged
appleboy merged 15 commits intomainfrom
feat/bash-cli
Mar 27, 2026
Merged

feat(examples): add bash-cli example using device code flow#3
appleboy merged 15 commits intomainfrom
feat/bash-cli

Conversation

@appleboy
Copy link
Copy Markdown
Member

Summary

  • Add a pure bash CLI example implementing OAuth 2.0 Device Authorization Grant (RFC 8628)
  • Only requires curl and jq — no SDK or runtime needed
  • Supports OIDC auto-discovery, token caching, refresh token rotation, and re-authentication on invalid tokens
  • Handles cross-platform date conversion (macOS + Linux)

Test plan

  • Run without jq installed → dependency error
  • Run without env vars → usage error
  • Run with unreachable server → clear connection error
  • Run full device code flow → authenticate and print token info
  • Run again → uses cached token without re-authentication
  • Compare output format with go-cli output

🤖 Generated with Claude Code

- Implement OAuth 2.0 Device Authorization Grant (RFC 8628) in pure bash
- Support OIDC auto-discovery, token caching, and refresh token rotation
- Handle cross-platform date conversion for macOS and Linux
- Add bash-cli section to examples README
Copilot AI review requested due to automatic review settings March 26, 2026 15:06
- Pass POST data and auth headers via stdin to prevent token leaks in process list
- URL-encode all form data values for correctness
- Use mktemp for unpredictable temp file paths
- Fix cache file permissions on load
- Consolidate multi-jq calls into single invocations per function
- Use bash parameter expansion in _parse_response hot path
- Extract run_device_flow to eliminate duplicated prompt block
- Remove redundant fetch_userinfo call from print_token_info
- Detect platform date flavor once at startup
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new bash-based CLI example demonstrating AuthGate authentication via OAuth 2.0 Device Authorization Grant (RFC 8628), complementing the existing Go/Python examples and enabling a “no SDK” flow using only common CLI tools.

Changes:

  • Introduces bash-cli/main.sh, a pure Bash implementation of the device code flow with OIDC discovery, token caching, refresh, and re-auth on invalid tokens.
  • Updates the root README.md to document how to run the new Bash CLI example.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
bash-cli/main.sh New Bash device-code CLI with discovery, polling, refresh, cache read/write, and token/userinfo/tokeninfo output
README.md Adds a brief section documenting the new Bash CLI example

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@appleboy appleboy requested a review from Copilot March 27, 2026 05:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 13 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@appleboy appleboy merged commit 2edd837 into main Mar 27, 2026
4 checks passed
@appleboy appleboy deleted the feat/bash-cli branch March 27, 2026 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants