Skip to content

Document how to fix "Resource protected by organization SAML enforcement" #2661

Closed

Description

@hoxu

When an organization enables SAML enforcement, gh starts giving the following error:

$ gh pr create ...
GraphQL error: Resource protected by organization SAML enforcement. You must grant your OAuth token access to this organization.

This is confusing, because if you check your https://github.com/settings/tokens page, the gh token is not there, so it's not immediately obvious what the user should do.

What is required is re-authentication, but it would be a good idea to cover this in a FAQ entry:

$ gh auth login
? What account do you want to log into? GitHub.com
- Logging into github.com
? You're already logged into github.com as XXX. Do you want to re-authenticate? Yes

Or maybe just tell the user to run gh auth login when the command fails with that error.

Activity

  1. added
    enhancement
    on Dec 21, 2020
  2. added
    priority-2
    on Jan 28, 2021
  3. viliam-durina commented on Feb 17, 2021

    @viliam-durina

    Thankfully google took me here so this issue already acts as a FAQ entry.

  4. leiflundberg commented on Aug 25, 2021

    @leiflundberg

    Bumping this as it fixed my problem 👍🏼

  5. imonkia commented on Jan 13, 2023

    @imonkia

    This was super helpful. Spent an unnecessary amount of time trying to "fix" this "issue". Thanks!

  6. AnkurAgarwal-ST commented on May 2, 2023

    @AnkurAgarwal-ST

    Super helpful, fixed my issue immediately.

  7. rkaurSFDX commented on Jul 27, 2023

    @rkaurSFDX

    Fixed my issue as well, thanks a ton!

  8. D99013682 commented on Sep 26, 2023

    @D99013682

    I have a service connection between Azure DevOps and GitHub for the pipelines to communicate with. It isn't possible to have the user re-authorize with a command. How do I fix the service connection to be re-authorized so when the pipeline is triggered it doesn't need this?

  9. ffisc commented on Dec 20, 2023

    @ffisc

    Thanks for the solution.
    @mislav I'm not sure why this issue is closed, since I just got the error and didn't get any suggestions of what to do.
    In fact the behavior was misleading: I got a link to authorize in my browser, followed the authorization, but continued to get an error. Only gh auth login fixed it.

  10. zyrain commented on Mar 14, 2024

    @zyrain

    This is not fixed. Re-open please.

  11. andyfeller commented on Jun 7, 2024

    @andyfeller
    Contributor

    for posterity, I'm explicitly linking this back to #5054 where the original solution was reworked to give users direction to authorize the organization associated with the PAT within the web browser:

    cli/cmd/gh/main.go

    Lines 158 to 166 in 6f558c9

    var httpErr api.HTTPError
    if errors.As(err, &httpErr) && httpErr.StatusCode == 401 {
    fmt.Fprintln(stderr, "Try authenticating with: gh auth login")
    } 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)
    }

  12. andyfeller commented on Jun 7, 2024

    @andyfeller
    Contributor

    This is not fixed. Re-open please.

    @zyrain : Please create a new issue including terminal commands, output, gh version, and any verbose / debug information so we can triage and prioritize! ❤

  13. bigben79 commented on Nov 25, 2024

    @bigben79

    Fixed my issue as well 👍

  14. berenar commented on Feb 21, 2025

    @berenar

    Thanks 🚀

  15. KoalaBear84 commented on May 1, 2025

    @KoalaBear84

    This should not be closed yet, as you still get this error without any hint to use gh auth login or gh auth refresh. But thanks, at least Google is helpful to guide us to this (unresolved) issue.

  16. ssbarnea commented on Aug 27, 2025

    @ssbarnea

    I totally agree that this should be reopened. While I get the message and use the browser to "authorize", it has no effect on gh cli. Even running gh auth refresh does nothing. In the browser I can access the repo, but not from gh cli.

    Does anyone have other hints?

  17. ssbarnea commented on Aug 27, 2025

    @ssbarnea

    Update: I was able to address this by going to my ssh key settings and enabling SSO access for it, something that the current error message does not say. I assume it assumes that you tried HTTP token approach, which was not the case.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority-2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions