scheme

package
v0.12.5 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 44 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrOAuth2MissingStateOrCode = errors.New("oauth2: callback missing state or code")
	ErrOAuth2InvalidState       = errors.New("oauth2: invalid state")
	ErrOAuth2Exchange           = errors.New("oauth2: exchange failed, unable to get token")
	ErrOAuth2TokenIsValid       = errors.New("oauth2: token is vaild")
)

OAuth2 Errors

Functions

This section is empty.

Types

type BaseAuth

type BaseAuth struct {
	// Name contains name of the auth scheme.
	// For e.g.: form, basic, oauth2, generic
	Name string

	// KeyName value is auth scheme configuration KeyName.
	// For e.g: `security.auth_schemes.<keyname>`.
	KeyName string

	// KeyPrefix value is composed auth scheme configuration key.
	//
	// 	For e.g.: KeyName is 'form_auth', then KeyPrefix is
	// 		  security.auth_schemes.form_auth
	KeyPrefix string

	// AppConfig value is application configuration, its suppiled via function `Init`.
	AppConfig *config.Config
	// contains filtered or unexported fields
}

BaseAuth struct hold base implementation of aah framework's authentication schemes.

func (*BaseAuth) ConfigError

func (b *BaseAuth) ConfigError(keySuffix string) error

ConfigError method creates config `error` instance for errors in the auth scheme configuration.

func (*BaseAuth) ConfigKey

func (b *BaseAuth) ConfigKey(suffix string) string

ConfigKey method returns fully qualified config key name with given suffix key for auth scheme.

func (*BaseAuth) DoAuthenticate

func (b *BaseAuth) DoAuthenticate(authcToken *authc.AuthenticationToken) (*authc.AuthenticationInfo, error)

DoAuthenticate method calls the registered `Authenticator` with authentication token.

func (*BaseAuth) DoAuthorizationInfo

func (b *BaseAuth) DoAuthorizationInfo(authcInfo *authc.AuthenticationInfo) *authz.AuthorizationInfo

DoAuthorizationInfo method calls registered `Authorizer` with authentication information.

func (*BaseAuth) ExtractAuthenticationToken

func (b *BaseAuth) ExtractAuthenticationToken(r *ahttp.Request) *authc.AuthenticationToken

ExtractAuthenticationToken method typically implementated by extending struct.

func (*BaseAuth) Init

func (b *BaseAuth) Init(appCfg *config.Config, keyName string) error

Init method typically implemented by extending struct.

func (*BaseAuth) Key

func (b *BaseAuth) Key() string

Key method returns auth scheme configuration KeyName. For e.g: `security.auth_schemes.<keyname>`.

func (*BaseAuth) Scheme

func (b *BaseAuth) Scheme() string

Scheme method return authentication scheme name.

func (*BaseAuth) SetAuthenticator

func (b *BaseAuth) SetAuthenticator(authenticator authc.Authenticator) error

SetAuthenticator method assigns the given `Authenticator` instance to auth scheme.

func (*BaseAuth) SetAuthorizer

func (b *BaseAuth) SetAuthorizer(authorizer authz.Authorizer) error

SetAuthorizer method assigns the given `Authorizer` instance to auth scheme.

func (*BaseAuth) SetPrincipalProvider

func (b *BaseAuth) SetPrincipalProvider(principal authc.PrincipalProvider) error

SetPrincipalProvider method assigns the given `PrincipalProvider` instance to auth scheme.

type BasicAuth

type BasicAuth struct {
	BaseAuth
	RealmName string
	// contains filtered or unexported fields
}

BasicAuth struct provides aah's OOTB Basic Auth scheme.

func (*BasicAuth) DoAuthenticate

func (b *BasicAuth) DoAuthenticate(authcToken *authc.AuthenticationToken) (*authc.AuthenticationInfo, error)

DoAuthenticate method calls the registered `Authenticator` with authentication token.

func (*BasicAuth) DoAuthorizationInfo

func (b *BasicAuth) DoAuthorizationInfo(authcInfo *authc.AuthenticationInfo) *authz.AuthorizationInfo

DoAuthorizationInfo method calls registered `Authorizer` with authentication information.

func (*BasicAuth) ExtractAuthenticationToken

func (b *BasicAuth) ExtractAuthenticationToken(r *ahttp.Request) *authc.AuthenticationToken

ExtractAuthenticationToken method extracts the authentication token information from the HTTP request.

func (*BasicAuth) Init

func (b *BasicAuth) Init(cfg *config.Config, keyName string) error

Init method initializes the Basic authentication scheme from `security.auth_schemes`.

type FormAuth

type FormAuth struct {
	BaseAuth
	IsAlwaysToDefaultTarget bool
	LoginURL                string
	LoginSubmitURL          string
	LoginFailureURL         string
	DefaultTargetURL        string
	FieldIdentity           string
	FieldCredential         string
}

FormAuth struct provides aah's OOTB Form Auth scheme.

func (*FormAuth) DoAuthenticate

func (f *FormAuth) DoAuthenticate(authcToken *authc.AuthenticationToken) (*authc.AuthenticationInfo, error)

DoAuthenticate method calls the registered `Authenticator` with authentication token.

func (*FormAuth) ExtractAuthenticationToken

func (f *FormAuth) ExtractAuthenticationToken(r *ahttp.Request) *authc.AuthenticationToken

ExtractAuthenticationToken method extracts the authentication token information from the HTTP request.

func (*FormAuth) Init

func (f *FormAuth) Init(cfg *config.Config, keyName string) error

Init method initializes the Form Auth scheme from `security.auth_schemes`.

type GenericAuth

type GenericAuth struct {
	BaseAuth
	IdentityHeader   string
	CredentialHeader string
}

GenericAuth struct provides generic Auth Scheme for all custom scenario's.

func (*GenericAuth) ExtractAuthenticationToken

func (g *GenericAuth) ExtractAuthenticationToken(r *ahttp.Request) *authc.AuthenticationToken

ExtractAuthenticationToken method extracts an authentication token information from the HTTP request.

func (*GenericAuth) Init

func (g *GenericAuth) Init(cfg *config.Config, keyName string) error

Init method initializes the Generic authentication scheme from `security.auth_schemes`.

type OAuth2

type OAuth2 struct {
	BaseAuth
	LoginURL    string
	RedirectURL string
	SuccessURL  string
	// contains filtered or unexported fields
}

OAuth2 auth scheme implementation for the aah framework.

func (*OAuth2) Client

func (o *OAuth2) Client(token *oauth2.Token) *http.Client

Client method returns Go HTTP client configured with given OAuth2 Token.

func (*OAuth2) Config

func (o *OAuth2) Config() *oauth2.Config

Config method returns OAuth2 config instance.

func (*OAuth2) Init

func (o *OAuth2) Init(appCfg *config.Config, keyName string) error

Init method initialize the OAuth2 auth scheme during an application start.

func (*OAuth2) Principal

func (o *OAuth2) Principal(keyName string, v ess.Valuer) ([]*authc.Principal, error)

Principal method calls the registered interface `SubjectPrincipalProvider` to obtain Subject principals.

func (*OAuth2) ProviderAuthURL

func (o *OAuth2) ProviderAuthURL(r *ahttp.Request) (string, string)

ProviderAuthURL method returns aah generated state value and OAuth2 login URL.

func (*OAuth2) RefreshAccessToken

func (o *OAuth2) RefreshAccessToken(token *oauth2.Token) (*oauth2.Token, error)

RefreshAccessToken method returns new OAuth2 token if given token was expried otherwise returns error `scheme.ErrOAuth2TokenIsValid`.

func (*OAuth2) ValidateCallback

func (o *OAuth2) ValidateCallback(state string, r *ahttp.Request) (*oauth2.Token, error)

ValidateCallback method validates the incoming OAuth2 provider redirect request and gets Access token from OAuth2 provider.

type Schemer

type Schemer interface {
	// Init method gets called by aah during an application start.
	//
	// `keyName` is value of security auth scheme key.
	// 		For e.g.:
	// 			security.auth_schemes.<keyname>
	Init(appCfg *config.Config, keyName string) error

	// Key method returns auth scheme configuration KeyName.
	// For e.g: `security.auth_schemes.<keyname>`.
	Key() string

	// Scheme method returns auth scheme name. For e.g.: form, basic, oauth2, generic, etc.
	Scheme() string

	// DoAuthenticate method called by aah SecurityManager to get Subject authentication
	// information.
	DoAuthenticate(authcToken *authc.AuthenticationToken) (*authc.AuthenticationInfo, error)

	// DoAuthorizationInfo method called by aah SecurityManager to get
	// Subject's authorization information if successful authentication.
	DoAuthorizationInfo(authcInfo *authc.AuthenticationInfo) *authz.AuthorizationInfo

	// ExtractAuthenticationToken method called by aah SecurityManager to
	// extract identity details from the HTTP request.
	ExtractAuthenticationToken(r *ahttp.Request) *authc.AuthenticationToken
}

Schemer interface is used to create new Auth Scheme for aah framework.

func New

func New(authSchemeType string) Schemer

New method creates the auth scheme instance for given type.

Jump to

Keyboard shortcuts

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