From b0b67014f124a8eeeb74c8a921fd79f69f66a576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 30 Aug 2021 17:18:59 +0200 Subject: [PATCH] Suggest to re-authenticate to fix "SAML enforcement" error As far as I can put together, this error appears when someone has authenticated GitHub CLI with a PAT that isn't authorized to access a certain org. It can also happen if someone has authorized GitHub CLI using the legacy "GitHub CLI (dev)" OAuth app instead of our production OAuth app. Doing `gh auth refresh` will re-authenticate the user using our production "GitHub CLI" OAuth app which will not have problems accessing resources in different GitHub organizations. --- cmd/gh/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/gh/main.go b/cmd/gh/main.go index 05b4596b5..97f5ae33b 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -217,13 +217,15 @@ func mainRun() exitCode { if strings.Contains(err.Error(), "Incorrect function") { fmt.Fprintln(stderr, "You appear to be running in MinTTY without pseudo terminal support.") - fmt.Fprintln(stderr, "To learn about workarounds for this error, run: gh help mintty") + fmt.Fprintln(stderr, "To learn about workarounds for this error, run: gh help mintty") return exitError } var httpErr api.HTTPError if errors.As(err, &httpErr) && httpErr.StatusCode == 401 { - fmt.Fprintln(stderr, "hint: try authenticating with `gh auth login`") + fmt.Fprintln(stderr, "Try authenticating with: gh auth login") + } else if strings.Contains(err.Error(), "Resource protected by organization SAML enforcement") { + fmt.Fprintln(stderr, "Try re-authenticating with: gh auth refresh") } return exitError