github

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyClientConfig = ClientConfig{}
	EmptyServerConfig = ServerConfig{}
)

Functions

func LoadAccessTokenFromFile

func LoadAccessTokenFromFile(filePath string) (*api.AccessToken, error)

func NewContextWithGitHubUserInfo

func NewContextWithGitHubUserInfo(ctx context.Context, userInfo *UserInfo) context.Context

func ResolveAccessToken

func ResolveAccessToken(c ClientConfig) (string, error)

func SaveAccessTokenToFile

func SaveAccessTokenToFile(accessToken *api.AccessToken, authFilePath string) error

Types

type Authenticator

type Authenticator struct {
	Config ServerConfig
	Client *github.Client
}

func NewGitHubAuthenticator

func NewGitHubAuthenticator(cfg ServerConfig) *Authenticator

func (*Authenticator) AuthenticateToken

func (a *Authenticator) AuthenticateToken(accessToken string) (*UserInfo, error)

type ClientConfig added in v0.37.0

type ClientConfig struct {
	CommonConfig                     `mapstructure:",squash"`
	AccessToken                      string `mapstructure:"access-token"`
	AccessTokenFile                  string `mapstructure:"access-token-file"`
	EnableAccessTokenFromEnvironment bool   `mapstructure:"enable-access-token-from-environment"`
}

func (ClientConfig) IsEmpty added in v0.37.0

func (c ClientConfig) IsEmpty() bool

type CommonConfig added in v0.37.0

type CommonConfig struct {
	AllowInsecureHTTP bool   `mapstructure:"allow-insecure-http"`
	ClientID          string `mapstructure:"client-id"`
	ClientSecret      string `mapstructure:"client-secret"`

	// ConfigFile containing ClientID and ClientSecret
	ConfigFile string `mapstructure:"config-file"`
}

only need ClientID for device flow

type GitHubClientAuth

type GitHubClientAuth struct {
	Config ClientConfig
	// contains filtered or unexported fields
}

func (GitHubClientAuth) AddAuth

func (a GitHubClientAuth) AddAuth(req *http.Request) error

type Handler added in v0.37.0

type Handler struct {
	Authenticator *Authenticator
}

func NewHandler added in v0.37.0

func NewHandler(cfg ServerConfig) *Handler

func (*Handler) AuthRequest added in v0.37.0

func (h *Handler) AuthRequest(r *http.Request) (stdctx.Context, error)

func (*Handler) Wrap added in v0.37.0

func (h *Handler) Wrap(handler http.Handler) http.Handler

type ServerConfig added in v0.37.0

type ServerConfig struct {
	CommonConfig `mapstructure:",squash"`

	PrincipalACLConfig authz.PrincipalACLConfig `mapstructure:"principals"`
}

func FromMap added in v0.37.0

func FromMap(m map[string]interface{}) ServerConfig

func (ServerConfig) IsEmpty added in v0.37.0

func (c ServerConfig) IsEmpty() bool

type TokenSource

type TokenSource struct {
	AccessToken string
}

func (*TokenSource) Token

func (t *TokenSource) Token() (*oauth2.Token, error)

type UserInfo

type UserInfo struct {
	Login                string
	Name                 string
	PrimaryEmail         string
	PrimaryEmailVerified bool
	Company              string
	WebSite              string
	Location             string
	PlanName             string
}

func FetchUserInfo

func FetchUserInfo(accessToken string) (*UserInfo, error)

func GitHubUserInfoFromContext

func GitHubUserInfoFromContext(ctx context.Context) *UserInfo

Jump to

Keyboard shortcuts

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