aahframe.work: aahframe.work/security/scheme Index | Files

package scheme

import "aahframe.work/security/scheme"

Index

Package Files

base.go basic_auth.go form_auth.go generic_auth.go oauth2.go scheme.go

Variables

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

type BaseAuth Uses

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 Uses

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

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

func (*BaseAuth) ConfigKey Uses

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 Uses

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

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

func (*BaseAuth) DoAuthorizationInfo Uses

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

DoAuthorizationInfo method calls registered `Authorizer` with authentication information.

func (*BaseAuth) ExtractAuthenticationToken Uses

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

ExtractAuthenticationToken method typically implementated by extending struct.

func (*BaseAuth) Init Uses

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

Init method typically implemented by extending struct.

func (*BaseAuth) Key Uses

func (b *BaseAuth) Key() string

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

func (*BaseAuth) Scheme Uses

func (b *BaseAuth) Scheme() string

Scheme method return authentication scheme name.

func (*BaseAuth) SetAuthenticator Uses

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

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

func (*BaseAuth) SetAuthorizer Uses

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

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

func (*BaseAuth) SetPrincipalProvider Uses

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

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

type BasicAuth Uses

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

BasicAuth struct provides aah's OOTB Basic Auth scheme.

func (*BasicAuth) DoAuthenticate Uses

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

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

func (*BasicAuth) DoAuthorizationInfo Uses

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

DoAuthorizationInfo method calls registered `Authorizer` with authentication information.

func (*BasicAuth) ExtractAuthenticationToken Uses

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

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

func (*BasicAuth) Init Uses

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

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

type FormAuth Uses

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 Uses

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

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

func (*FormAuth) ExtractAuthenticationToken Uses

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

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

func (*FormAuth) Init Uses

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

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

type GenericAuth Uses

type GenericAuth struct {
    BaseAuth
    IdentityHeader   string
    CredentialHeader string
}

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

func (*GenericAuth) ExtractAuthenticationToken Uses

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

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

func (*GenericAuth) Init Uses

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

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

type OAuth2 Uses

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 Uses

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

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

func (*OAuth2) Config Uses

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

Config method returns OAuth2 config instance.

func (*OAuth2) Init Uses

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

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

func (*OAuth2) Principal Uses

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 Uses

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

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

func (*OAuth2) RefreshAccessToken Uses

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 Uses

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 Uses

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 Uses

func New(authSchemeType string) Schemer

New method creates the auth scheme instance for given type.

Package scheme imports 44 packages (graph) and is imported by 9 packages. Updated 2019-10-25. Refresh now. Tools for package owners.