
A Go package that simplifies GitHub OAuth device flow authentication for CLI applications, similar to GitHub CLI.
Installation
go get github.com/terminalsin/leaf-githubauth
Prerequisites
Before using this package, you need to:
- Create a GitHub OAuth App at https://github.com/settings/developers
- Get your Client ID and Client Secret
- Set the following OAuth scopes for your application based on your needs:
repo - Full control of private repositories
read:org - Read organization information
- (Add other scopes as needed)
Usage
package main
import (
"context"
"fmt"
"log"
"github.com/terminalsin/leaf-githubauth/pkg/githoauth"
)
func main() {
config := githoauth.Config{
ClientID: "your_client_id",
ClientSecret: "your_client_secret",
Scopes: []string{"repo", "read:org"},
}
client := githoauth.NewClient(config)
ctx := context.Background()
token, err := client.Authenticate(ctx)
if err != nil {
log.Fatal(err)
}
// Use the token for GitHub API requests
httpClient := token.HTTPClient()
// Make API requests using httpClient...
}
Features
- Simple device flow authentication
- Automatic browser opening for authentication
- Token management
- Authenticated HTTP client creation
- Support for custom scopes
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature)
- Commit your changes (
git commit -m 'Add some amazing feature')
- Push to the branch (
git push origin feature/amazing-feature)
- Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.