auth

package
v2.51.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RefreshLeeway is how long before a token's expiry a Session refreshes it.
	// Refreshing ahead of time avoids races where a request is made with a token
	// that expires while it is in flight.
	RefreshLeeway = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthenticateArgs

type AuthenticateArgs struct {
	Ctx          map[interface{}]interface{}
	ClientID     string
	ClientSecret string
}

AuthenticateArgs for RPC

type AuthenticateReply

type AuthenticateReply struct {
	User  *user.User
	Auth  map[string]*authpb.Scope
	Error error
}

AuthenticateReply for RPC

type Authenticator added in v2.51.0

type Authenticator func(ctx context.Context) (context.Context, time.Time, error)

Authenticator produces an authenticated context together with the time at which its token expires. A Session calls it once up front and then again shortly before each expiry to keep the context fresh.

type ConfigureArg

type ConfigureArg struct {
	Ml map[string]interface{}
}

ConfigureArg for RPC

type ConfigureReply

type ConfigureReply struct {
	Err error
}

ConfigureReply for RPC

type CredentialStrategy

type CredentialStrategy interface {
	GetCredentials(w http.ResponseWriter, r *http.Request) (*Credentials, error)
	AddWWWAuthenticate(w http.ResponseWriter, r *http.Request, realm string)
}

CredentialStrategy obtains Credentials from the request.

type Credentials

type Credentials struct {
	Type         string
	ClientID     string
	ClientSecret string
}

Credentials contains the auth type, client id and secret.

type Manager

type Manager interface {
	plugin.Plugin
	Authenticate(ctx context.Context, clientID, clientSecret string) (*user.User, map[string]*authpb.Scope, error)
}

Manager is the interface to implement to authenticate users

type ProviderPlugin

type ProviderPlugin struct {
	Impl Manager
}

ProviderPlugin is the implementation of plugin.Plugin so we can serve/consume this.

func (*ProviderPlugin) Client

func (p *ProviderPlugin) Client(b *hcplugin.MuxBroker, c *rpc.Client) (interface{}, error)

Client returns interface implementation for the plugin that communicates to the server end of the plugin

func (*ProviderPlugin) Server

func (p *ProviderPlugin) Server(*hcplugin.MuxBroker) (interface{}, error)

Server returns the RPC Server which serves the methods that the Client calls over net/rpc

type RPCClient

type RPCClient struct{ Client *rpc.Client }

RPCClient is an implementation of Manager that talks over RPC.

func (*RPCClient) Authenticate

func (m *RPCClient) Authenticate(ctx context.Context, clientID, clientSecret string) (*user.User, map[string]*authpb.Scope, error)

Authenticate RPCClient Authenticate method

func (*RPCClient) Configure

func (m *RPCClient) Configure(ml map[string]interface{}) error

Configure RPCClient configure method

type RPCServer

type RPCServer struct {
	// This is the real implementation
	Impl Manager
}

RPCServer is the server that RPCClient talks to, conforming to the requirements of net/rpc

func (*RPCServer) Authenticate

func (m *RPCServer) Authenticate(args AuthenticateArgs, resp *AuthenticateReply) error

Authenticate RPCServer Authenticate method

func (*RPCServer) Configure

func (m *RPCServer) Configure(args ConfigureArg, resp *ConfigureReply) error

Configure RPCServer Configure method

type Registry

type Registry interface {
	ListProviders(ctx context.Context) ([]*registry.ProviderInfo, error)
	GetProvider(ctx context.Context, authType string) (*registry.ProviderInfo, error)
}

Registry is the interface that auth registries implement for discovering auth providers

type Session added in v2.51.0

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

Session keeps an authenticated context valid for the whole duration of a long-running task.

Many operations (indexing a space, creating an archive, bulk migrations, …) can outlive the lifetime of a single authentication token. Passing a static context to such a task means its token expires halfway through and every subsequent call fails. Session solves this by owning the context: it authenticates once up front via an Authenticator and then refreshes the context in the background shortly before the token expires. Callers always read the current context through Ctx, so they transparently pick up refreshed tokens without having to thread a new context around. A Session is safe for concurrent use.

func NewSession added in v2.51.0

func NewSession(parent context.Context, auth Authenticator) (*Session, error)

NewSession authenticates once via auth and then refreshes the context in the background shortly before the token expires. It returns an error if the initial authentication fails.

func NewStaticSession added in v2.51.0

func NewStaticSession(ctx context.Context) *Session

NewStaticSession returns a Session that always returns ctx and never refreshes. It is useful for callers that manage their own (typically short-lived) context but need to satisfy a Session-based API.

func (*Session) Close added in v2.51.0

func (s *Session) Close()

Close stops the background refresher and cancels the session-owned context, unblocking any in-flight authentication call.

func (*Session) Ctx added in v2.51.0

func (s *Session) Ctx() context.Context

Ctx returns the current authentication context. It always carries a valid token as long as the Authenticator keeps succeeding.

type TokenStrategy

type TokenStrategy interface {
	GetToken(r *http.Request) string
}

TokenStrategy obtains a token from the request. If token does not exist returns an empty string.

type TokenWriter

type TokenWriter interface {
	WriteToken(token string, w http.ResponseWriter)
}

TokenWriter stores the token in a http response.

Directories

Path Synopsis
manager
guestlinks
Package guestlinks implements a Reva auth.Manager that authenticates OpenCloud guest-link sessions.
Package guestlinks implements a Reva auth.Manager that authenticates OpenCloud guest-link sessions.
oidc
Package oidc verifies an OIDC token against the configured OIDC provider and obtains the necessary claims to obtain user information.
Package oidc verifies an OIDC token against the configured OIDC provider and obtains the necessary claims to obtain user information.

Jump to

Keyboard shortcuts

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