Documentation ¶
Index ¶
- Constants
- Variables
- func NewTokenCLI(creds Credentials, state string) (token *oauth2.Token, err error)
- type AuthCodeOptions
- type Credentials
- func (creds *Credentials) Inflate() error
- func (creds *Credentials) NewClient(ctx context.Context) (*http.Client, error)
- func (creds *Credentials) NewClientCLI(oauth2State string) (*http.Client, error)
- func (creds *Credentials) NewSimpleClient(ctx context.Context) (*httpsimple.SimpleClient, error)
- func (creds *Credentials) NewSimpleClientHTTP(httpClient *http.Client) (*httpsimple.SimpleClient, error)
- func (creds *Credentials) NewToken() (*oauth2.Token, error)
- func (creds *Credentials) NewTokenCLI(oauth2State string) (*oauth2.Token, error)
- type CredentialsBasicAuth
- type CredentialsHeaderQuery
- type CredentialsJWT
- type CredentialsOAuth2
- func (oc *CredentialsOAuth2) AppNameAndVersion() string
- func (oc *CredentialsOAuth2) AuthCodeURL(state string, opts map[string][]string) string
- func (oc *CredentialsOAuth2) BasicAuthHeader() (string, error)
- func (oc *CredentialsOAuth2) Config() oauth2.Config
- func (oc *CredentialsOAuth2) ConfigClientCredentials() clientcredentials.Config
- func (oc *CredentialsOAuth2) Exchange(ctx context.Context, code string, opts map[string][]string) (*oauth2.Token, error)
- func (oc *CredentialsOAuth2) InflateURL(apiURLPath string) string
- func (oc *CredentialsOAuth2) IsGrantType(grantType string) bool
- func (oc *CredentialsOAuth2) MarshalJSON(prefix, indent string) ([]byte, error)
- func (oc *CredentialsOAuth2) NewClient(ctx context.Context) (*http.Client, *oauth2.Token, error)
- func (oc *CredentialsOAuth2) NewToken(ctx context.Context) (*oauth2.Token, error)
- func (oc *CredentialsOAuth2) PasswordRequestBody() url.Values
- func (oc *CredentialsOAuth2) RefreshToken(tok *oauth2.Token) (*oauth2.Token, []byte, error)
- func (oc *CredentialsOAuth2) RefreshTokenSimple(refreshToken string) (*oauth2.Token, []byte, error)
- type CredentialsSet
- func (set *CredentialsSet) Accounts() []string
- func (set CredentialsSet) Get(key string) (Credentials, error)
- func (set *CredentialsSet) GetClient(ctx context.Context, key string) (*http.Client, error)
- func (set *CredentialsSet) Inflate() error
- func (set *CredentialsSet) Keys() []string
- func (set *CredentialsSet) WriteFile(filename, prefix, indent string, perm fs.FileMode) error
- type Options
Constants ¶
const ( TypeBasic = "basic" TypeHeaderQuery = "headerquery" TypeOAuth2 = "oauth2" TypeJWT = "jwt" )
const ( SigningMethodES256 = "ES256" SigningMethodES384 = "ES384" SigningMethodES512 = "ES512" SigningMethodHS256 = "HS256" SigningMethodHS384 = "HS384" SigningMethodHS512 = "HS512" )
Variables ¶
var ( ErrJWTNotSupported = errors.New("jwt is not supported for function") ErrBasicAuthNotPopulated = errors.New("basic auth is not populated") ErrJWTNotPopulated = errors.New("jwt is not populated") ErrOAuth2NotPopulated = errors.New("oauth2 is not populated") ErrTypeNotSupported = errors.New("credentials type not supported") )
Functions ¶
func NewTokenCLI ¶
func NewTokenCLI(creds Credentials, state string) (token *oauth2.Token, err error)
Types ¶
type AuthCodeOptions ¶
type AuthCodeOptions []oauth2.AuthCodeOption
func (*AuthCodeOptions) Add ¶
func (opts *AuthCodeOptions) Add(k, v string)
func (*AuthCodeOptions) AddMap ¶
func (opts *AuthCodeOptions) AddMap(m map[string][]string)
type Credentials ¶
type Credentials struct { Service string `json:"service,omitempty"` Type string `json:"type,omitempty"` Subdomain string `json:"subdomain,omitempty"` Basic CredentialsBasicAuth `json:"basic,omitempty"` OAuth2 CredentialsOAuth2 `json:"oauth2,omitempty"` JWT CredentialsJWT `json:"jwt,omitempty"` Token *oauth2.Token `json:"token,omitempty"` HeaderQuery CredentialsHeaderQuery `json:"headerquery,omitempty"` Additional url.Values `json:"additional,omitempty"` }
func NewCredentialsJSON ¶
func NewCredentialsJSON(credsData, accessToken []byte) (Credentials, error)
func ReadCredentialsFromFile ¶
func ReadCredentialsFromFile(credentialsSetFilename, accountKey string, inclAccountsOnError bool) (Credentials, error)
func (*Credentials) Inflate ¶
func (creds *Credentials) Inflate() error
func (*Credentials) NewClientCLI ¶
func (creds *Credentials) NewClientCLI(oauth2State string) (*http.Client, error)
func (*Credentials) NewSimpleClient ¶
func (creds *Credentials) NewSimpleClient(ctx context.Context) (*httpsimple.SimpleClient, error)
func (*Credentials) NewSimpleClientHTTP ¶
func (creds *Credentials) NewSimpleClientHTTP(httpClient *http.Client) (*httpsimple.SimpleClient, error)
func (*Credentials) NewTokenCLI ¶
func (creds *Credentials) NewTokenCLI(oauth2State string) (*oauth2.Token, error)
NewTokenCLI retrieves a token using CLI approach for OAuth 2.0 authorization code or password grant.
type CredentialsBasicAuth ¶
type CredentialsBasicAuth struct { Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` Encoded string `json:"encoded,omitempty"` ServerURL string `json:"serverURL,omitempty"` AllowInsecure bool `json:"allowInsecure,omitempty"` Metadata map[string]string `json:"metadata,omitempty"` }
func (*CredentialsBasicAuth) NewClient ¶
func (c *CredentialsBasicAuth) NewClient() (*http.Client, error)
func (*CredentialsBasicAuth) NewSimpleClient ¶
func (c *CredentialsBasicAuth) NewSimpleClient() (httpsimple.SimpleClient, error)
type CredentialsHeaderQuery ¶
type CredentialsHeaderQuery struct { ServerURL string `json:"serverURL,omitempty"` Header http.Header `json:"header,omitempty"` Query url.Values `json:"query,omitempty"` AllowInsecure bool `json:"allowInsecure,omitempty"` }
func (*CredentialsHeaderQuery) NewClient ¶
func (c *CredentialsHeaderQuery) NewClient() *http.Client
func (*CredentialsHeaderQuery) NewSimpleClient ¶
func (c *CredentialsHeaderQuery) NewSimpleClient() httpsimple.SimpleClient
type CredentialsJWT ¶
type CredentialsJWT struct { Issuer string `json:"issuer,omitempty"` PrivateKey string `json:"privateKey,omitempty"` SigningMethod string `json:"signingMethod,omitempty"` }
func (*CredentialsJWT) StandardToken ¶
type CredentialsOAuth2 ¶
type CredentialsOAuth2 struct { ServerURL string `json:"serverURL,omitempty"` ApplicationID string `json:"applicationID,omitempty"` ClientID string `json:"clientID,omitempty"` ClientSecret string `json:"clientSecret,omitempty"` Endpoint oauth2.Endpoint `json:"endpoint,omitempty"` RedirectURL string `json:"redirectURL,omitempty"` AppName string `json:"applicationName,omitempty"` AppVersion string `json:"applicationVersion,omitempty"` OAuthEndpointID string `json:"oauthEndpointID,omitempty"` AccessTokenTTL int64 `json:"accessTokenTTL,omitempty"` RefreshTokenTTL int64 `json:"refreshTokenTTL,omitempty"` GrantType string `json:"grantType,omitempty"` PKCE bool `json:"pkce"` Username string `json:"username,omitempty"` Password string `json:"password,omitempty"` JWT string `json:"jwt,omitempty"` Token *oauth2.Token `json:"token,omitempty"` Scopes []string `json:"scopes,omitempty"` AuthCodeOpts map[string][]string `json:"authCodeOpts,omitempty"` AuthCodeExchangeOpts map[string][]string `json:"authCodeExchangeOpts,omitempty"` PasswordOpts map[string][]string `json:"passwordOpts,omitempty"` Metadata map[string]string `json:"metadata,omitempty"` }
CredentialsOAuth2 supports OAuth 2.0 authorization_code, password, and client_credentials grant flows.
func NewCredentialsOAuth2Env ¶
func NewCredentialsOAuth2Env(envPrefix string) CredentialsOAuth2
func ParseCredentialsOAuth2 ¶
func ParseCredentialsOAuth2(b []byte) (CredentialsOAuth2, error)
func (*CredentialsOAuth2) AppNameAndVersion ¶
func (oc *CredentialsOAuth2) AppNameAndVersion() string
func (*CredentialsOAuth2) AuthCodeURL ¶
func (oc *CredentialsOAuth2) AuthCodeURL(state string, opts map[string][]string) string
func (*CredentialsOAuth2) BasicAuthHeader ¶
func (oc *CredentialsOAuth2) BasicAuthHeader() (string, error)
func (*CredentialsOAuth2) Config ¶
func (oc *CredentialsOAuth2) Config() oauth2.Config
func (*CredentialsOAuth2) ConfigClientCredentials ¶
func (oc *CredentialsOAuth2) ConfigClientCredentials() clientcredentials.Config
func (*CredentialsOAuth2) InflateURL ¶
func (oc *CredentialsOAuth2) InflateURL(apiURLPath string) string
func (*CredentialsOAuth2) IsGrantType ¶
func (oc *CredentialsOAuth2) IsGrantType(grantType string) bool
func (*CredentialsOAuth2) MarshalJSON ¶
func (oc *CredentialsOAuth2) MarshalJSON(prefix, indent string) ([]byte, error)
MarshalJSON returns JSON. It is useful for exporting creating configs to be parsed.
func (*CredentialsOAuth2) NewToken ¶
NewToken retrieves an `*oauth2.Token` when the requisite information is available. Note this uses `clientcredentials.Config.Token()` which doesn't always work. In This situation, use `authutil.TokenClientCredentials()` as an alternative. Note: authorization code is only supported for CLI testing purposes. In a production application, it should be done in a multi-step process to redirect the user to the authorization URL, retrieve the auth code and then `Exchange` it for a token. The `state` value is currently a randomly generated string as this should be used for testing purposes only.
func (*CredentialsOAuth2) PasswordRequestBody ¶
func (oc *CredentialsOAuth2) PasswordRequestBody() url.Values
func (*CredentialsOAuth2) RefreshToken ¶
func (*CredentialsOAuth2) RefreshTokenSimple ¶
type CredentialsSet ¶
type CredentialsSet struct {
Credentials map[string]Credentials `json:"credentials,omitempty"`
}
func ReadFileCredentialsSet ¶
func ReadFileCredentialsSet(credentialsSetFilename string, inflateEndpoints bool) (CredentialsSet, error)
func (*CredentialsSet) Accounts ¶
func (set *CredentialsSet) Accounts() []string
func (CredentialsSet) Get ¶
func (set CredentialsSet) Get(key string) (Credentials, error)
func (*CredentialsSet) Inflate ¶
func (set *CredentialsSet) Inflate() error
func (*CredentialsSet) Keys ¶
func (set *CredentialsSet) Keys() []string
type Options ¶
type Options struct { CredsPath string `long:"creds" description:"Environment File Path" required:"true"` Account string `long:"account" description:"Environment Variable Name"` Token string `long:"token" description:"Token"` CLI []bool `long:"cli" description:"CLI"` }
Options is a struct to be used with `github.com/jessevdk/go-flags`. It can be embedded in another struct.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
auth0 contains a Go implementation of Auth0's PKCE support: https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce
|
auth0 contains a Go implementation of Auth0's PKCE support: https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce |
cmd
|
|
examples
|
|
examples/send_ics
This package posts an ICS file to Gmail.
|
This package posts an ICS file to Gmail. |
util
|
|