Handle SAML enforcement challenge from the server (#5054)
Whenever a SSO challenge gets issued by the server by means of a URL in the `X-GitHub-SSO` response header, gh now additionally prints that URL on the standard error stream. This is achieved by installing a middleware to all HTTP requests and storing the server challenge to a value accessible by `factory.SSOURL()`. Such approach was made necessary mainly because of the `shurcool-graphql` client which doesn't give access to response headers when a GraphQL error case is encountered.
This commit is contained in:
parent
f950637b0b
commit
66c18b40f2
5 changed files with 63 additions and 7 deletions
|
|
@ -224,8 +224,9 @@ func mainRun() exitCode {
|
|||
var httpErr api.HTTPError
|
||||
if errors.As(err, &httpErr) && httpErr.StatusCode == 401 {
|
||||
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")
|
||||
} else if u := factory.SSOURL(); u != "" {
|
||||
// handles organization SAML enforcement error
|
||||
fmt.Fprintf(stderr, "Authorize in your web browser: %s\n", u)
|
||||
} else if msg := httpErr.ScopesSuggestion(); msg != "" {
|
||||
fmt.Fprintln(stderr, msg)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue