auth

package
v0.33.3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: GPL-3.0 Imports: 20 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticatedHttpClientFromContext

func AuthenticatedHttpClientFromContext(ctx context.Context) *mgcHttpPkg.Client

func NewContext

func NewContext(parentCtx context.Context, auth *Auth) context.Context

Types

type APIKeyParameters

type APIKeyParameters struct {
	Key string
}

type APIKeyParametersList

type APIKeyParametersList interface {
	GetAPIKey() string
}

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

func FromContext

func FromContext(ctx context.Context) *Auth

func New

func New(
	configMap map[string]Config, client *http.Client, profileManager *profile_manager.ProfileManager,
	mgcConfig *config.Config,
) *Auth

func (*Auth) AccessKeyPair

func (o *Auth) AccessKeyPair() (accessKeyId, secretAccessKey string)

func (*Auth) AccessToken

func (o *Auth) AccessToken(ctx context.Context) (string, error)

Returns the current user access token. If token is empty, we might still have refresh token, try getting a new one. It will either fail with error or return a valid non-empty access token

func (*Auth) ApiKey

func (o *Auth) ApiKey(ctx context.Context) (string, error)

func (*Auth) AuthenticatedHttpClientFromContext

func (a *Auth) AuthenticatedHttpClientFromContext(ctx context.Context) *mgcHttpPkg.Client

func (*Auth) BuiltInScopes

func (o *Auth) BuiltInScopes() core.Scopes

func (*Auth) CodeChallengeToURL

func (o *Auth) CodeChallengeToURL(scopes core.Scopes) (*url.URL, error)

func (*Auth) CurrentScopes

func (o *Auth) CurrentScopes() (core.Scopes, error)

func (*Auth) CurrentScopesString

func (o *Auth) CurrentScopesString() (core.ScopesString, error)

func (*Auth) CurrentSecurityMethod

func (o *Auth) CurrentSecurityMethod() string

func (*Auth) CurrentTenant

func (o *Auth) CurrentTenant(ctx context.Context) (*Tenant, error)

func (*Auth) CurrentTenantID

func (o *Auth) CurrentTenantID() (string, error)

func (*Auth) GetConfig

func (a *Auth) GetConfig() Config

func (*Auth) InitTokensFromFile

func (o *Auth) InitTokensFromFile()

func (*Auth) ListTenants

func (o *Auth) ListTenants(ctx context.Context) ([]*Tenant, error)

func (*Auth) Logout

func (o *Auth) Logout() error

func (*Auth) RedirectUri

func (o *Auth) RedirectUri() string

func (*Auth) RefreshAccessToken

func (o *Auth) RefreshAccessToken(ctx context.Context) (string, error)

func (*Auth) RequestAuthTokenWithAuthorizationCode

func (o *Auth) RequestAuthTokenWithAuthorizationCode(ctx context.Context, authCode string) error

* Creates a new request access token from authorization code request, be

  • mindful that the code verifier used in this request come from the last call
  • of `CodeChallengeToUrl` method.

func (*Auth) SelectTenant

func (o *Auth) SelectTenant(ctx context.Context, id string, scopes core.ScopesString) (
	*TokenExchangeResult, error,
)

func (*Auth) SetAPIKey

func (o *Auth) SetAPIKey(apiKey string) error

func (*Auth) SetAccessKey

func (o *Auth) SetAccessKey(id string, key string) error

func (*Auth) SetScopes

func (o *Auth) SetScopes(ctx context.Context, scopes core.Scopes) (*TokenExchangeResult, error)

func (*Auth) SetTokens

func (o *Auth) SetTokens(token *LoginResult) error

func (*Auth) SetXTenantID

func (o *Auth) SetXTenantID(tenantId string) error

func (*Auth) TenantsListUrl

func (o *Auth) TenantsListUrl() string

func (*Auth) TokenExchangeUrl

func (o *Auth) TokenExchangeUrl() string

func (*Auth) UnsetAccessKey

func (o *Auth) UnsetAccessKey() error

func (*Auth) ValidateAccessToken

func (o *Auth) ValidateAccessToken(ctx context.Context) error

func (*Auth) XTenantID

func (o *Auth) XTenantID(ctx context.Context) (string, error)

type Authenticator

type Authenticator interface {
	AccessToken(ctx context.Context) (string, error)
	SetTokens(token *LoginResult) error
	RefreshAccessToken(ctx context.Context) (string, error)
	ValidateAccessToken(ctx context.Context) error
	CodeChallengeToURL(scopes core.Scopes) (*url.URL, error)
	RequestAuthTokenWithAuthorizationCode(ctx context.Context, authCode string) error
	ListTenants(ctx context.Context) ([]*Tenant, error)
	SelectTenant(ctx context.Context, id string, scopes core.ScopesString) (*TokenExchangeResult, error)
	CurrentTenant(ctx context.Context) (*Tenant, error)
	CurrentTenantID() (string, error)
	SetScopes(ctx context.Context, scopes core.Scopes) (*TokenExchangeResult, error)
	CurrentScopes() (core.Scopes, error)
	CurrentScopesString() (core.ScopesString, error)
	ApiKey(ctx context.Context) (string, error)
	SetAPIKey(apiKey string) error
	AccessKeyPair() (accessKeyId, secretAccessKey string)
	SetAccessKey(id string, key string) error
	UnsetAccessKey() error
	XTenantID(ctx context.Context) (string, error)
	SetXTenantID(tenantId string) error
	Logout() error
	GetConfig() Config
	CurrentSecurityMethod() string
}

type Config

type Config struct {
	ClientId              string
	ObjectStoreScopeIDs   []string
	PublicClientsScopeIDs map[string]string
	RedirectUri           string
	LoginUrl              string
	TokenUrl              string
	ValidationUrl         string
	RefreshUrl            string
	TenantsListUrl        string
	TokenExchangeUrl      string
	ApiKeysUrlV1          string
	ApiKeysUrlV2          string
	PublicClientsUrl      string
	ClientsV2Url          string
}

type ConfigResult

type ConfigResult struct {
	AccessToken     string `json:"access_token"`
	RefreshToken    string `json:"refresh_token"`
	AccessKeyId     string `json:"access_key_id"`
	SecretAccessKey string `json:"secret_access_key"`
	CurrentEnv      string `json:"current_environment"`
}

type FailedRefreshAccessToken

type FailedRefreshAccessToken struct {
	Message string
}

func (FailedRefreshAccessToken) Error

func (e FailedRefreshAccessToken) Error() string

type LoginResult

type LoginResult struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type SecurityMethod

type SecurityMethod int
const (
	BearerToken SecurityMethod = iota
	APIKey
	XTenantID
)

func (SecurityMethod) String

func (s SecurityMethod) String() string

type Tenant

type Tenant struct {
	UUID        string `json:"uuid"`
	Name        string `json:"legal_name"`
	Email       string `json:"email"`
	IsManaged   bool   `json:"is_managed"`
	IsDelegated bool   `json:"is_delegated"`
}

type TokenExchangeResult

type TokenExchangeResult struct {
	TenantID     string    `json:"uuid"`
	CreatedAt    core.Time `json:"created_at"`
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	Scope        []string  `json:"scope"`
}

type XTenantIDParameters

type XTenantIDParameters struct {
	Key string
}

type XTenantIDParametersList

type XTenantIDParametersList interface {
	GetXTenantID() string
}

Jump to

Keyboard shortcuts

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