Qt desktop app
The casdoor-cpp-qt-example shows Casdoor sign-in in a Qt desktop app.
Run the example
Prérequis
Initialisation
Set these 7 string parameters:
| Nom | Description | Fichier |
|---|---|---|
| endpoint | Votre hôte/domaine de serveur Casdoor | mainwindow.h |
| client_id | L'ID client de votre application Casdoor | mainwindow.h |
| client_secret | Le Secret Client de votre application Casdoor | mainwindow.h |
| certificate | La clé publique pour le certificat de l'application Casdoor | mainwindow.h |
| org_name | Le nom de votre organisation Casdoor | mainwindow.h |
| app_name | Le nom de votre application Casdoor | mainwindow.h |
| redirect_url | Le chemin de l'URL de rappel pour votre application Casdoor, sera http://localhost:8080/callback s'il n'est pas fourni | mainwindow.h |
Default endpoint: http://localhost:8000 if not set.
Running
Qt Creator
- Ouvrir
casdoor-cpp-qt-example.pro - Définir le
INCLUDEPATHd'OpenSSL danscasdoor-cpp-qt-example.pro - Appuyez sur
Ctrl + Rpour démarrer
Aperçu

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()));
Utilisation du code d'autorisation pour obtenir les informations de l'utilisateur
// Get the token and parse it with the JWT library
std::string token = m_casdoor->GetOAuthToken(code.toStdString());
auto decoded = m_casdoor->ParseJwtToken(token);