auth

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: GPL-3.0 Imports: 13 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

Role Mask constants

View Source
var RoleSpaceAdmin = NewRoleMask(Admin, Manager)
View Source
var RoleSpaceSuperUser = NewRoleMask(Admin)

Functions

This section is empty.

Types

type Authenticator

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

func NewAuthenticator

func NewAuthenticator(
	context config.AuthContext,
	config *oauth2.Config,
	authCallbackHandler func(w http.ResponseWriter, r *http.Request),
) *Authenticator

func (*Authenticator) IsAuthenticated

func (authn *Authenticator) IsAuthenticated() (bool, error)

Checks if the current auth context has been authenticated. This will refresh the oauth token if the access token has expired and the refresh token has not expired

func (*Authenticator) OAuthHandler

func (authn *Authenticator) OAuthHandler(w http.ResponseWriter, r *http.Request)

Handles the OAuth callback which exchanges the auth code in the request for a token and saves the token.

func (*Authenticator) RetrieveToken

func (authn *Authenticator) RetrieveToken(authCode string) error

Exchange given auth code for a token

func (*Authenticator) StartOAuthFlow

func (authn *Authenticator) StartOAuthFlow(
	ports []int,
	reqHandlers ...func() (string, func(http.ResponseWriter, *http.Request)),
) (string, error)

Starts an http listener locally to listen for the oauth redirect with authcode once the user has been authenticated by the auth service.

func (*Authenticator) WaitForOAuthFlowCompletion

func (authn *Authenticator) WaitForOAuthFlowCompletion(timeout time.Duration) (bool, error)

Wait until OAuth flow has completed. Returns false if oath flow completes with callback to local server

type Role

type Role uint

User Role

const (
	// grants admin access both at
	// local/device and remote/space
	Admin Role = iota
	// grants access to remote
	// management space functions
	Manager
	// guest access
	Guest
)

func RoleFromContext

func RoleFromContext(
	deviceContext config.DeviceContext,
	spaceNode userspace.SpaceNode,
) Role

func RoleFromString

func RoleFromString(r string) Role

func (Role) String

func (r Role) String() string

type RoleMask

type RoleMask uint

Space user role mask

func NewRoleMask

func NewRoleMask(roles ...Role) RoleMask

func (RoleMask) HasOnlyRole

func (m RoleMask) HasOnlyRole(r Role) bool

func (RoleMask) HasRole

func (m RoleMask) HasRole(r Role) bool

func (RoleMask) LoggedInUserHasRole

func (m RoleMask) LoggedInUserHasRole(
	deviceContext config.DeviceContext,
	spaceNode userspace.SpaceNode,
) bool

check if user logged into device is authorized using the give mask

Jump to

Keyboard shortcuts

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