credentials

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: MIT Imports: 18 Imported by: 0

README

OAuth2More Credentials

oauth2more/credentials is a package to manage generic OAuth 2.0 credentials definitions.

The primary use case is to have a single JSON definition of multiple applications for multiple services which can be used to generate token and API requests.

Both OAuth 2.0 and JWT are supported.

It works with oauth2more/endpoints to add endpoints for known services.

Documentation

Index

Constants

View Source
const (
	TypeOAuth2 = "oauth2"
	TypeJWT    = "jwt"
)
View Source
const (
	GrantTypeAuthCode          = "authorization_code"
	GrantTypePassword          = "password"
	GrantTypeClientCredentials = "client_credentials"
	GrantTypeRefreshToken      = "refresh_token"
)
View Source
const (
	SigningMethodES256 = "ES256"
	SigningMethodES384 = "ES384"
	SigningMethodES512 = "ES512"
	SigningMethodHS256 = "HS256"
	SigningMethodHS384 = "HS384"
	SigningMethodHS512 = "HS512"
)

Variables

This section is empty.

Functions

func NewTokenCli

func NewTokenCli(creds Credentials, state string) (token *oauth2.Token, err error)

Types

type ApplicationCredentials

type ApplicationCredentials struct {
	ServerURL       string          `json:"serverURL,omitempty"`
	ApplicationID   string          `json:"applicationID,omitempty"`
	ClientID        string          `json:"clientID,omitempty"`
	ClientSecret    string          `json:"clientSecret,omitempty"`
	OAuth2Endpoint  oauth2.Endpoint `json:"oauth2Endpoint,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"`
	Scopes          []string        `json:"scopes,omitempty"`
}

ApplicationCredentials supports OAuth 2.0 authorization_code, password, and client_credentials grant flows.

func (*ApplicationCredentials) AppNameAndVersion

func (ac *ApplicationCredentials) AppNameAndVersion() string

func (*ApplicationCredentials) AuthCodeURL

func (app *ApplicationCredentials) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string

func (*ApplicationCredentials) Config

func (app *ApplicationCredentials) Config() oauth2.Config

func (*ApplicationCredentials) Exchange

func (app *ApplicationCredentials) Exchange(code string) (*oauth2.Token, error)

func (*ApplicationCredentials) InflateURL

func (app *ApplicationCredentials) InflateURL(apiUrlPath string) string

func (*ApplicationCredentials) IsGrantType

func (app *ApplicationCredentials) IsGrantType(grantType string) bool

func (*ApplicationCredentials) NewClient added in v0.8.1

func (app *ApplicationCredentials) NewClient(ctx context.Context) (*http.Client, error)

NewClient returns a `*http.Client` for applications using `client_credentials` grant. The client can be modified using context, e.g. ignoring bad certs or otherwise.

type Credentials

type Credentials struct {
	Service             string                 `json:"service,omitempty"`
	Type                string                 `json:"type,omitempty"`
	Subdomain           string                 `json:"subdomain,omitempty"`
	Application         ApplicationCredentials `json:"application,omitempty"`
	PasswordCredentials PasswordCredentials    `json:"passwordCredentials,omitempty"`
	JWT                 JWTCredentials         `json:"jwt,omitempty"`
	Token               *oauth2.Token          `json:"token,omitempty"`
}

func NewCredentialsJSON added in v0.6.2

func NewCredentialsJSON(data []byte) (Credentials, error)

func NewCredentialsJSONs

func NewCredentialsJSONs(appJson, userJson, accessToken []byte) (Credentials, error)

func ReadCredentialsFromFile

func ReadCredentialsFromFile(credentialsSetFilename, accountKey string, inclAccountsOnError bool) (Credentials, error)

func (*Credentials) Inflate added in v0.6.0

func (creds *Credentials) Inflate() error

func (*Credentials) NewClient

func (creds *Credentials) NewClient(ctx context.Context) (*http.Client, error)

func (*Credentials) NewClientCli

func (creds *Credentials) NewClientCli(oauth2State string) (*http.Client, error)

func (*Credentials) NewSimpleClient

func (creds *Credentials) NewSimpleClient(httpClient *http.Client) (*httpsimple.SimpleClient, error)

func (*Credentials) NewToken

func (creds *Credentials) NewToken() (*oauth2.Token, 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 CredentialsSet

type CredentialsSet struct {
	Credentials map[string]Credentials
}

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) GetClient

func (set *CredentialsSet) GetClient(ctx context.Context, key string) (*http.Client, error)

func (*CredentialsSet) Inflate added in v0.6.0

func (set *CredentialsSet) Inflate()

func (*CredentialsSet) Keys

func (set *CredentialsSet) Keys() []string

type JWTCredentials added in v0.8.0

type JWTCredentials struct {
	Issuer        string `json:"issuer,omitempty"`
	PrivateKey    string `json:"privateKey,omitempty"`
	SigningMethod string `json:"signingMethod,omitempty"`
}

func (*JWTCredentials) StandardToken added in v0.8.0

func (jc *JWTCredentials) StandardToken(tokenDuration time.Duration) (*jwt.Token, string, error)

type Options added in v0.7.1

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.

func (*Options) UseCLI added in v0.7.2

func (opts *Options) UseCLI() bool

type PasswordCredentials

type PasswordCredentials struct {
	GrantType            string `url:"grant_type"`
	AccessTokenTTL       int64  `url:"access_token_ttl"`
	RefreshTokenTTL      int64  `url:"refresh_token_ttl"`
	Username             string `json:"username" url:"username"`
	Extension            string `json:"extension" url:"extension"`
	Password             string `json:"password" url:"password"`
	EndpointId           string `url:"endpoint_id"`
	EngageVoiceAccountId int64  `json:"engageVoiceAccountId"`
}

func (*PasswordCredentials) URLValues

func (pw *PasswordCredentials) URLValues() url.Values

func (*PasswordCredentials) UsernameSimple

func (uc *PasswordCredentials) UsernameSimple() string

Jump to

Keyboard shortcuts

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