auth

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

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

Go to latest
Published: May 31, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

source: golang.org/x/oauth2

Index

Constants

View Source
const (
	URI_RefreshToken = "/api/login/oauth/refresh_token"
)

Variables

This section is empty.

Functions

func ContextClient

func ContextClient(ctx context.Context) *http.Client

func NewService

func NewService(ctx context.Context, logger log.Logger, cfg Config, tokenRepository TokenRepository, sessionRepository session.Repository, userService user.IService, langFinder text_lang.LangFinder) (*service, error)

NewService creates a new authentication service.

func RefreshToken

func RefreshToken(ctx context.Context, conf *oauth2.Config, refreshToken string) (*oauth2.Token, error)

WARNING: Token is not safe for concurrent access, as it updates the tokenRefresher's refreshToken field. Within this package, it is used by reuseTokenSource which synchronizes calls to this method with its own mutex.

func ResetAuthCache

func ResetAuthCache()

ResetAuthCache resets the global authentication style cache used for AuthStyleUnknown token requests.

func RetrieveToken

func RetrieveToken(ctx context.Context, clientID, clientSecret, tokenURL string, v url.Values, authStyle AuthStyle) (*oauth2.Token, error)

func UnauthorizedError

func UnauthorizedError(rctx *routing.Context, message string) routing.HTTPError

Types

type AuthStyle

type AuthStyle int

AuthStyle is a copy of the golang.org/x/oauth2 package's AuthStyle type.

const (
	AuthStyleUnknown  AuthStyle = 0
	AuthStyleInParams AuthStyle = 1
	AuthStyleInHeader AuthStyle = 2
)

type Config

type Config struct {
	SignInRedirectURL      string
	JWTSigningKey          string
	JWTExpirationInHours   uint
	SessionlifeTimeInHours uint
	DefaultAccountSettings DefaultAccountSettings
}

type ContextKey

type ContextKey struct{}

ContextKey is just an empty struct. It exists so HTTPClient can be an immutable public variable with a unique type. It's immutable because nobody else can create a ContextKey, being unexported.

var HTTPClient ContextKey

HTTPClient is the context key to use with golang.org/x/net/context's WithValue function to associate an *http.Client value with a context.

type DefaultAccountSettings

type DefaultAccountSettings struct {
	Lang string
}

type RetrieveError

type RetrieveError struct {
	Response *http.Response
	Body     []byte
}

func (*RetrieveError) Error

func (r *RetrieveError) Error() string

type Service

type Service interface {
	//GetSignUpUrl() string
	//GetSignInUrl() string
	//GetForgetUrl() string
	//GetSession(ctx context.Context) *session.Session
	//SessionInit(ctx context.Context, token string, sessionID string, accountSettings *account.AccountSettings) (context.Context, error)
	//UpdateSession(ctx context.Context, sess *session.Session) (context.Context, *session.Session, error)
	//AccountSettingsUpdate(ctx context.Context, accountSettings *account.AccountSettings) (context.Context, error)
	//AccountUpdate(ctx context.Context, sess *session.Session) (context.Context, error)
	//SignIn(ctx context.Context, code, state string, accountSettings *account.AccountSettings) (context.Context, error)
	//StringTokenValidation(ctx context.Context, stringToken string) error
	//RoutingGetAccountSettingsWithDefaults(rctx *routing.Context) (*account.AccountSettings, error)
	//CheckAuthMiddleware(rctx *routing.Context) error
	//CreateUnauthSession(ctx context.Context, accountSettings *account.AccountSettings) (*session.Session, error)
	GetSession(ctx context.Context) (*session.Session, error)
	MiddlewareCheckAuth() routing.Handler
	MiddlewareSessionInit() routing.Handler
	SignInTg(ctx context.Context, account *tg_account.TgAccount, langID uint) (accessToken string, err error)
}

Service encapsulates the authentication logic.

type Token

type Token interface {
	GetClaims() *jwt.Claims
	GetData() *jwt.TokenData
	GenerateStringToken() (string, error)
}

type TokenRepository

type TokenRepository interface {
	NewTokenWithData(data *jwt.TokenData) (*jwt.Token, error)
	ParseStringToken(tokenString string) (*jwt.Token, error)
}

type UserService

type UserService interface {
}

Jump to

Keyboard shortcuts

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