Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github GET on private repo with access token

Tags:

I have a private repo in my org and I need to provide access. I want to be able to access a file through a GET request (the browser). I do NOT have a terminal or curl or any other tools.

I created a dummy account that I linked to my org. I went to https://github.com/settings/tokens and added one.

Then I tried the following URLS

  • https://raw.githubusercontent.com/ORG/REPO/master/path/to/file.json?private_token=26cb4d8a30ca2
  • https://raw.githubusercontent.com/ORG/REPO/master/path/to/file.json?token=26cb4d8a30ca2

which does not work. It only seems to work with the generated token that you get when you click on "raw" on the github gui. Unfortunately this token expires quickly so it does not work for my application.

How do I access private resource on github with an access token through a URL ?

like image 534
bny Avatar asked Oct 03 '16 08:10

bny


People also ask

Can I give access to private repo GitHub?

Under your repository name, click Settings. In the "Access" section of the sidebar, click Collaborators & teams. Click Invite a collaborator. In the search field, start typing the name of person you want to invite, then click a name in the list of matches.


2 Answers

The API docs list that you can use the parameter access_token to pass in an oauth token (not private_token or token).

Does https://raw.githubusercontent.com/ORG/REPO/master/path/to/file.json?access_token=26cb4d8a30ca2 work for you?

like image 51
Azquelt Avatar answered Sep 20 '22 19:09

Azquelt


To fetch raw use:

curl \
  -H 'Authorization: token <personal token gen value>' \
  https://raw.<host>/user/org/repo/pathtofile

To fetch through api:

curl \
  -H 'Authorization: token <personal token gen>' \
  -H 'Accept:application/vnd.github.VERSION.raw' \
  https://<host_name>/api/v3/repos/<user>/<repo_name>/contents/<path_to_file>/?ref=<branch>
like image 34
PruthviRaj Reddy Avatar answered Sep 21 '22 19:09

PruthviRaj Reddy