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 ¶
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 ¶
var ErrNoAuthCode = errors.New("no authorization code provided")
ErrNoAuthCode indicates the prompt returned an empty authorization code.
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 ¶
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.