-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthserver.cpp
More file actions
48 lines (42 loc) · 1.25 KB
/
authserver.cpp
File metadata and controls
48 lines (42 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "authserver.h"
AuthServer::AuthServer(QObject *parent)
: QObject{parent}
{
server = nullptr;
}
AuthServer::~AuthServer() {
if(server == nullptr) {
delete server;
server = nullptr;
}
deleteLater();
}
int AuthServer::serve() {
server = new QHttpServer(this);
server->route("/", []() {
return "Hello World";
});
server->route("/auth", QHttpServerRequest::Method::Get, [=](const QHttpServerRequest &req) {
QUrlQuery uQry = req.query();
code = uQry.queryItemValue("code");
emit getCode(code);
return "success!";
});
const auto port = this->server->listen(QHostAddress::Any, 65412);
emit Serving(port);
QString URL = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize? \
client_id=c6bd3fe0-989e-48b7-8425-d5ae917f650a \
&response_type=code \
&redirect_uri=http%3A%2F%2Flocalhost%3A65412%2Fauth \
&response_mode=query \
&scope=offline_access%20User.Read%20Tasks.ReadWrite";
QDesktopServices::openUrl(URL);
return port;
}
void AuthServer::stop() {
if(server == nullptr) {
delete server;
server = nullptr;
}
deleteLater();
}