Qt desktop app
The casdoor-cpp-qt-example shows Casdoor sign-in in a Qt desktop app.
Run the example
Voraussetzungen
Initialisierung
Set these 7 string parameters:
| Name | Beschreibung | Datei |
|---|---|---|
| endpoint | Ihr Casdoor Server Host/Domain | mainwindow.h |
| client_id | Die Client-ID Ihrer Casdoor-Anwendung | mainwindow.h |
| client_secret | Das Client-Geheimnis Ihrer Casdoor-Anwendung | mainwindow.h |
| certificate | Der öffentliche Schlüssel für das Zertifikat der Casdoor-Anwendung | mainwindow.h |
| org_name | Der Name Ihrer Casdoor-Organisation | mainwindow.h |
| app_name | Der Name Ihrer Casdoor-Anwendung | mainwindow.h |
| redirect_url | Der Pfad der Callback-URL für Ihre Casdoor-Anwendung, wird http://localhost:8080/callback sein, falls nicht angegeben | mainwindow.h |
Default endpoint: http://localhost:8000 if not set.
Running
Qt Creator
- Öffnen Sie
casdoor-cpp-qt-example.pro - Setzen Sie den
INCLUDEPATHvon OpenSSL incasdoor-cpp-qt-example.pro - Drücken Sie
Ctrl + R, um zu starten
Vorschau

Click Sign In to open the login window. After sign-in, the user profile is shown.

Integration
Open the login window
// Load and display the login page of Casdoor
m_webview->page()->load(*m_signin_url);
m_webview->show();
Listen for the callback (TCP)
// Initialize the TcpServer object and listen on port 8080
m_tcpserver = new QTcpServer(this);
if (!m_tcpserver->listen(QHostAddress::LocalHost, 8080)) {
qDebug() << m_tcpserver->errorString();
close();
}
connect(m_tcpserver, SIGNAL(newConnection()), this, SLOT(on_tcp_connected()));
Mit dem Auth-Code die Benutzerinfo abrufen
// Get the token and parse it with the JWT library
std::string token = m_casdoor->GetOAuthToken(code.toStdString());
auto decoded = m_casdoor->ParseJwtToken(token);