package github
import "github.com/oslokommune/okctl/pkg/credentials/github"
Package github knows how to retrieve valid Github credentials
Index ¶
- Constants
- func AreValid(credentials *Credentials, client HTTPClient) error
- func RequiredScopes() []string
- func ReviewURL(clientID string) string
- type Auth
- func New(persister Persister, client HTTPClient, retriever Retriever, retrievers ...Retriever) *Auth
- func (a *Auth) Raw() (*Credentials, error)
- func (a *Auth) Resolve() (*Credentials, error)
- type AuthDeviceFlow
- func NewAuthDeviceFlow(clientID string, scopes []string) *AuthDeviceFlow
- func (a *AuthDeviceFlow) Invalidate()
- func (a *AuthDeviceFlow) Retrieve() (*Credentials, error)
- func (a *AuthDeviceFlow) Survey(verificationURI, userCode string) error
- func (a *AuthDeviceFlow) Valid() bool
- type AuthStatic
- func NewAuthStatic(creds *Credentials) *AuthStatic
- func (a *AuthStatic) Invalidate()
- func (a *AuthStatic) Retrieve() (*Credentials, error)
- func (a *AuthStatic) Valid() bool
- type Authenticator
- type Credentials
- type HTTPClient
- type InMemoryPersister
- func NewInMemoryPersister() *InMemoryPersister
- func (i *InMemoryPersister) Get() (*Credentials, error)
- func (i *InMemoryPersister) Save(credentials *Credentials) error
- type KeyGetter
- type KeyringCredentialsState
- type KeyringPersister
- func NewKeyringPersister(keyring keyring.Keyringer) *KeyringPersister
- func (k *KeyringPersister) Get() (*Credentials, error)
- func (k *KeyringPersister) Save(credentials *Credentials) error
- type Persister
- type Retriever
Constants ¶
const ( // CredentialsTypeDeviceFlow indicate that these are device flow credentials CredentialsTypeDeviceFlow = "device-flow" // CredentialsTypePersonalAccessToken indicate that these are personal access token CredentialsTypePersonalAccessToken = "personal-access-token" )
const DefaultDeviceCodeURL = "https://github.com/login/device/code"
DefaultDeviceCodeURL is the default URL for entering the device code URL
const DefaultGithubOauthClientID = "3e9b474f17b2bf31b07c"
DefaultGithubOauthClientID is the oauth application setup in the oslokommune org, this ID is considered a public identifier and is therefore safe to add verbatim
Functions ¶
func AreValid ¶
func AreValid(credentials *Credentials, client HTTPClient) error
AreValid checks to see if the credentials are still good
func RequiredScopes ¶
func RequiredScopes() []string
RequiredScopes returns the scopes required by okctl to perform its operations towards the Github API, see for all: - https://docs.github.com/en/developers/apps/scopes-for-oauth-apps
func ReviewURL ¶
ReviewURL returns the github review URL for the oauth permissions
Types ¶
type Auth ¶
type Auth struct { Retrievers []Retriever Persister Persister // contains filtered or unexported fields }
Auth orchestrates fetching and returning credentials to an end user
func New ¶
func New(persister Persister, client HTTPClient, retriever Retriever, retrievers ...Retriever) *Auth
New returns an initialised github authenticator
func (*Auth) Raw ¶
func (a *Auth) Raw() (*Credentials, error)
Raw returns the credentials as is
func (*Auth) Resolve ¶
func (a *Auth) Resolve() (*Credentials, error)
Resolve the available authenticators until we succeed
type AuthDeviceFlow ¶
type AuthDeviceFlow struct { ClientID string Credentials *Credentials DeviceEndpoint oauth2device.DeviceEndpoint IsValid bool ReviewURL string Scopes []string }
AuthDeviceFlow contains the state required for performing a device flow authentication towards github
func NewAuthDeviceFlow ¶
func NewAuthDeviceFlow(clientID string, scopes []string) *AuthDeviceFlow
NewAuthDeviceFlow returns an initialised authenticator that follows the device flow
func (*AuthDeviceFlow) Invalidate ¶
func (a *AuthDeviceFlow) Invalidate()
Invalidate the authorisation flow
func (*AuthDeviceFlow) Retrieve ¶
func (a *AuthDeviceFlow) Retrieve() (*Credentials, error)
Retrieve the credentials from github
func (*AuthDeviceFlow) Survey ¶
func (a *AuthDeviceFlow) Survey(verificationURI, userCode string) error
Survey queries the user to open the URL for entering the device code
func (*AuthDeviceFlow) Valid ¶
func (a *AuthDeviceFlow) Valid() bool
Valid returns true if the auth method is still valid
type AuthStatic ¶
type AuthStatic struct { Credentials *Credentials IsValid bool }
AuthStatic simply returns the provided credentials
func NewAuthStatic ¶
func NewAuthStatic(creds *Credentials) *AuthStatic
NewAuthStatic returns an initialised static authenticator
func (*AuthStatic) Invalidate ¶
func (a *AuthStatic) Invalidate()
Invalidate the stored credentials
func (*AuthStatic) Retrieve ¶
func (a *AuthStatic) Retrieve() (*Credentials, error)
Retrieve the stored credentials
func (*AuthStatic) Valid ¶
func (a *AuthStatic) Valid() bool
Valid returns true if the credentials are still valid
type Authenticator ¶
type Authenticator interface { Raw() (*Credentials, error) }
Authenticator provides the client interface for retrieving a set of valid Github credentials
type Credentials ¶
Credentials contains the credentials
type HTTPClient ¶
HTTPClient defines the http client interface
type InMemoryPersister ¶
type InMemoryPersister struct { Credentials *Credentials }
InMemoryPersister stores the credentials in memory
func NewInMemoryPersister ¶
func NewInMemoryPersister() *InMemoryPersister
NewInMemoryPersister returns an initialised in memory persister
func (*InMemoryPersister) Get ¶
func (i *InMemoryPersister) Get() (*Credentials, error)
Get the in memory credentials
func (*InMemoryPersister) Save ¶
func (i *InMemoryPersister) Save(credentials *Credentials) error
Save the credentials in memory
type KeyGetter ¶
KeyGetter defines an interface for retrieving string values based on a key
type KeyringCredentialsState ¶
type KeyringCredentialsState struct { AccessToken string `json:"access_token"` ClientID string `json:"client_id"` Type string `json:"type"` }
KeyringCredentialsState contains the state we store in the keyring
type KeyringPersister ¶
type KeyringPersister struct {
// contains filtered or unexported fields
}
KeyringPersister stores the access token in the user's keyring
func NewKeyringPersister ¶
func NewKeyringPersister(keyring keyring.Keyringer) *KeyringPersister
NewKeyringPersister returns an initialised keyring
func (*KeyringPersister) Get ¶
func (k *KeyringPersister) Get() (*Credentials, error)
Get the access token from the keyring
func (*KeyringPersister) Save ¶
func (k *KeyringPersister) Save(credentials *Credentials) error
Save the access token to the keyring
type Persister ¶
type Persister interface { Save(credentials *Credentials) error Get() (*Credentials, error) }
Persister defines the operations for storing and retrieving Github credentials
type Retriever ¶
type Retriever interface { Retrieve() (*Credentials, error) Invalidate() Valid() bool }
Retriever defines the operations required for the auth orchestrator
func NewAuthEnvironment ¶
NewAuthEnvironment creates a retriever that fetches credentials from environment variables
Source Files ¶
- Version
- v0.0.106 (latest)
- Published
- Oct 21, 2022
- Platform
- linux/amd64
- Imports
- 12 packages
- Last checked
- 18 hours ago –
Tools for package owners.