Hanzo
PlatformHanzo IAMConnecting to IAMDesktop SDKs

Qt desktop app

Integrate Hanzo IAM in a Qt (C++) desktop app with WebEngine.

The iam-cpp-qt-example shows Hanzo IAM sign-in in a Qt desktop app.

Run the example

Prerequisites

Initialization

Set these 7 string parameters:

NameDescriptionFile
endpointYour Hanzo IAM server host/domainmainwindow.h
client_idThe Client ID of your Hanzo IAM applicationmainwindow.h
client_secretThe Client Secret of your Hanzo IAM applicationmainwindow.h
certificateThe public key for the Hanzo IAM application's certmainwindow.h
org_nameThe name of your Hanzo IAM organizationmainwindow.h
app_nameThe name of your Hanzo IAM applicationmainwindow.h
redirect_urlThe path of the callback URL for your Hanzo IAM application, will be http://localhost:8080/callback if not providedmainwindow.h

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

Running

Qt Creator

  1. Open iam-cpp-qt-example.pro
  2. Set the INCLUDEPATH of OpenSSL in iam-cpp-qt-example.pro
  3. Press Ctrl + R to start

Preview

index

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

login user profile preview gif

Integration

Open the login window

// Load and display the login page of Hanzo IAM
m_webview->page()->load(*m_signin_url);
m_webview->show();

### Listen for the callback (TCP)

```cpp
// 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()));

### Using Auth Code to Get the User Info

```cpp
// Get the token and parse it with the JWT library
std::string token = m_iam->GetOAuthToken(code.toStdString());
auto decoded = m_iam->ParseJwtToken(token);

How is this guide?

Last updated on

On this page