private/RequestHandlerPrivate.cpp
/** ************************************************************************************************
    * @brief        Initialize the object.
    *
    * @details      This must be called in the thread in which the object lives (using invokeMethod).
    ***************************************************************************************************/
@brief        Initialize the object.
@details      This must be called in the thread in which the object lives (using invokeMethod).
@brief Initialize the object . @details This must be called in the thread in which the object lives ( using invokeMethod ) .
void RequestHandlerPrivate::init()
    {
        m_networkAccessManager = std::make_unique<QNetworkAccessManager>(this);
        m_authManager = std::make_unique<QOAuth2AuthorizationCodeFlow>(m_networkAccessManager.get(), this);
        m_replyHandler = std::make_unique<QOAuthHttpServerReplyHandler>(m_replyPort, this);
        m_authManager->setReplyHandler(m_replyHandler.get());
        m_authManager->setAuthorizationUrl(AUTHORIZATION_URL);
        m_authManager->setAccessTokenUrl(TOKEN_ACCESS_URL);
        m_authManager->setClientIdentifier(m_clientId);
        m_authManager->setClientIdentifierSharedKey(m_clientSecret);
        QString scope;
        for (const QString &scopeItem: REQUEST_SCOPE)
        {
            if (!scopeItem.isEmpty())
            {
                scope += scopeItem + " ";
            }
        }
        scope.chop(1); 
        m_authManager->setScope(scope);
        connect(m_authManager.get(), &QOAuth2AuthorizationCodeFlow::authorizeWithBrowser,
                this,                &QDesktopServices::openUrl);
        connect(m_authManager.get(), &QOAuth2AuthorizationCodeFlow::granted,
                this,                &RequestHandlerPrivate::onAccessGranted);
        connect(&m_tokenRefreshTimer, &QTimer::timeout, this, &RequestHandlerPrivate::refreshToken);
        m_tokenRefreshTimer.setInterval(std::chrono::minutes(5));
        m_tokenRefreshTimer.setSingleShot(true);
        connect(thread(), &QThread::finished, &m_tokenRefreshTimer, &QTimer::stop);
    }
void RequestHandlerPrivate :: init ( ) { m_networkAccessManager = std :: make_unique < QNetworkAccessManager > ( this ) ; m_authManager = std :: make_unique < QOAuth2AuthorizationCodeFlow > ( m_networkAccessManager . get ( ) , this ) ; m_replyHandler = std :: make_unique < QOAuthHttpServerReplyHandler > ( m_replyPort , this ) ; m_authManager -> setReplyHandler ( m_replyHandler . get ( ) ) ; m_authManager -> setAuthorizationUrl ( AUTHORIZATION_URL ) ; m_authManager -> setAccessTokenUrl ( TOKEN_ACCESS_URL ) ; m_authManager -> setClientIdentifier ( m_clientId ) ; m_authManager -> setClientIdentifierSharedKey ( m_clientSecret ) ; QString scope ; for ( const QString & scopeItem : REQUEST_SCOPE ) { if ( ! scopeItem . isEmpty ( ) ) { scope += scopeItem + " " ; } } scope . chop ( 1 ) ; m_authManager -> setScope ( scope ) ; connect ( m_authManager . get ( ) , & QOAuth2AuthorizationCodeFlow :: authorizeWithBrowser , this , & QDesktopServices :: openUrl ) ; connect ( m_authManager . get ( ) , & QOAuth2AuthorizationCodeFlow :: granted , this , & RequestHandlerPrivate :: onAccessGranted ) ; connect ( & m_tokenRefreshTimer , & QTimer :: timeout , this , & RequestHandlerPrivate :: refreshToken ) ; m_tokenRefreshTimer . setInterval ( std :: chrono :: minutes ( 5 ) ) ; m_tokenRefreshTimer . setSingleShot ( true ) ; connect ( thread ( ) , & QThread :: finished , & m_tokenRefreshTimer , & QTimer :: stop ) ; }
@brief        Initialize the object.
@brief Initialize the object .
// Build the scope list for each available request type. // Remove the final space. // Open a webpage for login authorization. // Handle successful access. // Refresh token periodically. // When the thread is stopped, stop the timer.