Skip to content

Commit

Permalink
Fix auth support for Github OAuth Access token Closes #431 (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthaI committed May 6, 2024
1 parent 41b3f5f commit 257960a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions github/utils.go
Expand Up @@ -75,8 +75,8 @@ func connect(ctx context.Context, d *plugin.QueryData) *github.Client {

// Return error for unsupported token by prefix
// https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-authentication-to-github#githubs-token-formats
if token != "" && !strings.HasPrefix(token, "ghs_") && !strings.HasPrefix(token, "ghp_") {
panic("Supported token formats are 'ghs_' and 'ghp_'")
if token != "" && !strings.HasPrefix(token, "ghs_") && !strings.HasPrefix(token, "ghp_") && !strings.HasPrefix(token, "gho_") {
panic("Supported token formats are 'ghs_', 'gho_', and 'ghp_'")
}

var client *github.Client
Expand All @@ -90,8 +90,8 @@ func connect(ctx context.Context, d *plugin.QueryData) *github.Client {
client = github.NewClient(tc)
}

// Authentication Using App Installation Access Token
if token != "" && strings.HasPrefix(token, "ghs_") {
// Authentication Using App Installation Access Token or OAuth Access token
if token != "" && (strings.HasPrefix(token, "ghs_") || strings.HasPrefix(token, "gho_")) {
client = github.NewClient(&http.Client{Transport: &oauth2Transport{
Token: token,
}})
Expand Down Expand Up @@ -191,14 +191,14 @@ func connectV4(ctx context.Context, d *plugin.QueryData) *githubv4.Client {

// Return error for unsupported token by prefix
// https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/about-authentication-to-github#githubs-token-formats
if token != "" && !strings.HasPrefix(token, "ghs_") && !strings.HasPrefix(token, "ghp_") {
panic("Supported token formats are 'ghs_' and 'ghp_'")
if token != "" && !strings.HasPrefix(token, "ghs_") && !strings.HasPrefix(token, "ghp_") && !strings.HasPrefix(token, "gho_") {
panic("Supported token formats are 'ghs_', 'gho_', and 'ghp_'")
}

var client *githubv4.Client

// Authentication Using App Installation Access Token
if token != "" && strings.HasPrefix(token, "ghs_") {
// Authentication Using App Installation Access Token or OAuth Access token
if token != "" && (strings.HasPrefix(token, "ghs_") || strings.HasPrefix(token, "gho_")) {
return githubv4.NewClient(&http.Client{Transport: &oauth2Transport{
Token: token,
}})
Expand Down

0 comments on commit 257960a

Please sign in to comment.