How to get token of a raw GitHub file

Hi Everyone,

Can someone help me, how to get a token from a raw file in private GitHub repository …
Generally that token will be at the end of url of that particular raw file when we click on raw button in that file…
I need to get that token from the url using cli like powershell or any API methods.
If that is possible please suggest

1 Like

Are you trying to download the file or do something else? For downloading, see here:

If it’s something else, please give us some more details of what you’re trying to do.

Actually my requirement is to get the token from url when we open a raw file in github private repo using cli or powershell or if any methods.
Please find below screenshot for reference. I want to capture only token from that url using cli or any other methods.

For that you can use URL parsing in whatever language you’re the most comfortable with, the part of the URL with parameters after the ? is called “query string”. For example in Python using urllib.parse:

>>> from urllib.parse import parse_qs, urlparse
>>> u = urlparse('')
>>> u.query
>>> parse_qs(u.query)
{'token': ['xyz']}

Its not capturing the token from the available url . My requirement is to access the private repo → Inside repo {file} → have to open the file using raw → then have to get the token, all of these steps needs to be done using cli not GUI.
{ Have to get the raw url using cli instead of using GUI so that i can do URL parsing later to get token.} Please let me know how we can achieve this. ?
I hope you understand if it is possible.
Thanks in Advance.

I don’t think there’s a way to do that, unless you want to look at automating the browser interface (e.g. using Selenium) including login.

But I’m wondering: Why would you ever need those tokens?

Actually I need those tokens to place them into my ARM templates so that when ever i update my files in github i will just take those tokens and update them in my templates.
Each and every time to go and copy those tokens for each file is getting difficult so I am checking is there anyway that can we do using automation ( cli or any methods ). Instead of going to github and opening that raw url and copying the token from GUI.

That’s not going to work, because those tokens have a limited lifetime. You’ll have to create a Personal Access Token (PAT) and download the files using that, using the Authorization header instead of a token in the URL.

Something like this:

curl -H "Authorization: token ${PAT}"

You can try<username>/<reponame>/raw/<branch>/<path-to-your-file>
This will return a “redirect (HTTP 302)” with location header value pointing to the URL with the token.
Since you are trying this from shell script, you probably have to access that URL with your PAT.
curl -H "Authorization: token ${PAT}"<username>/<reponame>/raw/<branch>/<path-to-your-file> and CURL by default will not follow redirects.