Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 3
Message 1 of 2

Error get commit author email when auth through username/password in GraphQL

So this works perfectly fine for OAuth/PAT but when I auth using username/password it gives following error, my expectation is given I have the username/password already I shall have full access. GitHub/GitHub Enterprise is consistent on this. And it works fine for other cases in GraphQL such as get a repo owner's email 

 

Error Message 

Your token has not been granted the required scopes to execute this query. The 'email' field requires one of the following scopes: ['user:email', 'read:user'], but your token has only been granted the: [''] scopes. Please modify your token's scopes at: https://abghe215.westus2.cloudapp.azure.com/settings/tokens.

 

GraphQL - Fails (Commit Author Email)

{
  repository(owner: "github", name: "training-kit") {
    object(expression: "HEAD") {
      ... on Commit {
        author {
          user {
            email
          }
        }
      }
    }
    nameWithOwner
  }
}
{
  "errors": [
    {
      "type": "INSUFFICIENT_SCOPES",
      "locations": [
        {
          "line": 7,
          "column": 13
        }
      ],
      "message": "Your token has not been granted the required scopes to execute this query. The 'email' field requires one of the following scopes: ['user:email', 'read:user'], but your token has only been granted the: [''] scopes. Please modify your token's scopes at: https://github.com/settings/tokens."
    }
  ]
}

 

GraphQL - Works (Repo owner email)

{
  repository(owner: "github", name: "training-kit") {
    nameWithOwner
    owner {
      ... on Organization {
        email
      }
    }
  }
}
{
  "data": {
    "repository": {
      "nameWithOwner": "github/training-kit",
      "owner": {
        "email": "support@github.com"
      }
    }
  }
}

 

 

1 Reply
Community Manager
Message 2 of 2

Re: Error get commit author email when auth through username/password in GraphQL

I'm suspect that this is because you're asking for:

 

 

... on Commit {
  author {
    user {
      email
    }
  }
}

 

 

Specifically, you're asking for the commit -> author -> user -> email instead of commit -> author -> email. The difference is that you're asking for the email of the GitHub user, which may or may not be public. If you ask for commit -> author -> email, then you'll get the email that is associated directly with the git commit, though it may be an anonymized one. You could also ask for commit -> author -> user -> name.

 

I hope that helps!