32

Do GitHub raw urls for private repositories expire? I'm referring to the link generated when you click the Raw button while viewing a file on github.com.

The link includes a token but there's no info about where that token comes from.

user4722818
  • 423
  • 1
  • 4
  • 6

3 Answers3

22

No one has clearly mentioned this, but the github raw urls expire in 7 days.

You can use longer lasting personal access tokens generated here: https://github.com/settings/tokens but those can only be used via curl:

curl -H 'Authorization: token <personal_token>' <raw_url>

Note that the personal access tokens expire if unused for an entire year.

rouble
  • 16,364
  • 16
  • 107
  • 102
  • 2
    As of June 2021 this should be the accepted answer. Original question and accepted answer are 5 years old at this point and a lot has changed since. – Juan Jun 14 '21 at 15:04
  • 2
    This method should work for any request-based tool, not just cURL. Just add the header `Authorization: token – StephenGodderidge Jun 14 '21 at 16:38
  • The link is broken for the source. I had the feeling that the links already expire after a few hours, but could be wrong. – User Rebo Oct 27 '22 at 12:08
4

That token comes from using OAuth with Git

https://<oauth-secret>:x-oauth-basic@raw.githubusercontent.com/<me>/<repo>/master/<file>

The raw.githubusercontent.com/<me>/<repo>/master/<file> part does not expire.
But it is to type 'y' before clicking 'Raw' on the GitHub page, in order to get the SHA1 as part of the url: that way, you are sure to reference always the same file version.

https://<oauth-secret>:x-oauth-basic@raw.githubusercontent.com/<me>/<repo>/<sha1>/<file>
                              ^                                             ^^^^

The token part does not "expire" (but it can be deleted or revoked)

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
2

Please look at this API document, https://developer.github.com/v3/repos/contents/.

The URL should be:

curl -H 'Accept: application/vnd.github.VERSION.raw' -k \
https://{{githubhost}}/api/v3/repos/{{org}}/{{repo}}/contents/{{path}}?access_token=xxxx

It worked for me:

  • The access_token is personal access token.
  • And the path canbe a file or dir.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250