login

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthAdd

func AuthAdd(req *http.Request, clientID, clientSecret string, style session.AuthHeaderStyle)

AuthAdd is a function to set Authorization header.

Style must be AuthHeaderStyleBasic or AuthHeaderStyleBearerSecret, otherwise it does nothing.

Default style is AuthHeaderStyleBasic.

func NewState

func NewState() (string, error)

NewState generates cryptographically secure random state with base64 URL encoding.

func RemoveCookie

func RemoveCookie(w http.ResponseWriter, cookie *Cookie)

func SetBearerAuth

func SetBearerAuth(r *http.Request, token string)

SetBearerAuth sets the Authorization header to use Bearer token.

func SetCookie

func SetCookie(w http.ResponseWriter, value string, cookie *Cookie)

Types

type Cookie struct {
	// CookieName is the name of the cookie. Default is "auth_" + ClientID.
	CookieName string `cfg:"cookie_name"`
	// MaxAge the number of seconds until the cookie expires.
	MaxAge int `cfg:"max_age"`
	// Path that must exist in the requested URL for the browser to send the Cookie header.
	Path string `cfg:"path"`
	// Domain for defines the host to which the cookie will be sent.
	Domain string `cfg:"domain"`
	// Secure to cookie only sent over HTTPS.
	Secure bool `cfg:"secure"`
	// SameSite for Lax 2, Strict 3, None 4.
	SameSite http.SameSite `cfg:"same_site"`
	// HttpOnly for true for not accessible by JavaScript.
	HttpOnly bool `cfg:"http_only"`
}

type Info

type Info struct {
	Title string `cfg:"title"`
}

type InfoProvider

type InfoProvider struct {
	Password []Link `json:"password"`
	Code     []Link `json:"code"`
}

type InfoUIResponse

type InfoUIResponse struct {
	Title    string       `json:"title"`
	Provider InfoProvider `json:"provider"`
}
type Link struct {
	Name     string `json:"name"`
	URL      string `json:"url"`
	Priority int    `json:"-"`
}

type Login

type Login struct {
	Path     Path     `cfg:"path"`
	Redirect Redirect `cfg:"redirect"`
	UI       UI       `cfg:"ui"`
	Info     Info     `cfg:"info"`
	Request  Request  `cfg:"request"`

	SessionMiddleware string `cfg:"session_middleware"`

	StateCookie   Cookie `cfg:"state_cookie"`
	SuccessCookie Cookie `cfg:"success_cookie"`
	// contains filtered or unexported fields
}

Login middleware gives a login page.

func (*Login) AuthCodeRedirectURL

func (m *Login) AuthCodeRedirectURL(r *http.Request, providerName string) (string, error)

func (*Login) AuthCodeURL

func (m *Login) AuthCodeURL(r *http.Request, state, providerName string, oauth2 *session.Oauth2) (string, error)

func (*Login) CheckState

func (m *Login) CheckState(c echo.Context, check string) error

func (*Login) CodeFlow

func (m *Login) CodeFlow(c echo.Context) error

func (*Login) CodeFlowInit

func (m *Login) CodeFlowInit(c echo.Context, providerName string) error

func (*Login) CodeToken

func (m *Login) CodeToken(c echo.Context, code, providerName string, oauth2 *session.Oauth2) ([]byte, int, error)

CodeToken get token and set the cookie/session.

func (*Login) GetState

func (m *Login) GetState(c echo.Context) (string, error)

func (*Login) GetSuccess

func (m *Login) GetSuccess(c echo.Context) (string, error)

func (*Login) InformationUI

func (m *Login) InformationUI(c echo.Context) error

func (*Login) Logout

func (m *Login) Logout(c echo.Context) error

func (*Login) Middleware

func (m *Login) Middleware(ctx context.Context, _ string) (echo.MiddlewareFunc, error)

func (*Login) PasswordFlow

func (m *Login) PasswordFlow(c echo.Context) error

func (*Login) PasswordToken

func (m *Login) PasswordToken(ctx context.Context, username, password string, oauth2 *session.Oauth2) ([]byte, int, error)

func (*Login) RemoveState

func (m *Login) RemoveState(c echo.Context)

func (*Login) RemoveSuccess

func (m *Login) RemoveSuccess(c echo.Context)

func (*Login) SetState

func (m *Login) SetState(c echo.Context, state string)

func (*Login) SetSuccess

func (m *Login) SetSuccess(c echo.Context, success string)

func (*Login) SetView

func (m *Login) SetView() (func(http.Handler) http.Handler, error)

func (*Login) View

func (m *Login) View(w http.ResponseWriter, r *http.Request) error

type Path

type Path struct {
	Base string `cfg:"base"`
	// BaseURL for adding prefix like https://example.com
	BaseURL string `cfg:"base_url"`

	Code   string `cfg:"code"`
	Token  string `cfg:"token"`
	InfoUI string `cfg:"info_ui"`
}

type PathFixed

type PathFixed struct {
	Code   string
	InfoUI string
	Token  string
}

type Provider

type Provider struct {
	Oauth2 *session.Oauth2 `cfg:"oauth2"`

	// PasswordFlow is use password flow to get token.
	PasswordFlow bool `cfg:"password_flow"`
	// Priority is use to sort provider.
	Priority int `cfg:"priority"`
}

type Redirect

type Redirect struct {
	// BaseURL is the base URL to use for the redirect.
	// Default is the request Host with checking the X-Forwarded-Host header.
	BaseURL string `cfg:"base_url"`
	// Schema is the default schema to use for the redirect if no schema is provided.
	// Default is the https schema.
	Schema string `cfg:"schema"`
}

type Request

type Request struct {
	InsecureSkipVerify bool `cfg:"insecure_skip_verify"`
}

type TokenRequest

type TokenRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type UI

type UI struct {
	ExternalFolder bool `cfg:"external_folder"`
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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