Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to generate an API token with cli/api? #3910

Open
petersutter5 opened this issue Nov 1, 2023 · 3 comments
Open

Way to generate an API token with cli/api? #3910

petersutter5 opened this issue Nov 1, 2023 · 3 comments

Comments

@petersutter5
Copy link

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.

@HermanBide
Copy link

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants