跳到主内容

Qt desktop app

The casdoor-cpp-qt-example shows Casdoor sign-in in a Qt desktop app.

Run the example

前置要求

初始化

Set these 7 string parameters:

名称描述文件
endpoint您的 Casdoor 服务器主机/域mainwindow.h
client_id您的 Casdoor 应用程序的客户端 IDmainwindow.h
client_secret你的Casdoor应用的客户端密钥mainwindow.h
certificateCasdoor 应用程序证书的公钥mainwindow.h
org_name您的Casdoor应用程序的名称mainwindow.h
app_name您的Casdoor应用程序的名称mainwindow.h
redirect_url您的Casdoor 应用程序的回调URL路径将是 casdoor://callback 如果没有提供mainwindow.h

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

Running

Qt Creator

  1. 打开casdoor-cpp-qt-example.pro
  2. casdoor-cpp-qt-example.pro中设置OpenSSL的INCLUDEPATH
  3. Ctrl + R开始

效果预览

索引

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

登录 user profile 预览 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()));

使用授权码获取用户信息

// 获取令牌并使用JWT库解析
std::string token = m_casdoor->GetOAuthToken(code.toStdString());
auto decoded = m_casdoor->ParseJwtToken(token);