Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Path gets URL-encoded when using fine-grained tokens #2422

Open
1 task done
tamoreton opened this issue Apr 11, 2023 · 2 comments
Open
1 task done

[BUG]: Path gets URL-encoded when using fine-grained tokens #2422

tamoreton opened this issue Apr 11, 2023 · 2 comments
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented

Comments

@tamoreton
Copy link

tamoreton commented Apr 11, 2023

What happened?

When using octokit.rest.repos.getContent like

    ({ data: markdown } = await octokit.rest.repos.getContent({
      owner: "infinityworks",
      repo: "handbook",
      path: "docs/introduction.md",
      mediaType: {
        format: "raw",
      },
    }));

using a classic PAT that looks like ghp_[REDACTED], it works as expected. However, I want to use a fine-grained token with read access to just the repo I need content from for security reasons. When I do exactly the same call as above but substituting a fine-grained PAT that looks like github_pat_[REDACTED], I get a RequestError [HttpError]: Not Found. When I log the response I note that the request field looks like:

 {
    "method": "GET",
    "url": "https://api.github.com/repos/infinityworks/handbook/contents/docs%2Fintroduction.md",
    "headers": {
      "accept": "application/vnd.github.v3.raw",
      "user-agent": "octokit.js/2.0.14 octokit-core.js/4.2.0 Node.js/18.13.0 (darwin; arm64)",
      "authorization": "token [REDACTED]"
    },
    "request": { "hook": /* ... */ }
  }

It seems that for some reason, using a fine-grained PAT causes getContent to go down a branch which URL-encodes path.

Versions

Octokit.js v2.0.14, Node v18.13.0

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@tamoreton tamoreton added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Apr 11, 2023
@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone Priority: Normal and removed Status: Triage This is being looked at and prioritized labels Apr 11, 2023
@kfcampbell kfcampbell moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Apr 17, 2023
@RupertBarrow
Copy link

I'm getting the same issue when using a Github OAuthApp :

  // Authentication

  this.github.app = new OAuthApp({
    clientType: "oauth-app",
    clientId: this.config.client_id,
    clientSecret: this.config.client_secret,
  })
  // Request

  request: {
    method: 'GET',
    url: 'https://api.github.com/repos/<owner>/<repo>/contents/.github%2Fworkflows%2Fmywf.yml%3Fref%3Dfeature%2F1-add-checkout-and-deploy-to-github-actions',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit.js/2.0.14 octokit-core.js/4.2.0 Node.js/18.16.0 (darwin; x64)',
      authorization: 'token [REDACTED]'
    }

Response.status is 404

@RupertBarrow
Copy link

Do you think that this is related to octokit/endpoint.js#207 (which has been fixed) ?

@nickfloyd nickfloyd added the hacktoberfest Issues for participation in Hacktoberfest label Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Bug Something isn't working as documented
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

4 participants