My scrapbook about anything which I learned or want to remember, Sometime about tech tips, thoughts and rambling. If you find anything useful don't forget to give thumbs-up :)

Breaking

Thursday, June 1, 2023

Get User details from Github Token

While managing my environment, I've stumble-upon few Github tokens (PAT or Personal Access Token) which was mentioned in my scratch book but silly me, I forgot to mention the user name of those tokens. After few google search, I have found few ways to fetch the username of those PATs which I am going to discuss here. 

Programmatically:
  You can write down program to complete the ask but it does not worth the effort until you are in really need it. You can use any programming language to do this magic whether you are using Python (PyGithub), Ruby (Oktokit) or Go (go-github), it's pretty straight-forward if you get hold on the libraries. 

Via Script/Curl:
    But as I said earlier, It is too much to write code if you have to do only this. It can be done pretty easily with simple curl.  Github provides API to fetch the authenticated user details which we can tweak for Github enterprise as well. 

curl -L \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>"\
  -H "X-GitHub-Api-Version: 2022-11-28" \
  https://api.github.com/user 

Let's see the complete script - 

Demo:



Like the below page to get the update 
Facebook Page      Facebook Group      Twitter Feed     

No comments:

Post a Comment

Disclaimer

The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.