oauth2google

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// CookieExpiration is expiration for JWT cookie
	CookieExpiration time.Duration = 72 * time.Hour

	StateExpiration time.Duration = 20 * time.Minute

	TokenEpiration time.Duration = 72 * time.Hour
)
View Source
var (
	// DefaultConfigName is default config name of oauth2 google
	DefaultConfigName = "OAUTH2_GOOGLE"
)

Functions

func Module

func Module() *typapp.Module

Module of google oauth

Types

type AuthCntrl

type AuthCntrl struct {
	dig.In
	*Config
	AuthService
}

AuthCntrl is controller to handle authentication

func (*AuthCntrl) Callback

func (c *AuthCntrl) Callback(ce echo.Context) (err error)

Callback for google auth

func (*AuthCntrl) Login

func (c *AuthCntrl) Login(ce echo.Context) (err error)

Login with google auth

func (*AuthCntrl) Logout

func (c *AuthCntrl) Logout(ce echo.Context) (err error)

Logout by invalidating cookies

func (*AuthCntrl) Middleware

func (c *AuthCntrl) Middleware() echo.MiddlewareFunc

Middleware for google social login

func (*AuthCntrl) SetTokenCtxMiddleware

func (c *AuthCntrl) SetTokenCtxMiddleware() echo.MiddlewareFunc

SetTokenCtxMiddleware re-set token to request context for informational purpose (getting username, etc)

type AuthService

type AuthService interface {
	VerifyCallback(ce echo.Context, jwtSecret string) (string, error)
	GetAuthCodeURL(ce echo.Context, cookieSecure bool) string
}

AuthService is center related logic [mock]

func NewService

func NewService(cfg *Config) AuthService

NewService return new instance of AuthGoogleService

type AuthServiceImpl

type AuthServiceImpl struct {
	dig.In
	*oauth2.Config
	// contains filtered or unexported fields
}

AuthServiceImpl implementation of AuthService

func (*AuthServiceImpl) GetAuthCodeURL

func (c *AuthServiceImpl) GetAuthCodeURL(ce echo.Context, cookieSecure bool) (authCodeURL string)

func (*AuthServiceImpl) VerifyCallback

func (c *AuthServiceImpl) VerifyCallback(ce echo.Context, jwtSecret string) (string, error)

VerifyCallback to add metaTag

type Config

type Config struct {
	ClientID     string `envconfig:"CLIENT_ID" required:"true"`
	ClientSecret string `envconfig:"CLIENT_SECRET" required:"true"`
	Callback     string `envconfig:"CALLBACK" required:"true"`
	HostedDomain string `envconfig:"HOSTED_DOMAIN"`

	CookieSecure bool   `envconfig:"COOKIE_SECURE" default:"false"`
	JWTSecret    string `envconfig:"JWT_SECRET"`

	RedirectSuccess string `envconfig:"REDIRECT_SUCCESS"`
	RedirectFailure string `envconfig:"REDIRECT_FAILURE"`
	LogoutRedirect  string `envconfig:"LOGOUT_REDIRECT"`
}

Config is configuration of google social login

Jump to

Keyboard shortcuts

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