Skip to content

Conversation

@ankddev
Copy link
Contributor

@ankddev ankddev commented Aug 16, 2025

Fixes #11354

Description

Add -c/--clipboard flag to gh auth login and gh auth refresh which copies one-time OAuth device code to clipboard instead of just printing it.

Notes

  • feat: add ability to copy one-time OAuth code while logging in

@ankddev ankddev requested a review from a team as a code owner August 16, 2025 06:30
@ankddev ankddev requested a review from williammartin August 16, 2025 06:30
@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Aug 16, 2025
@ankddev ankddev force-pushed the copy-one-time-code branch 4 times, most recently from 5eb0933 to 2c8ab15 Compare August 17, 2025 08:06
Copy link
Member

@BagToad BagToad left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up @ankddev 🙏 ✨

I noted a few issues I think we'll want to fix, the most important being how we should react when this fails. More details in the review comments 😁

Let me know if you have any questions!

ankddev and others added 6 commits August 19, 2025 08:56
Signed-off-by: Andrey <andrekabatareika@gmail.com>
Co-authored-by: Kynan Ware <47394200+BagToad@users.noreply.github.com>
Co-authored-by: Kynan Ware <47394200+BagToad@users.noreply.github.com>
Co-authored-by: Kynan Ware <47394200+BagToad@users.noreply.github.com>
@ankddev ankddev force-pushed the copy-one-time-code branch from 5f8d6a0 to 4d1587f Compare August 19, 2025 05:56
@ankddev ankddev requested a review from BagToad August 19, 2025 05:58
@ankddev
Copy link
Contributor Author

ankddev commented Aug 19, 2025

@BagToad Done!

Copy link
Member

@BagToad BagToad left a comment

Choose a reason for hiding this comment

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

Small nits to align the language between gh auth login and gh auth refresh help docs - I'll push these to get this over the line.

Copy link
Member

@BagToad BagToad left a comment

Choose a reason for hiding this comment

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

LGTM! This is a very useful change and works great 😁 Thanks @ankddev! 🚀

Some tests

Happy paths:

❯ ./bin/gh auth login -c           
? Where do you use GitHub? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
? How would you like to authenticate GitHub CLI? Login with a web browser

! One-time code (XXXX-XXXX) copied to clipboard
Press Enter to open https://github.com/login/device in your browser... 
❯ ./bin/gh auth refresh -c                  

! One-time code (XXXX-XXXX) copied to clipboard
Press Enter to open https://github.com/login/device in your browser...

Forcing a failure to see that it will be non-fatal:

❯ PATH=/nonexistent ./bin/gh auth login --web -c
? What is your preferred protocol for Git operations on this host? HTTPS
? Authenticate Git with your GitHub credentials? Yes

! Failed to copy one-time code to clipboard
  exec: "pbcopy": executable file not found in $PATH
! First copy your one-time code: XXXX-XXXX
Press Enter to open https://github.com/login/device in your browser... 
❯ PATH=/nonexistent ./bin/gh auth refresh -c    
? Authenticate Git with your GitHub credentials? Yes

! Failed to copy one-time code to clipboard
  exec: "pbcopy": executable file not found in $PATH
! First copy your one-time code: XXXX-XXXX
Press Enter to open https://github.com/login/device in your browser... 

@BagToad BagToad changed the title feat: add ability to copy one-time OAuth code while authenticating feat: gh auth Automatically copy one-time OAuth code to clipboard Aug 25, 2025
@BagToad BagToad merged commit 4e1318e into cli:trunk Aug 25, 2025
10 of 11 checks passed
@ankddev ankddev deleted the copy-one-time-code branch August 25, 2025 15:58
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Sep 12, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.78.0` -> `v2.79.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.79.0`](https://github.com/cli/cli/releases/tag/v2.79.0): GitHub CLI 2.79.0

[Compare Source](cli/cli@v2.78.0...v2.79.0)

#### Advanced Issue Search Support

The GitHub CLI now supports advanced issue search syntax using:

- Searching issues: `gh search issues <advanced issue search query>`
- Searching pull requests: `gh search prs <advanced issue search query>`
- While listing issues: `gh issue list --search <advanced issue search query>`
- While listing pull requests: `gh pr list --search <advanced issue search query>`

For more information about advanced issue search syntax, see: "[Filtering and Searching Issues and Merge Requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/filtering-and-searching-issues-and-pull-requests#building-advanced-filters-for-issues)"

#### Copy OAuth Code Automatically

The GitHub CLI now supports writing the OAuth one-time pass code to the clipboard automatically during authentication:

- While logging in: `gh auth login --clipboard` / `gh auth login -c`
- While refreshing the token: `gh auth refresh --clipboard` / `gh auth refresh -c`

#### What's Changed

##### ✨ Features

- feat: `gh auth` Automatically copy one-time OAuth code to clipboard by [@&#8203;ankddev](https://github.com/ankddev) in [#&#8203;11518](cli/cli#11518)
- feat: add support for `--ref` in `gh cache delete` by [@&#8203;luxass](https://github.com/luxass) in [#&#8203;11592](cli/cli#11592)
- Use advanced issue search by [@&#8203;babakks](https://github.com/babakks) in [#&#8203;11638](cli/cli#11638)

##### 📚 Docs & Chores

- docs(release create): difference `--generate-notes` and `--notes-from-tag` by [@&#8203;ankddev](https://github.com/ankddev) in [#&#8203;11534](cli/cli#11534)
- refactor tests: use `slices.Equal` to simplify code by [@&#8203;minxinyi](https://github.com/minxinyi) in [#&#8203;11364](cli/cli#11364)
- Remove mention of public preview in trustedroot.go by [@&#8203;jkylekelly](https://github.com/jkylekelly) in [#&#8203;11652](cli/cli#11652)

##### :dependabot: Dependencies

- Bump sigstore/rekor to v1.4.1 by [@&#8203;BagToad](https://github.com/BagToad) in [#&#8203;11654](cli/cli#11654)
- chore(deps): bump actions/stale from 9 to 10 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;11663](cli/cli#11663)
- chore(deps): bump actions/setup-go from 5 to 6 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;11662](cli/cli#11662)

#### New Contributors

- [@&#8203;minxinyi](https://github.com/minxinyi) made their first contribution in [#&#8203;11364](cli/cli#11364)
- [@&#8203;jkylekelly](https://github.com/jkylekelly) made their first contribution in [#&#8203;11652](cli/cli#11652)
- [@&#8203;luxass](https://github.com/luxass) made their first contribution in [#&#8203;11592](cli/cli#11592)

**Full Changelog**: <cli/cli@v2.78.0...v2.79.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS45OC4xIiwidXBkYXRlZEluVmVyIjoiNDEuOTguMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
@nguyenan852001

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance gh auth login to copy one-time code into clipboard before launching browser

4 participants