如何解决使用 Typescript 和 Node 在 CLI 中克隆 git 存储库
我正在用 CLI
在 nodejs
中编写我的 typescript
。
我需要克隆 git 存储库,然后运行 npm i
。
我需要使用凭据或 SSO 再次对 github 进行身份验证。如何以及是否可以实施?我试过 octokit/rest
但没有成功。
似乎这个库已被弃用。
你能建议我选择哪一个或如何实施吗?
export class GitAuthManager {
private readonly appHubRepositoryUrl = 'https://github.';
private readonly umsRepositoryUrl = 'https://github';
private git: SimpleGit;
private octokit: any;
constructor() {
}
getInstance() {
return this.octokit;
}
gitAuthToken(token: string) {
this.octokit = new Octokit.Octokit({ auth: token });
}
async getPersonalAccessToken() {
const credentials: GitAuthAnswer = await askGithubCredentials();
const status = new Spinner('Authenticating you,please wait...');
status.start();
this.octokit = new Octokit.Octokit({ auth: `${credentials.username}:${credentials.password}` });
const payload = {
note: `your token`,scopes: ['user','public_repo','repo','repo:status','delete_repo','gist']
}
try {
const { data } = await this.octokit.oauthAuthorizations.createAuthorization(payload);
console.log(data)
return data;
} catch (err) {
throw new Error(`Error creating GitHub token\n${ err.message }`);
} finally {
status.stop();
}
this.git.clone(this.umsRepositoryUrl,[],() => {
console.log('Completed cloning...');
});
}
}`
this is my implementation. Which doesn't work.
解决方法
自从github deprecated http basic auth at Nov 13,2020
您肯定无法使用凭据(用户名和密码)进行身份验证。 您可以按照 github offical oauth documentation
中的说明使用 oauth然后您可以使用 octokit/auth-oauth-app 来帮助您通过 github 进行身份验证,或者只需将访问令牌附加到您的请求标头中,例如:
curl -H 'Authorization: token my-oauth-token' https://api.github.com/user/repos
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。