Giter VIP home page Giter VIP logo

oauth's Introduction

GitHub CLI

gh is GitHub on the command line. It brings pull requests, issues, and other GitHub concepts to the terminal next to where you are already working with git and your code.

screenshot of gh pr status

GitHub CLI is supported for users on GitHub.com and GitHub Enterprise Server 2.20+ with support for macOS, Windows, and Linux.

Documentation

For installation options see below, for usage instructions see the manual.

Contributing

If anything feels off, or if you feel that some functionality is missing, please check out the contributing page. There you will find instructions for sharing your feedback, building the tool locally, and submitting pull requests to the project.

If you are a hubber and are interested in shipping new commands for the CLI, check out our doc on internal contributions.

Installation

macOS

gh is available via Homebrew, MacPorts, Conda, Spack, Webi, and as a downloadable binary including Mac OS installer .pkg from the releases page.

Note

As of May 29th, Mac OS installer .pkg are unsigned with efforts prioritized in cli/cli#9139 to support signing them.

Homebrew

Install: Upgrade:
brew install gh brew upgrade gh

MacPorts

Install: Upgrade:
sudo port install gh sudo port selfupdate && sudo port upgrade gh

Conda

Install: Upgrade:
conda install gh --channel conda-forge conda update gh --channel conda-forge

Additional Conda installation options available on the gh-feedstock page.

Spack

Install: Upgrade:
spack install gh spack uninstall gh && spack install gh

Webi

Install: Upgrade:
curl -sS https://webi.sh/gh | sh webi gh@stable

For more information about the Webi installer see its homepage.

Flox

Install: Upgrade:
flox install gh flox upgrade toplevel

For more information about Flox, see its homepage

Linux & BSD

gh is available via:

For more information, see Linux & BSD installation.

Windows

gh is available via WinGet, scoop, Chocolatey, Conda, Webi, and as downloadable MSI.

WinGet

Install: Upgrade:
winget install --id GitHub.cli winget upgrade --id GitHub.cli

Note
The Windows installer modifies your PATH. When using Windows Terminal, you will need to open a new window for the changes to take effect. (Simply opening a new tab will not be sufficient.)

scoop

Install: Upgrade:
scoop install gh scoop update gh

Chocolatey

Install: Upgrade:
choco install gh choco upgrade gh

Signed MSI

MSI installers are available for download on the releases page.

Codespaces

To add GitHub CLI to your codespace, add the following to your devcontainer file:

"features": {
  "ghcr.io/devcontainers/features/github-cli:1": {}
}

GitHub Actions

GitHub CLI comes pre-installed in all GitHub-Hosted Runners.

Other platforms

Download packaged binaries from the releases page.

Build from source

See here on how to build GitHub CLI from source.

Comparison with hub

For many years, hub was the unofficial GitHub CLI tool. gh is a new project that helps us explore what an official GitHub CLI tool can look like with a fundamentally different design. While both tools bring GitHub to the terminal, hub behaves as a proxy to git, and gh is a standalone tool. Check out our more detailed explanation to learn more.

oauth's People

Contributors

arcanericky avatar jamierocks avatar looneym avatar markandrus avatar mislav avatar swinton avatar vertextau avatar vilmibm avatar wingkwong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oauth's Issues

Can I create an access token with SSO enabled?

I'm trying to create a CLI tool for internal use at my company that can access an internal repository in our GitHub Enterprise Cloud organization (we have SSO enabled). I can use this library to successfully create an access token for my account, but I can't use the access token to access my repository. Is it possible to request that the access token have SSO enabled programmatically so that I can use it to hit an internal repository, or would I be better off just asking my users to provide a personal access token with SSO already enabled?

Introduce safe host parsing command

Description

See bug report: cli/cli#9248

TL;DR: The current host parsing function is non-idiomatic and hides errors opening the possibility for panics. We can't change the existing function without a breaking change so we will introduce a new function with signature func NewHost(hostname string) (*Host, error).

oauth/oauth.go

Lines 28 to 36 in adf5f73

func GitHubHost(hostURL string) *Host {
u, _ := url.Parse(hostURL)
return &Host{
DeviceCodeURL: fmt.Sprintf("%s://%s/login/device/code", u.Scheme, u.Host),
AuthorizeURL: fmt.Sprintf("%s://%s/login/oauth/authorize", u.Scheme, u.Host),
TokenURL: fmt.Sprintf("%s://%s/login/oauth/access_token", u.Scheme, u.Host),
}
}

@fingolfin Thats seems like a good idea. Will you make the PR ?

@fingolfin Thats seems like a good idea. Will you make the PR ?


Once you have selected your values for your --json flag and made them pretty with --template, you can then pass your command through fzf for an interactive experience.

Take advantage of the environment variable GH_FORCE_TTY, to enable terminal-style output even when the output is redirected (see gh environment for more details about it).

Example:

Code

# .zshrc gh pr list command extended with fzf, see the man page (man fzf) for an explanation of the arguments.
function ghpr {
	[[ ! "$(git rev-parse --is-inside-work-tree)" ]] && return 1
	GH_COMMAND='gh pr list --state open --json number,author,additions,deletions,updatedAt,title --template "
	{{- tablerow (\"PR\" | color \"blue+b\") (\"LAST UPDATE\" | color \"blue+b\") (\"AUTHOR\" | color \"blue+b\") \"\" \"\" (\"TITLE\" | color \"blue+b\") -}}
	{{- range . -}}
		{{- tablerow (printf \"#%v\" .number | color \"green+h\") (timeago .updatedAt | color \"gray+h\") (.author.login | color \"cyan+h\") (printf \"+%v\" .additions | color \"green\") (printf \"-%v\" .deletions | color \"red\") .title -}}
	{{- end -}}" --search'
	FZF_DEFAULT_COMMAND="$GH_COMMAND ${1:-\"\"}" \
		GH_FORCE_TTY=100% fzf --ansi --disabled --no-multi --header-lines=1 \
		--header $'CTRL+B - Browser | CTRL+D - Toggle Diff  | CTRL+X - Checkout\nCTRL+E - Edit    | CTRL+I - Toggle Info  | CTRL+Y - Comment' \
		--prompt 'Search Open PRs >' --preview-window hidden:wrap \
		--layout=reverse --info=inline --no-multi \
		--bind "change:reload:sleep 0.25; $GH_COMMAND {q} || true" \
		--bind 'ctrl-b:execute-silent(gh pr view {1} --web)' \
		--bind 'ctrl-d:toggle-preview+change-preview(gh pr diff {1} --color always)' \
		--bind 'ctrl-i:toggle-preview+change-preview(gh pr view {1} --comments)' \
		--bind 'ctrl-e:accept+execute(gh pr edit {1})' \
		--bind 'ctrl-x:accept+execute(gh pr checkout {1})' \
		--bind 'ctrl-y:accept+execute(gh pr comment {1})'
}

GIF

In the example I used nano as editor to write the comment, but you can set your own with gh config set editor ....

Originally posted by @LangLangBart in cli/cli#6089 (comment)

Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message.

Hi! Thanks for the pull request. Please ensure that this change is linked to an issue by mentioning an issue number in the description of the pull request. If this pull request would close the issue, please put the word 'Fixes' before the issue number somewhere in the pull request body. If this is a tiny change like fixing a typo, feel free to ignore this message.

Originally posted by @cliAutomation in cli/cli#3943 (comment)

Device Flow does not work with JSON Responses

I've been testing this library out with the device code flow feature in the Dex Authorization framework (https://github.com/dexidp/dex) and it doesn't seem to work properly.

After digging into the code a little bit, I realized that this library expects the response to be encoded as a form. If it does not receive a response in that form, it falls back to the webapp flow.

However, the official RFC for the Device Code flow explicitly expects a JSON response.

Would a PR that allows for both response types be welcome?

Add support for custom strings in Device Flow

On the device flow, add support to specify the message to be shown to the user.

On oauth_device.go, currently the messages are:
fmt.Fprintf(stdout, "First, copy your one-time code: %s\n", code.UserCode)
fmt.Fprint(stdout, "Then press [Enter] to continue in the web browser... ")

Note: I had erroneously committed to `master` instead of to a feature branch before creating this PR — I suppose that may be why I saw this message. Regardless, `gh` didn't help me figure this out, but instead confused me further; so I suppose the message could be clarified.

Note: I had erroneously committed to master instead of to a feature branch before creating this PR — I suppose that may be why I saw this message. Regardless, gh didn't help me figure this out, but instead confused me further; so I suppose the message could be clarified.

Originally posted by @waldyrious in cli/cli#2090 (comment)

## What's Changed

What's Changed

New Contributors

Full Changelog: cli/cli@v2.5.1...v2.5.2


This discussion was created from the release GitHub CLI 2.5.2.

Originally posted by @github-actions[bot] in cli/cli#5265

PollToken should cancel early if the context is canceled

This is kind of a nice issue, but in a console app I am working on the app intercepts the os SIGKILL/SIGINT signals to do all of its own graceful shutdown via context, but currently there is no way to cancel the loop in PollToken.

To make this cancelable, it would be nice to something like this into the loop there.

		select {
		case <-ctx.Done():
			return nil, ErrCanceled
		default:
			timeSleep(checkInterval)
		}

Then the function could be extended like a lot of packages with a second copy of the method, and context propagated down.

func PollTokenContext(ctx context.Context, c httpClient, pollURL string, clientID string, code *CodeResponse) (*api.AccessToken, error) {
... current implementation
}

func PollToken(c httpClient, pollURL string, clientID string, code *CodeResponse) (*api.AccessToken, error) {
  return PollTokenContext(context.Background(), c, pollURL, clientID, code)
}

The same thing could be done to DetectFlow, or it could be embbed within the flow struct so the outer api layout would change less.

[Question] Interest in adding support for the Microsoft identity platform's OAuth device flow?

Hey there! Thanks for making this oauth module, it's awesome!

Curious if there is interest in adding support for the Microsoft identity platform's OAuth device flow?

I took a quick look at what's needed, and I think potentially the "only" change would be to support a JSON response from the device code endpoint, currently it looks like we only handle form responses:

const formType = "application/x-www-form-urlencoded"

I think if it could accept JSON, then other OAuth servers, like Microsoft identity platform's, would come for free.

Thoughts?

How should OAuth Client IDs be distributed to headless apps?

Hi, I apologize if I've just missed something in the documentation but, should our OAuth App Client IDs be kept secret? In the case of writing a headless app how should we distribute the Client IDs to the user's applications so that they can authenticate with GitHub? Is it best to write a server side relay that requests the tokens on the behalf of the CLI tool and then passes the resulting temporary code and token back to the user, so that the user never has access to the Client ID, or is it safe to embed the client ID in a distributed binary/source code? Thanks for your time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.