credentialsset

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package credentialsset creates GitHub clients from a goauth credentials set file, using an OAuth app instead of a personal access token.

A token issued to an OAuth app is accepted by organizations that forbid personal access tokens, provided the organization allows the OAuth app.

It lives in its own package so that importing gogithub/auth does not pull in goauth and its dependencies.

Index

Constants

View Source
const RedirectURL = "https://grokify.github.io/goauth/oauth2callback/"

RedirectURL is a hosted redirect page that displays the authorization code and state, for applications that cannot receive a redirect themselves. Register it as the OAuth app's authorization callback URL to use it.

Variables

View Source
var ErrNoAuthCode = errors.New("no authorization code provided")

ErrNoAuthCode indicates the prompt returned an empty authorization code.

View Source
var ErrNotOAuth2 = errors.New("credentials are not oauth2 credentials")

ErrNotOAuth2 indicates the account's credentials are not OAuth 2.0 credentials.

Functions

func NewClient

func NewClient(ctx context.Context, filename, account string, prompt AuthCodePrompt) (clientv1.Client, error)

NewClient creates a GitHub client for an account in a goauth credentials set file. See NewToken for how the token is obtained.

func NewToken

func NewToken(ctx context.Context, filename, account string, prompt AuthCodePrompt) (*oauth2.Token, error)

NewToken returns an OAuth token for an account in a goauth credentials set file.

A valid token stored with the account is returned as is. Otherwise, for the authorization code grant, prompt is called with the authorization URL and the code it returns is exchanged for a token. The token is not written back to the file.

Types

type AuthCodePrompt

type AuthCodePrompt func(ctx context.Context, authURL, state string) (code string, err error)

AuthCodePrompt asks the user to authorize the application at authURL and returns the authorization code shown on the redirect page. The state on the redirect page should match state.

func PromptReadWriter

func PromptReadWriter(w io.Writer, r io.Reader) AuthCodePrompt

PromptReadWriter returns an AuthCodePrompt that writes instructions to w and reads the authorization code from r. Pass os.Stderr as w to keep instructions out of a command's standard output.

Jump to

Keyboard shortcuts

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