httpserver

package
v0.0.0-...-e77dc18 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Endpoint = goog.Endpoint

Endpoint is Google's OAuth 2.0 endpoint.

View Source
var ErrUserAlreadyExists = "User already exists with the given email"

ErrUserAlreadyExists ...

View Source
var ErrUserNotFound = "No user account exists with given email. Please sign in first"

ErrUserNotFound ...

View Source
var GetState = func(req *http.Request) string {
	params := req.URL.Query()
	if params.Encode() == "" && req.Method == http.MethodPost {
		return req.FormValue("state")
	}
	return params.Get("state")
}

GetState gets the state returned by the provider during the callback. This is used to prevent CSRF attacks, see http://tools.ietf.org/html/rfc6749#section-10.12

View Source
var PgDuplicateKeyMsg = "duplicate key value violates unique constraint"

PgDuplicateKeyMsg ...

View Source
var PgNoRowsMsg = "no rows in result set"

PgNoRowsMsg ...

View Source
var SetState = func(req *http.Request) string {
	state := req.URL.Query().Get("state")
	if len(state) > 0 {
		return state
	}

	nonceBytes := make([]byte, 64)
	_, err := io.ReadFull(rand.Reader, nonceBytes)
	if err != nil {
		panic("gothic: source of randomness unavailable: " + err.Error())
	}
	return base64.URLEncoding.EncodeToString(nonceBytes)
}

SetState sets the state string associated with the given request. If no state string is associated with the request, one will be generated. This state is sent to the provider and can be retrieved during the callback.

View Source
var UserCreationFailed = "Unable to create user.Please try again later"

UserCreationFailed ...

Functions

This section is empty.

Types

type AuthHandler

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

AuthHandler wraps instances needed to perform operations on user object

func NewAuthHandler

func NewAuthHandler(l hclog.Logger, c *utils.Configurations, v *data.Validation, r data.AuthRepository, auth service.Authentication, jwtManager *token.JWTManager, mail mail.Service, opts ...Option) *AuthHandler

NewAuthHandler returns a new UserHandler instance

func (*AuthHandler) GeneratePassResetCode

func (ah *AuthHandler) GeneratePassResetCode(w http.ResponseWriter, r *http.Request)

GeneratePassResetCode generate a new secret code to reset password.

func (*AuthHandler) GoogleLogin

func (ah *AuthHandler) GoogleLogin(w http.ResponseWriter, r *http.Request)

GoogleLogin ...

func (*AuthHandler) GoogleOAuth

func (ah *AuthHandler) GoogleOAuth(w http.ResponseWriter, r *http.Request)

GoogleOAuth ...

func (*AuthHandler) Greet

func (ah *AuthHandler) Greet(w http.ResponseWriter, r *http.Request)

Greet request greet request

func (*AuthHandler) Login

func (ah *AuthHandler) Login(w http.ResponseWriter, r *http.Request)

Login handles login request

func (*AuthHandler) MiddlewareValidateAccessToken

func (ah *AuthHandler) MiddlewareValidateAccessToken(next http.Handler) http.Handler

MiddlewareValidateAccessToken validates whether the request contains a bearer token it also decodes and authenticates the given token

func (*AuthHandler) MiddlewareValidateRefreshToken

func (ah *AuthHandler) MiddlewareValidateRefreshToken(next http.Handler) http.Handler

MiddlewareValidateRefreshToken validates whether the request contains a bearer token it also decodes and authenticates the given token

func (*AuthHandler) MiddlewareValidateUser

func (ah *AuthHandler) MiddlewareValidateUser(next http.Handler) http.Handler

MiddlewareValidateUser validates the user in the request

func (*AuthHandler) MiddlewareValidateVerificationData

func (ah *AuthHandler) MiddlewareValidateVerificationData(next http.Handler) http.Handler

MiddlewareValidateVerificationData validates whether the request contains the email and confirmation code that are required for the verification

func (*AuthHandler) Profile

func (ah *AuthHandler) Profile(w http.ResponseWriter, r *http.Request)

Profile ...

func (*AuthHandler) RefreshToken

func (ah *AuthHandler) RefreshToken(w http.ResponseWriter, r *http.Request)

RefreshToken handles refresh token request

func (*AuthHandler) ResetPassword

func (ah *AuthHandler) ResetPassword(w http.ResponseWriter, r *http.Request)

ResetPassword handles the password reset request

func (*AuthHandler) Signup

func (ah *AuthHandler) Signup(w http.ResponseWriter, r *http.Request)

Signup handles signup request

func (*AuthHandler) UpdateUsername

func (ah *AuthHandler) UpdateUsername(w http.ResponseWriter, r *http.Request)

UpdateUsername handles username update request

func (*AuthHandler) VerifyMail

func (ah *AuthHandler) VerifyMail(w http.ResponseWriter, r *http.Request)

VerifyMail verifies the provided confirmation code and set the User state to verified

func (*AuthHandler) VerifyPasswordReset

func (ah *AuthHandler) VerifyPasswordReset(w http.ResponseWriter, r *http.Request)

VerifyPasswordReset verifies the code provided for password reset

type AuthResponse

type AuthResponse struct {
	RefreshToken string `json:"refresh_token"`
	AccessToken  string `json:"access_token"`
	Username     string `json:"username"`
}

AuthResponse ...

type CodeVerificationReq

type CodeVerificationReq struct {
	Code string `json:"code"`
	Type string `json:"type"`
}

CodeVerificationReq ...

type GenericResponse

type GenericResponse struct {
	Status  bool        `json:"status"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

GenericResponse is the format of our response

type Option

type Option func(*AuthHandler)

Option ...

func WithGoogleAuth

func WithGoogleAuth(clientKey string, secret string, callbackURL string, scopes ...string) Option

WithGoogleAuth ...

type PasswordResetReq

type PasswordResetReq struct {
	Password   string `json:"password"`
	PasswordRe string `json:"password_re"`
	Code       string `json:"code"`
}

PasswordResetReq ...

type TokenResponse

type TokenResponse struct {
	RefreshToken string `json:"refresh_token"`
	AccessToken  string `json:"access_token"`
}

TokenResponse below data types are used for encoding and decoding b/t go types and json

type UserIDKey

type UserIDKey struct{}

UserIDKey is used as a key for storing the UserID in context at middleware

type UserKey

type UserKey struct{}

UserKey is used as a key for storing the User object in context at middleware

type UsernameUpdate

type UsernameUpdate struct {
	Username string `json:"username"`
}

UsernameUpdate ...

type ValidationError

type ValidationError struct {
	Errors []string `json:"errors"`
}

ValidationError is a collection of validation error messages

type VerificationDataKey

type VerificationDataKey struct{}

VerificationDataKey is used as the key for storing the VerificationData in context at middleware

Jump to

Keyboard shortcuts

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