authutils

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InsertTokenIntoRedis

func InsertTokenIntoRedis(User Person, token string, redisClient *redis.Client) string

InsertTokenIntoRedis is delegated to store the token of the customer into Redis. After that a customer have logged in, the token assigned as a cookie is stored into Redis (used as a Cache), in order to validate every request without query MongoDB.

func LoginUserCoreHTTP

func LoginUserCoreHTTP(username, password string, mongoClient *mgo.Session) string

LoginUserCoreHTTP is delegated to manage the "core process" of authentication. It use the username in input for retrieve the customer data from MongoDB. If the data is found, then the password in input will be compared with the one retrieved from the database

func ParseAuthCredentialFromHeaders

func ParseAuthCredentialFromHeaders(auth []byte) (string, string)

ParseAuthCredentialFromHeaders is delegated to extract the username and the password from the BasicAuth header provided by the request In case of error will return two emtpy string; in case of success will return (username,password)

func PasswordValidation

func PasswordValidation(password string) bool

PasswordValidation execute few check on the password in input

func RegisterUserCoreHTTP

func RegisterUserCoreHTTP(username, password string, mongoClient *mgo.Session) string

RegisterUserCoreHTTP is delegated to register the credential of the user into the Redis database. It estabilish the connection to MongoDB with a specialized function, then it create an user with the input data. After that, it ask to a delegated function to insert the data into Redis.

func TokenValidation

func TokenValidation(token string) bool

TokenValidation execute few check on the token in input

func UsernameValidation

func UsernameValidation(username string) bool

UsernameValidation execute few check on the username in input

func ValidateCredentials

func ValidateCredentials(user string, pass string) bool

ValidateCredentials is wrapper for the multiple method for validate the input parameters

func VerifyCookieFromRedisCoreHTTP

func VerifyCookieFromRedisCoreHTTP(user, token string, redisClient *redis.Client) string

VerifyCookieFromRedisCoreHTTP is delegated to verify if the cookie of the customer is present on the DB (aka is logged). This method have only to verify if the token provided by the customer that use the API is present on RedisDB. In first instance it try to validate the input data. Then will continue connecting to Redis in order to retrieve the token of the customer. If the token is found, the customer is authorized to continue.

Types

type City

type City struct {
	Name    string `bson:"Name,omitempty"` // Bergamo
	Town    string `bson:"Town,omitempty"` // Verdello
	ZipCode int    `bson:"ZipCode,omitempty"`
}

City save the location status of the customer

type Info

type Info struct {
	Type   string   `bson:"Type,omitempty"`   // IT Specialist
	Skills []string `bson:"Skills,omitempty"` // Java, Spring, Golang
	Years  int      `bson:"Years,omitempty"`
	City   City     `bson:"City,omitempty"`
}

Info Used for track user skill/experience/role

type Person

type Person struct {
	ID        bson.ObjectId `bson:"_id,omitempty" json:"_id,omitempty"`
	Username  string        `bson:"Username,omitempty" json:"Username,omitempty"`
	Password  string        `bson:"Password,omitempty" json:"Password,omitempty"`
	Name      string        `bson:"Name,omitempty" json:"Name,omitempty"`
	Surname   string        `bson:"Surname,omitempty"`
	Birthday  time.Time     `bson:"Birthday,omitempty"` // time.Date(2014, time.November, 5, 0, 0, 0, 0, time.UTC)
	Cellphone string        `bson:"Cellphone,omitempty"`
	Phone     string        `bson:"Phone,omitempty"`
	Addresses []Info        `bson:"Addresses,omitempty"`
	Mail      string        `bson:"Mail,omitempty" json:"Mail,omitempty"`
	WorkMail  string        `bson:"WorkMail,omitempty"`
}

Person structure of a customer for save it into the DB during registration phase.

Jump to

Keyboard shortcuts

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