elogin

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package elogin provides auth middle procedures for remote authentication including oauth2 and other protocols, and specific providers like google, facebook, etc.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidState = errors.New("invalid state")
)

Functions

This section is empty.

Types

type AuthAccessor

type AuthAccessor interface {
	Provider() string
	Protocol() string
	LoginURL(urlParams []URLParam) string
	UserData(ctx context.Context, values url.Values, urlParams []URLParam) (*Token, *UserData, error)
}

type AuthHTTPWrapper

type AuthHTTPWrapper struct {
	Auth           AuthAccessor
	Error          ErrorHandler
	Success        SuccessHandler
	RedirectParams RedirectParamsExtractor
}

AuthHTTPWrapper provides a wrapper for auth authentication

func NewWrapper

func NewWrapper(auth AuthAccessor, err ErrorHandler, success SuccessHandler, redirectParams RedirectParamsExtractor) *AuthHTTPWrapper

NewWrapper creates a new instance of AuthHTTPWrapper

func (*AuthHTTPWrapper) Callback

func (wr *AuthHTTPWrapper) Callback(w http.ResponseWriter, r *http.Request)

Callback handles the callback request

func (*AuthHTTPWrapper) HandleWrapper

func (wr *AuthHTTPWrapper) HandleWrapper(prefix string) http.Handler

HandleWrapper returns the http handler which handles the auth authentication

func (*AuthHTTPWrapper) Login

func (wr *AuthHTTPWrapper) Login(w http.ResponseWriter, r *http.Request)

Login handles the login request

func (*AuthHTTPWrapper) Protocol

func (wr *AuthHTTPWrapper) Protocol() string

Protocol returns the protocol name

func (*AuthHTTPWrapper) Provider

func (wr *AuthHTTPWrapper) Provider() string

Provider returns the provider name

type ErrorHandler

type ErrorHandler interface {
	Error(w http.ResponseWriter, r *http.Request, err error)
}

type RedirectParamsExtractor

type RedirectParamsExtractor interface {
	RedirectParams(w http.ResponseWriter, r *http.Request, login bool) []URLParam
}

type SuccessHandler

type SuccessHandler interface {
	Success(w http.ResponseWriter, r *http.Request, token *Token, data *UserData)
}

type Token

type Token struct {
	TokenType    string    `json:"token_type,omitempty"`
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token"`
	ExpiresAt    time.Time `json:"expires_at,omitempty"`
	Scopes       []string  `json:"scopes,omitempty"`
}

Token represents the token data

func (*Token) IsBearer

func (tok *Token) IsBearer() bool

IsBearer checks if the token is a bearer token

func (*Token) IsExpired

func (tok *Token) IsExpired() bool

IsExpired checks if the token is expired

type URLParam

type URLParam struct {
	Key   string
	Value string
}

type UserData

type UserData struct {
	ID        string `json:"id"`
	Email     string `json:"email"`
	FirstName string `json:"first_name"`
	LastName  string `json:"last_name"`
	Username  string `json:"username"`
	AvatarURL string `json:"avatar_url"`
	Link      string `json:"link"`

	// Ext is the extra data
	Ext map[string]any `json:"ext,omitempty"`

	OAuth2conf *oauth2.Config `json:"-"`
}

UserData represents the user data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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