Passer au contenu principal

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:

NomDescriptionFichier
endpointVotre hôte/domaine de serveur Casdoormainwindow.h
client_idL'ID client de votre application Casdoormainwindow.h
client_secretLe Secret Client de votre application Casdoormainwindow.h
certificateLa clé publique pour le certificat de l'application Casdoormainwindow.h
org_nameLe nom de votre organisation Casdoormainwindow.h
app_nameLe nom de votre application Casdoormainwindow.h
redirect_urlLe chemin de l'URL de rappel pour votre application Casdoor, sera http://localhost:8080/callback s'il n'est pas fournimainwindow.h

Default endpoint: http://localhost:8000 if not set.

Running

Qt Creator

  1. Ouvrir casdoor-cpp-qt-example.pro
  2. Définir le INCLUDEPATH d'OpenSSL dans casdoor-cpp-qt-example.pro
  3. Appuyez sur Ctrl + R pour démarrer

Aperçu

index

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

connexion user profile aperçu gif

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);