Home > Enterprise >  GitHub redirects with cURL
GitHub redirects with cURL

Time:10-06

I was trying to create a repo in gitHub via cURL. However whenever I am trying to create the repo the it gives me the login URL via a redirect and I'm not able to proceed anywhere from there. Doesn't give me an option to insert my credentials as well. I am using my access token to login. Not sure how do I proceed from here.

So below is the piece of cURL I'm trying:

curl -H "Authorization: token" -k https://enterprise.github.com/orgs/internal/repositories -d '{\"name\": \"testRepo\", \"description\": \"my test repo\", "\private\":\true\}'

And I always get the below response back:

<html><body>You are being <a href="https://enterprise.github.com/login?return_to=https://enterprise.github.com/orgs/internal/repositories">redirected</a>.</body></html>

What I'm not able to figure out is how do I login from here and why do I have to do another login when I'm using access token to login? I have also tried using -L in the cURL, but that didn't helped either.

CodePudding user response:

So I am able to get rid of the redirect issue by using the below cURL. However, now I am seeing "Cookies must be enabled to use GitHub." message as a response from the below cURL:

curl \
-X POST \
-H "Accept: application/vnd.github json" \
-H "Authorization: Bearer access token" \
-k -L --post302 https://enterprise.github.com/orgs/internal/repositories \
-d '{\"name\": \"testRepo\", \"description\": \"my test repo\", "\private\":\true\}'

How to get rid of this Cookies must be enabled to use GitHub. error?

CodePudding user response:

The problem is that you're accessing the web interface instead of the API. For security reasons, tokens are not allowed to access the web interface.

For a GitHub Enterprise Server instance, depending on how it's configured, you either need to access something under https://api.enterprise.github.com or under https://enterprise.github.com/api/v3, depending on how your instance is configured. That is, the URL should be either https://api.enterprise.github.com/orgs/internal/repositories or https://enterprise.github.com/api/v3/orgs/internal/repositories.

  • Related