This middleware performs authentication on your application.
More...
#include <auth_middleware.h>
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
AuthMiddleware::AuthMiddleware |
( |
const char * |
nameID, |
|
|
const char * |
cookieID, |
|
|
const char * |
jsonID |
|
) |
| |
|
inline |
Create new auth middleware. Depends on cookie and json middleware
- Parameters
-
nameID | id of itself |
cookieID | string id of cookie middleware |
jsonID | string id of json middleware |
AuthMiddleware::~AuthMiddleware |
( |
| ) |
|
|
override |
Add different auth strategies. By default, you can add CookieAuth or/and JwtAuth strategy, or write your and add it
- Parameters
-
strategy | concrete 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
-
userName | user id |
password | user 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
-
deserialize | function that get user object from string |
void AuthMiddleware::setOnLogin |
( |
std::function< Entity *(std::string &, std::string &)> |
login | ) |
|
Set function for authentication
- Parameters
-
login | get 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
-
serialize | function that convert user object to string |
The documentation for this class was generated from the following file: