Qt desktop app
The casdoor-cpp-qt-example shows Casdoor sign-in in a Qt desktop app.
Run the example
Prerrequisitos
Inicialización
Set these 7 string parameters:
| Nombre | Descripción | Archivo |
|---|---|---|
| endpoint | El host/dominio de tu servidor Casdoor | mainwindow.h |
| client_id | El ID de Cliente de tu aplicación Casdoor | mainwindow.h |
| client_secret | El Secreto de Cliente de tu aplicación Casdoor | mainwindow.h |
| certificate | La clave pública para el certificado de la aplicación Casdoor | mainwindow.h |
| org_name | El nombre de tu organización Casdoor | mainwindow.h |
| app_name | El nombre de tu aplicación Casdoor | mainwindow.h |
| redirect_url | La ruta de la URL de callback para tu aplicación Casdoor, será http://localhost:8080/callback si no se proporciona | mainwindow.h |
Default endpoint: http://localhost:8000 if not set.
Running
Qt Creator
- Abrir
casdoor-cpp-qt-example.pro - Establecer el
INCLUDEPATHde OpenSSL encasdoor-cpp-qt-example.pro - Presiona
Ctrl + Rpara iniciar
Vista previa

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()));
Usando el Código de Autorización para Obtener la Información del Usuario
// Get the token and parse it with the JWT library
std::string token = m_casdoor->GetOAuthToken(code.toStdString());
auto decoded = m_casdoor->ParseJwtToken(token);