-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix:(GitHub Auth): Deprecate getAuthUsername #585
Changes from 3 commits
eadbe92
828b1d5
88b9422
2688e3b
8da197f
94b9d8e
f3d3a5c
59fa411
5daffec
0f02075
dbd6d3f
c8907b1
8381e1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,27 +26,14 @@ | |
public constructor( | ||
owner: string, | ||
repo: string, | ||
username?: string, | ||
apiToken?: string | ||
) { | ||
this.owner = owner; | ||
this.repo = repo; | ||
if (username && apiToken) { | ||
this.setAuth(username, apiToken); | ||
} | ||
this.url = `/${this.owner}/${this.repo}/`; | ||
} | ||
|
||
/** | ||
* Sets authentication arguments: username and personal API token | ||
* | ||
* @param username GitHub username | ||
* @param apiToken GitHub API token | ||
*/ | ||
public setAuth(username: string, apiToken: string): void { | ||
this.username = username; | ||
this.apiToken = apiToken; | ||
} | ||
|
||
/** | ||
* Returns an HTTP-based git remote | ||
|
@@ -56,19 +43,6 @@ | |
public getRemoteString(): string { | ||
return this.PROTOCOL_PREFIX + this.GITHUB_HOSTNAME + this.url; | ||
} | ||
|
||
/** | ||
* Returns an HTTP-based git remote with embedded HTTP basic auth | ||
* | ||
* It MAY contain sensitive information (e.g. API tokens) | ||
*/ | ||
public getRemoteStringWithAuth(): string { | ||
const authData = | ||
this.username && this.apiToken | ||
? `${this.username}:${this.apiToken}@` | ||
: ''; | ||
return this.PROTOCOL_PREFIX + authData + this.GITHUB_HOSTNAME + this.url; | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -87,6 +61,20 @@ | |
return githubApiToken; | ||
} | ||
|
||
/** | ||
* Returns the GitHub auth header | ||
* | ||
* @returns GitHub auth header | ||
*/ | ||
export function getGitHubAuthHeader(): Array<string> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found something arguably easier and more like the old ways here: https://stackoverflow.com/a/66156992/90297
So, maybe just do that to keep things simple and hopefully more compatible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. afaict both ways work with user tokens or app tokens -- fun fact the username does not matter for the clone-url approach just that it cannot be empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wowza, alright then let's go with the old way as it seems simpler? |
||
return [ | ||
'config', | ||
'--global', | ||
'http.extraheader', | ||
'AUTHORIZATION: bearer ' + getGitHubApiToken() | ||
]; | ||
} | ||
|
||
const _GitHubClientCache: Record<string, Octokit> = {}; | ||
|
||
/** | ||
|
@@ -123,21 +111,6 @@ | |
return _GitHubClientCache[githubApiToken]; | ||
} | ||
|
||
/** | ||
* Gets the currently authenticated GitHub user from the client | ||
* | ||
* @param github GitHub client | ||
* @returns GitHub username | ||
*/ | ||
export async function getAuthUsername(github: Octokit): Promise<string> { | ||
const userData = await github.users.getAuthenticated({}); | ||
const username = (userData.data || {}).login; | ||
if (!username) { | ||
throw new Error('Cannot reliably detect GitHub username, aborting'); | ||
} | ||
return username; | ||
} | ||
|
||
/** | ||
* Loads a file from the context's repository | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be able to remove these parameters entirely -- or maybe take the api key and do the header modification here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameters removed, but I'm not sure how to bake the token and header in there