auth

package
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SessionIDFromContext added in v2.5.4

func SessionIDFromContext(ctx context.Context) string

SessionIDFromContext returns the authenticated Mattermost session ID, or an empty string when the request has no session. Callers must fail closed when the result is empty.

func WithSessionID added in v2.5.4

func WithSessionID(ctx context.Context, sessionID string) context.Context

WithSessionID returns a context carrying the authenticated Mattermost session used for policy checks.

Types

type AuthenticationProvider

type AuthenticationProvider interface {
	ValidateAuth(ctx context.Context) error

	// GetAuthenticatedMattermostClient returns an authenticated Mattermost client
	GetAuthenticatedMattermostClient(ctx context.Context) (*model.Client4, error)
}

AuthenticationProvider handles authentication for MCP requests

type ClientAndUserProvider added in v2.10.0

type ClientAndUserProvider interface {
	GetAuthenticatedClientAndUser(ctx context.Context) (*model.Client4, *model.User, error)
}

ClientAndUserProvider returns the authenticated client and user from a single validation. Callers needing both use it instead of calling GetAuthenticatedMattermostClient and GetAuthenticatedUser, which would each validate the session (one GET /users/me apiece).

type ContextKey

type ContextKey string

Context keys for passing data through context

const (
	// AuthTokenContextKey is used to store the validated auth token in context
	AuthTokenContextKey ContextKey = "auth_token"
	// SessionIDContextKey is used to store the session ID in context
	SessionIDContextKey ContextKey = "session_id"
	// TokenResolverContextKey is used to store a function that resolves sessionID to token
	TokenResolverContextKey ContextKey = "token_resolver"
	// UserIDContextKey is used to store the user ID in context for HTTP callbacks
	UserIDContextKey ContextKey = "user_id"
)

type OAuthAuthenticationProvider

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

OAuthAuthenticationProvider provides OAuth authentication for HTTP transport As a resource server, we only need to validate tokens using Mattermost's API

func NewOAuthAuthenticationProvider

func NewOAuthAuthenticationProvider(externalURL, internalURL, issuer string, logger logger.Logger) *OAuthAuthenticationProvider

NewOAuthAuthenticationProvider creates a new OAuth authentication provider for resource server Uses internalURL for API communication if provided, otherwise falls back to externalURL

func (*OAuthAuthenticationProvider) GetAuthenticatedMattermostClient

func (p *OAuthAuthenticationProvider) GetAuthenticatedMattermostClient(ctx context.Context) (*model.Client4, error)

GetAuthenticatedMattermostClient returns an OAuth-authenticated Mattermost client

func (*OAuthAuthenticationProvider) GetAuthenticatedUser

func (p *OAuthAuthenticationProvider) GetAuthenticatedUser(ctx context.Context) (*model.User, error)

GetAuthenticatedUser returns the Mattermost user for the OAuth token in context.

func (*OAuthAuthenticationProvider) ValidateAuth

func (p *OAuthAuthenticationProvider) ValidateAuth(ctx context.Context) error

ValidateAuth validates OAuth authentication from context

type SessionAuthenticationProvider

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

SessionAuthenticationProvider provides session-based authentication for in-memory transport This provider uses existing Mattermost session tokens passed through context, eliminating the need for separate OAuth flows for embedded MCP servers

func NewSessionAuthenticationProvider

func NewSessionAuthenticationProvider(externalURL, internalURL string, logger logger.Logger) *SessionAuthenticationProvider

NewSessionAuthenticationProvider creates a new session authentication provider for in-memory transport Uses internalURL for API communication if provided, otherwise falls back to externalURL

func (*SessionAuthenticationProvider) GetAuthenticatedClientAndUser added in v2.10.0

func (p *SessionAuthenticationProvider) GetAuthenticatedClientAndUser(ctx context.Context) (*model.Client4, *model.User, error)

GetAuthenticatedClientAndUser returns the client and user from one session validation.

func (*SessionAuthenticationProvider) GetAuthenticatedMattermostClient

func (p *SessionAuthenticationProvider) GetAuthenticatedMattermostClient(ctx context.Context) (*model.Client4, error)

GetAuthenticatedMattermostClient returns a session-authenticated Mattermost client Uses token resolver to get tokens from session IDs for the embedded server

func (*SessionAuthenticationProvider) GetAuthenticatedUser

func (p *SessionAuthenticationProvider) GetAuthenticatedUser(ctx context.Context) (*model.User, error)

GetAuthenticatedUser returns the authenticated Mattermost user for the session token in context. Uses token resolver to get tokens from session IDs for the embedded server

func (*SessionAuthenticationProvider) ValidateAuth

func (p *SessionAuthenticationProvider) ValidateAuth(ctx context.Context) error

ValidateAuth validates session authentication from context The session token must be present in the context and be valid

type TokenAuthenticationProvider

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

TokenAuthenticationProvider provides PAT token authentication for STDIO transport

func NewTokenAuthenticationProvider

func NewTokenAuthenticationProvider(externalURL, internalURL, token string, logger logger.Logger) *TokenAuthenticationProvider

NewTokenAuthenticationProvider creates a new PAT token authentication provider for STDIO transport Uses internalURL for API communication if provided, otherwise falls back to externalURL

func (*TokenAuthenticationProvider) GetAuthenticatedMattermostClient

func (p *TokenAuthenticationProvider) GetAuthenticatedMattermostClient(ctx context.Context) (*model.Client4, error)

GetAuthenticatedMattermostClient returns an authenticated Mattermost client

func (*TokenAuthenticationProvider) ValidateAuth

func (p *TokenAuthenticationProvider) ValidateAuth(ctx context.Context) error

ValidateAuth validates authentication (single GetMe call)

type TokenResolver

type TokenResolver func(sessionID string) (string, error)

TokenResolver is a function that resolves a sessionID to a token

type UserIdentityProvider

type UserIdentityProvider interface {
	AuthenticationProvider

	// GetAuthenticatedUser returns the authenticated Mattermost user for the current context
	GetAuthenticatedUser(ctx context.Context) (*model.User, error)
}

UserIdentityProvider can supply the authenticated Mattermost user for the current context. Implementations may use cached validation results to avoid additional network calls.

Jump to

Keyboard shortcuts

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