-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support GitHub Apps Installation authentication (#69)
* Initial commit of github apps poc * Demo of GitHub Apps auth working in go-sdk * Remove unnecessary auth configuration functions * Docs comments cleanup * Differentiate App and token auth examples * Switch to using fork of ghinstallation * Bump to latest ghinstallation fork version * Allow authorizing with clientID * Refactor naming to default to clientID for App auth * Bump kfcampbell/ghinstallation version * Rename WithAuthorizationToken to WithTokenAuthentication * Add README note about different types of App auth * Simplify token initialization client * Another ghinstallation version bump * Use env vars for App auth example * Test coverage for Apps auth * Update pkg/client.go Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com> * Fix build error from code suggestion --------- Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com>
- Loading branch information
1 parent
be07f65
commit 3d777e7
Showing
11 changed files
with
322 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
abs "github.com/microsoft/kiota-abstractions-go" | ||
"github.com/octokit/go-sdk/pkg" | ||
"github.com/octokit/go-sdk/pkg/github/installation" | ||
) | ||
|
||
func main() { | ||
installationID, err := strconv.ParseInt(os.Getenv("INSTALLATION_ID"), 10, 64) | ||
if err != nil { | ||
log.Fatalf("error parsing installation ID from string to int64: %v", err) | ||
} | ||
|
||
client, err := pkg.NewApiClient( | ||
pkg.WithUserAgent("my-user-agent"), | ||
pkg.WithRequestTimeout(5*time.Second), | ||
pkg.WithBaseUrl("https://api.github.com"), | ||
pkg.WithGitHubAppAuthentication(os.Getenv("PATH_TO_PEM_FILE"), os.Getenv("CLIENT_ID"), installationID), | ||
) | ||
|
||
// equally valid: | ||
//client, err := pkg.NewApiClient() | ||
if err != nil { | ||
log.Fatalf("error creating client: %v", err) | ||
} | ||
|
||
queryParams := &installation.RepositoriesRequestBuilderGetQueryParameters{} | ||
requestConfig := &abs.RequestConfiguration[installation.RepositoriesRequestBuilderGetQueryParameters]{ | ||
QueryParameters: queryParams, | ||
} | ||
repos, err := client.Installation().Repositories().Get(context.Background(), requestConfig) | ||
if err != nil { | ||
log.Fatalf("error getting repositories: %v", err) | ||
} | ||
|
||
if len(repos.GetRepositories()) > 0 { | ||
log.Printf("Repositories:\n") | ||
for _, repo := range repos.GetRepositories() { | ||
log.Printf("%v\n", *repo.GetFullName()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.