Add server auth example.
This commit is contained in:
@@ -21,7 +21,7 @@ QHttpEngine is designed in a portable way, so it may run on other compilers and
|
||||
|
||||
## Build Instructions
|
||||
|
||||
QHttpEngine uses CMake for building the library. The library recognizes four options during configuration, all of which are disabled by default (the library is built as a shared library):
|
||||
QHttpEngine uses CMake for building the library. The library recognizes three options during configuration, all of which are disabled by default (the library is built as a shared library):
|
||||
|
||||
- `BUILD_DOC` - (requires Doxygen) generates documentation from the comments in the source code
|
||||
- `BUILD_EXAMPLES` - builds the sample applications that demonstrate how to use QHttpEngine
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
# Client
|
||||
add_executable(authclient client.cpp)
|
||||
target_link_libraries(authclient qhttpengine)
|
||||
target_compile_features(authclient PRIVATE cxx_lambdas)
|
||||
set_target_properties(authclient PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
)
|
||||
install(TARGETS authclient
|
||||
RUNTIME DESTINATION "${EXAMPLE_DIR}"
|
||||
)
|
||||
|
||||
# Server
|
||||
add_executable(authserver server.cpp)
|
||||
target_link_libraries(authserver qhttpengine)
|
||||
set_target_properties(authserver PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
)
|
||||
install(TARGETS authserver
|
||||
RUNTIME DESTINATION "${EXAMPLE_DIR}"
|
||||
)
|
||||
|
||||
@@ -20,8 +20,6 @@
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
|
||||
50
examples/auth/server.cpp
Normal file
50
examples/auth/server.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2017 Nathan Osman
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QHostAddress>
|
||||
#include <QVariantMap>
|
||||
|
||||
#include <qhttpengine/handler.h>
|
||||
#include <qhttpengine/localauthmiddleware.h>
|
||||
#include <qhttpengine/qobjecthandler.h>
|
||||
#include <qhttpengine/server.h>
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
QCoreApplication a(argc, argv);
|
||||
|
||||
QHttpEngine::QObjectHandler handler;
|
||||
QHttpEngine::Server server(&handler);
|
||||
if (!server.listen(QHostAddress::LocalHost)) {
|
||||
qCritical("unable to bind to a local port");
|
||||
a.exit(1);
|
||||
}
|
||||
|
||||
QHttpEngine::LocalAuthMiddleware middleware;
|
||||
middleware.setData(QVariantMap{
|
||||
{"port", server.serverPort()},
|
||||
});
|
||||
handler.addMiddleware(&middleware);
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user