简体   繁体   English

如何使用 Github API 创建和删除个人访问令牌?

[英]How to Create and Delete Personal Access Token's with the Github API?

I have a github bot with a personal access token that some github actions use to make commits during some action runs.我有一个带有个人访问令牌的 github 机器人,一些 github 操作用于在某些操作运行期间进行提交。 I'd like to make a script that can automatically swap out this personal access token, and delete the old one via a cron job.我想制作一个脚本,可以自动换出这个个人访问令牌,并通过 cron 作业删除旧的。 Is this possible with the github API?这可以通过 github API 实现吗? If it's not possible, is there another mechanism I should be using instead perhaps?如果不可能,我是否应该使用另一种机制来代替?

No, not for personal access token, whose API is deprecated, and removed in Nov. 2020 .不,不适用于个人访问令牌, 其 API 已弃用,并于 2020 年 11 月删除

You could try instead an installation access token for an app , which does have an API for creation.您可以尝试使用 app安装访问令牌,它确实具有用于创建的 API。

By default the installation token has access to all repositories that the installation can access.默认情况下,安装令牌可以访问安装可以访问的所有存储库。
To restrict the access to specific repositories, you can provide the repository_ids when creating the token.要限制对特定存储库的访问,您可以在创建令牌时提供repository_ids When you omit repository_ids, the response does not contain the repositories key.当您省略 repository_ids 时,响应不包含存储库键。

But that token, valid only one hour from the time you create them, might not have access to the same kind of action a PAT would have.但是,该令牌仅在您创建它们后一小时内有效,可能无法访问 PAT 具有的相同类型的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM