Web framework C++  2.0.0
Simple web framework on c++ designed to easily create web pages, etc
Public Member Functions | List of all members
AuthMiddleware Class Reference

This middleware performs authentication on your application. More...

#include <auth_middleware.h>

Inheritance diagram for AuthMiddleware:
Inheritance graph
Collaboration diagram for AuthMiddleware:
Collaboration graph

Public Member Functions

 AuthMiddleware (const char *nameID, const char *cookieID, const char *jsonID)
 
 ~AuthMiddleware () override
 
void setOnSerialize (std::function< std::string(Entity *)> serialize)
 
void setOnDeserialize (std::function< Entity *(std::string &)> deserialize)
 
void setOnLogin (std::function< Entity *(std::string &, std::string &)> login)
 
bool login (std::string &userName, std::string &password)
 
bool autoExec () override
 
void exec () override
 
void clear () override
 
EntitygetUser ()
 
void addStrategy (AuthStrategy *strategy)
 
- Public Member Functions inherited from Middleware
 Middleware (const char *nameID)
 
virtual ~Middleware ()
 
void setContent (Request *request, Response *response)
 
void addValueToMap (const char *key, const char *value)
 
bool getValueFromMap (const char *key, std::string &value)
 
std::unordered_map< std::string, std::string > * getMap ()
 
std::string getNameID ()
 

Additional Inherited Members

- Protected Attributes inherited from Middleware
Requestrequest
 
Responseresponse
 
std::unordered_map< std::string, std::string > * map
 

Detailed Description

This middleware performs authentication on your application.

AuthMiddleware is intended to parse cookies or other data in headers with CookieMiddleware or JsonMiddleware, and then get information about authenticated user, also it could generate special technical data for responses to identificate clients

Constructor & Destructor Documentation

AuthMiddleware::AuthMiddleware ( const char *  nameID,
const char *  cookieID,
const char *  jsonID 
)
inline

Create new auth middleware. Depends on cookie and json middleware

Parameters
nameIDid of itself
cookieIDstring id of cookie middleware
jsonIDstring id of json middleware
AuthMiddleware::~AuthMiddleware ( )
override

Destructs inner objects

Member Function Documentation

void AuthMiddleware::addStrategy ( AuthStrategy strategy)

Add different auth strategies. By default, you can add CookieAuth or/and JwtAuth strategy, or write your and add it

Parameters
strategyconcrete strategy
bool AuthMiddleware::autoExec ( )
overridevirtual

If found users credentials, perform exec

Returns
true if should execute

Implements Middleware.

void AuthMiddleware::clear ( )
inlineoverridevirtual

delete all data, saved in internal values, set to default

Reimplemented from Middleware.

void AuthMiddleware::exec ( )
overridevirtual

Perform operations to check users credentials and proceed them

Implements Middleware.

Entity* AuthMiddleware::getUser ( )

Get current authenticated user. Could be used by any client defined handlers.

Returns
user object, or null if anyone was authorised
bool AuthMiddleware::login ( std::string &  userName,
std::string &  password 
)

Check authentication. Could be used in any client defined handler, where is processing user login to application

Parameters
userNameuser id
passworduser pass
Returns
true if authenticated successfully
void AuthMiddleware::setOnDeserialize ( std::function< Entity *(std::string &)>  deserialize)

Set deserialization function of user. From passed string this function should get user object from string if everything all right or null otherwise

Parameters
deserializefunction that get user object from string
void AuthMiddleware::setOnLogin ( std::function< Entity *(std::string &, std::string &)>  login)

Set function for authentication

Parameters
loginget User object from username and password. If something is wrong return null
void AuthMiddleware::setOnSerialize ( std::function< std::string(Entity *)>  serialize)

Set function, that perform serialization of user object. This data will be available on each call of deserialization function

Parameters
serializefunction that convert user object to string

The documentation for this class was generated from the following file: