auth

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Authenticator

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

Authenticator is an auth requests handler.

func New

func New(log *zap.Logger, sdkPool *pool.Pool, config *Config) (*Authenticator, error)

New creates authenticator using config.

func (*Authenticator) Callback

func (u *Authenticator) Callback(w http.ResponseWriter, r *http.Request)

Callback is an external services callback handler.

func (*Authenticator) Index

func (u *Authenticator) Index(w http.ResponseWriter, _ *http.Request)

Index is main page handler.

func (*Authenticator) LogInWith

func (u *Authenticator) LogInWith(w http.ResponseWriter, r *http.Request)

LogInWith is an auth using external services handler.

type Config

type Config struct {
	Bearer           *bearer.Config
	BearerCookieName string
	Oauth            map[string]*ServiceOauth
	TLSEnabled       bool
	Host             string
	RedirectURL      string
}

Config for authenticator handler.

type ServiceOauth

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

ServiceOauth is config for specific service.

func NewServiceConfig

func NewServiceConfig(name string, oauth *oauth2.Config) (*ServiceOauth, error)

NewServiceConfig creates config for supported services.

func (*ServiceOauth) AuthCodeURL

func (c *ServiceOauth) AuthCodeURL(state string) string

AuthCodeURL gets URL to auth on external service using state.

func (*ServiceOauth) Exchange

func (c *ServiceOauth) Exchange(ctx context.Context, code string) (*oauth2.Token, error)

Exchange gets auth token after authorization.

func (*ServiceOauth) GetUserEmail

func (c *ServiceOauth) GetUserEmail(ctx context.Context, token *oauth2.Token) (string, error)

GetUserEmail receives user email after authentication on external service.

type Services

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

Services stores supported external oauth2 services.

func NewServices

func NewServices(configs map[string]*ServiceOauth) *Services

NewServices creates services storage using config.

func (*Services) AddState

func (s *Services) AddState(state, service string)

AddState saves new state to auth into storage.

func (*Services) Oauth

func (s *Services) Oauth(service string) (*ServiceOauth, bool)

Oauth gets config for specified service.

func (*Services) RemoveState

func (s *Services) RemoveState(state string) (string, error)

RemoveState gets and deletes used state from storage.

Jump to

Keyboard shortcuts

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