porter-archive icon indicating copy to clipboard operation
porter-archive copied to clipboard

Way to generate an API token with cli/api?

Open petersutter5 opened this issue 2 years ago • 3 comments

Is there a way to generate an API token with the CLI or API? I would like to write a script to rotate our github API key on a schedule instead of having to remember to do it on a schedule. Thank you.

petersutter5 avatar Nov 01 '23 17:11 petersutter5

from my research it seems there is. Yes, GitHub provides an API endpoint that allows you to generate personal access tokens programmatically. You can use this API to automate the process of rotating your GitHub API key on a schedule. Here's an overview of how you can do it:

HermanBide avatar Feb 29 '24 19:02 HermanBide

write a script that makes an HTTP request to the GitHub API to generate a new personal access token. Use the GitHub API endpoint for creating personal access tokens (/authorizations or /oauth/token) to generate a new token. You'll need to include your current API key as part of the request for authentication. Rotate the token: Once you've obtained a new token, update your applications or scripts to use the new token for authentication. You can then securely store the new token and discard the old one.

HermanBide avatar Feb 29 '24 19:02 HermanBide

Use a scheduling tool such as cron (on Unix-like systems) or Task Scheduler (on Windows) to run your script on a regular schedule. You can schedule the script to run daily, weekly, or at any other interval that works for your needs.

HermanBide avatar Feb 29 '24 19:02 HermanBide