auth

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2022 License: MIT Imports: 9 Imported by: 3

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(
	authServiceURL string,
	closed <-chan struct{},
	tokenKey,
	cookieKey []byte,
) (*Auth, error)

New initializes an Auth service.

func (*Auth) Authenticate

func (a *Auth) Authenticate(w http.ResponseWriter, r *http.Request) (ctx context.Context, err 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) FromContext

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

FromContext returnes the user id from a context returned by Authenticate(). If the context was not returned from Authenticate or the user is an anonymous user, then 0 is returned.

func (*Auth) ListenOnLogouts

func (a *Auth) ListenOnLogouts(ctx context.Context, logoutEventer LogoutEventer, errHandler func(error))

ListenOnLogouts listen on logout events and closes the connections.

func (*Auth) PruneOldData

func (a *Auth) PruneOldData(ctx context.Context)

PruneOldData removes old logout events.

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.

Jump to

Keyboard shortcuts

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