auth

package
v0.0.0-...-4eef36e Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package auth implement the auth system from the openslides-auth-service: https://github.com/OpenSlides/openslides-auth-service

Index

Constants

View Source
const (
	DebugTokenKey  = "auth-dev-token-key"
	DebugCookieKey = "auth-dev-cookie-key"
)

DebugTokenKey and DebugCookieKey are non random auth keys for development.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

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

Auth authenticates a request against the openslides-auth-service.

Has to be initialized with auth.New().

func New

func New(lookup environment.Environmenter, messageBus LogoutEventer) (*Auth, func(context.Context, func(error)), error)

New initializes the Auth object.

Returns the initialized Auth objectand a function to be called in the background.

func (*Auth) Authenticate

func (a *Auth) Authenticate(w http.ResponseWriter, r *http.Request) (context.Context, error)

Authenticate uses the headers from the given request to get the user id. The returned context will be cancled, if the session is revoked.

func (*Auth) AuthenticatedContext

func (a *Auth) AuthenticatedContext(ctx context.Context, userID int) context.Context

AuthenticatedContext returns a new context that contains an userID.

Should only used for internal URLs. All other URLs should use auth.Authenticate.

func (*Auth) FromContext

func (a *Auth) FromContext(ctx context.Context) int

FromContext returnes the user id from a context returned by Authenticate().

If the user is an anonymous user 0 is returned.

Panics, if the context was not returned from Authenticate

type LogoutEventer

type LogoutEventer interface {
	LogoutEvent(context.Context) ([]string, error)
}

LogoutEventer tells, when a sessionID gets revoked.

The method LogoutEvent has to block until there are new data. The returned data is a list of sessionIDs that are revoked.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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