How to Create and Delete Personal Access Token's with the Github API? #1902
Replies: 1 comment 4 replies
-
It is possible using Basic Authentication, but note that authenticating using basic authentication is deprecated. const { Octokit } = require("@octokit/rest");
const { createBasicAuth } = require("@octokit/auth-basic");
const octokit = new Octokit({
authStrategy: createBasicAuth,
auth: {
username,
password,
token: {
scopes: ["repo"],
},
async on2Fa() {
throw new Error("2Fa not supported for bot accounts");
},
},
}); This will transparently create a personal access token the first time you send a request with the const authorization = await octokit.auth({ type: "token" });
await octokit.request("DELETE /authorizations/:authorization_id", {
authorization_id: authorization.id,
}); But you mention that you use GitHub Actions. Is there a reason that you cannot use the provided git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/owner/repo.git The reasons the |
Beta Was this translation helpful? Give feedback.
-
I have a github bot with a personal access token that some github actions use to make commits during some action runs. I'd like to make a script that can automatically swap out this personal access token, and delete the old one. Is this possible with the github API? If it's not possible, is there another mechanism I should be using instead perhaps?
Beta Was this translation helpful? Give feedback.
All reactions