leaf-githubauth

module
v0.0.0-...-3f43d96 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2025 License: MIT

README

Logo

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:

  1. Create a GitHub OAuth App at https://github.com/settings/developers
  2. Get your Client ID and Client Secret
  3. 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

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Directories

Path Synopsis
cmd
example command
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL