middleware

package
v0.0.0-...-0ae9f9e Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidClient      = "Invalid client credential!"
	InvalidUser        = "Invalid resource owner credential!"
	InvalidGrantType   = "Invalid grant type!"
	InvalidAccessToken = "Invalid access token!"
	InvalidScope       = "Invalid scope!"
	EmptyHeader        = "Authorization header is not included!"
	InvalidHeader      = "Authorization header is invalid!"
	RefreshToken       = "refresh_token"
	Password           = "password"
	Expiry             = 3600
)
View Source
const (
	ErrorTypeErrorValidation string = "validator.ValidationErrors"
)

const list

Variables

View Source
var (
	ErrorInternalError = errors.New("whoops something went wrong")
)

var list

View Source
var ValidationObject = []ExtraValidation{
	{Tag: "required", Message: "%s is required!"},
	{Tag: "max", Message: "%s cannot be more than %s!"},
	{Tag: "min", Message: "%s must be minimum %s!"},
	{Tag: "email", Message: "Invalid email format!"},
	{Tag: "len", Message: "%s must be %s characters long!"},
}

ValidationObject initialize default Validation object

Functions

func AccessToken

func AccessToken(store *oauth2.Store) gin.HandlerFunc

Return Access Token for valid client and user credential

func CORS

func CORS() gin.HandlerFunc

func Errors

func Errors() gin.HandlerFunc

Errors method collects all errors and submits them to Rollbar

func LcFirst

func LcFirst(str string) string

LcFirst method is to change lowercase word

func MakeExtraValidation

func MakeExtraValidation(v []ExtraValidation)

MakeExtraValidation method is for registering new validator

func OauthMiddleware

func OauthMiddleware(store *oauth2.Store) gin.HandlerFunc

Check If access token is valid and have proper scope

func Split

func Split(src string) string

Split method is to split camelcase letter

func UcFirst

func UcFirst(str string) string

UcFirst method is for uppercase first letter of word

func ValidationErrorToText

func ValidationErrorToText(e validator.FieldError) string

ValidationErrorToText method changes FieldError to string

Types

type AccessTokenPayload

type AccessTokenPayload struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiryTime   int64  `json:"expiry_time"`
}

type ExtraValidation

type ExtraValidation struct {
	Tag     string
	Message string
}

ExtraValidation model

type GrantType

type GrantType struct {
	GrantType string `json:"grant_type" binding:"required"`
}

type PasswordCredential

type PasswordCredential struct {
	ClientID     string `json:"client_id" binding:"required"`
	ClientSecret string `json:"client_secret" binding:"required"`
	Scope        string `json:"scope,omitempty" binding:"required"`
	Username     string `json:"username" binding:"required"`
	Password     string `json:"Password" binding:"required"`
}

func (PasswordCredential) GetScope

func (pc PasswordCredential) GetScope() string

type Profile

type Profile struct {
	Email string `json:"email"`
	Name  string `json:"name"`
	ID    uint   `json:"id"`
}

type RefreshTokenCredential

type RefreshTokenCredential struct {
	ClientID     string `json:"client_id" binding:"required"`
	ClientSecret string `json:"client_secret" binding:"required"`
	RefreshToken string `json:"refresh_token" binding:"required"`
	Scope        string `json:"scope,omitempty"`
}

func (RefreshTokenCredential) GetScope

func (rtc RefreshTokenCredential) GetScope() string

type Tokens

type Tokens interface {
	GetScope() string
}

Jump to

Keyboard shortcuts

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