auth

package
v1.15.6 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2021 License: MIT Imports: 14 Imported by: 13

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckOAuthAccessToken

func CheckOAuthAccessToken(accessToken string) int64

CheckOAuthAccessToken returns uid of user from oauth token

func Free

func Free()

Free should be called exactly once when the application is terminating to allow Auth plugins to release necessary resources

func Init

func Init()

Init should be called exactly once when the application starts to allow plugins to allocate necessary resources

func Register

func Register(method Auth)

Register adds the specified instance to the list of available methods

func SessionUser

func SessionUser(sess SessionStore) *models.User

SessionUser returns the user object corresponding to the "uid" session variable.

Types

type Auth

type Auth interface {
	Name() string

	// Init should be called exactly once before using any of the other methods,
	// in order to allow the plugin to allocate necessary resources
	Init() error

	// Free should be called exactly once before application closes, in order to
	// give chance to the plugin to free any allocated resources
	Free() error

	// Verify tries to verify the authentication data contained in the request.
	// If verification is successful returns either an existing user object (with id > 0)
	// or a new user object (with id = 0) populated with the information that was found
	// in the authentication data (username or email).
	// Returns nil if verification fails.
	Verify(http *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User
}

Auth represents an authentication method (plugin) for HTTP requests.

func Methods

func Methods() []Auth

Methods returns the instances of all registered methods

type Basic

type Basic struct {
}

Basic implements the Auth interface and authenticates requests (API requests only) by looking for Basic authentication data or "x-oauth-basic" token in the "Authorization" header.

func (*Basic) Free

func (b *Basic) Free() error

Free does nothing as the Basic implementation does not have to release any resources

func (*Basic) Init

func (b *Basic) Init() error

Init does nothing as the Basic implementation does not need to allocate any resources

func (*Basic) Name

func (b *Basic) Name() string

Name represents the name of auth method

func (*Basic) Verify

func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User

Verify extracts and validates Basic data (username and password/token) from the "Authorization" header of the request and returns the corresponding user object for that name/token on successful validation. Returns nil if header is empty or validation fails.

type DataStore

type DataStore middleware.DataStore

DataStore represents a data store

type Group

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

Group implements the Auth interface with serval Auth.

func NewGroup

func NewGroup(methods ...Auth) *Group

NewGroup creates a new auth group

func (*Group) Free

func (b *Group) Free() error

Free does nothing as the Basic implementation does not have to release any resources

func (*Group) Init

func (b *Group) Init() error

Init does nothing as the Basic implementation does not need to allocate any resources

func (*Group) Name

func (b *Group) Name() string

Name represents the name of auth method

func (*Group) Verify

func (b *Group) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User

Verify extracts and validates

type OAuth2

type OAuth2 struct {
}

OAuth2 implements the Auth interface and authenticates requests (API requests only) by looking for an OAuth token in query parameters or the "Authorization" header.

func (*OAuth2) Free

func (o *OAuth2) Free() error

Free does nothing as the OAuth2 implementation does not have to release any resources

func (*OAuth2) Init

func (o *OAuth2) Init() error

Init does nothing as the OAuth2 implementation does not need to allocate any resources

func (*OAuth2) Name

func (o *OAuth2) Name() string

Name represents the name of auth method

func (*OAuth2) Verify

func (o *OAuth2) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User

Verify extracts the user ID from the OAuth token in the query parameters or the "Authorization" header and returns the corresponding user object for that ID. If verification is successful returns an existing user object. Returns nil if verification fails.

type ReverseProxy

type ReverseProxy struct {
}

ReverseProxy implements the Auth interface, but actually relies on a reverse proxy for authentication of users. On successful authentication the proxy is expected to populate the username in the "setting.ReverseProxyAuthUser" header. Optionally it can also populate the email of the user in the "setting.ReverseProxyAuthEmail" header.

func (*ReverseProxy) Free

func (r *ReverseProxy) Free() error

Free does nothing as the ReverseProxy implementation does not have to release resources

func (*ReverseProxy) Init

func (r *ReverseProxy) Init() error

Init does nothing as the ReverseProxy implementation does not need initialization

func (*ReverseProxy) Name

func (r *ReverseProxy) Name() string

Name represents the name of auth method

func (*ReverseProxy) Verify

func (r *ReverseProxy) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User

Verify extracts the username from the "setting.ReverseProxyAuthUser" header of the request and returns the corresponding user object for that name. Verification of header data is not performed as it should have already been done by the revese proxy. If a username is available in the "setting.ReverseProxyAuthUser" header an existing user object is returned (populated with username or email found in header). Returns nil if header is empty.

type Session

type Session struct {
}

Session checks if there is a user uid stored in the session and returns the user object for that uid.

func (*Session) Free

func (s *Session) Free() error

Free does nothing as the Session implementation does not have to release any resources

func (*Session) Init

func (s *Session) Init() error

Init does nothing as the Session implementation does not need to allocate any resources

func (*Session) Name

func (s *Session) Name() string

Name represents the name of auth method

func (*Session) Verify

func (s *Session) Verify(req *http.Request, w http.ResponseWriter, store DataStore, sess SessionStore) *models.User

Verify checks if there is a user uid stored in the session and returns the user object for that uid. Returns nil if there is no user uid stored in the session.

type SessionStore

type SessionStore session.Store

SessionStore represents a session store

Jump to

Keyboard shortcuts

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