libfuoten 0.8.2
Qt based library to access the Nextcloud News App API.
Loading...
Searching...
No Matches
Fuoten::LoginFlowV2 Class Reference

Manages the Login Flow v2 to request an application password. More...

#include <Fuoten/API/LoginFlowV2>

Inheritance diagram for Fuoten::LoginFlowV2:
Fuoten::Component QObject

Properties

int pollingInterval
 Sets the interval in seconds at which polling requests are sent to the server.
int pollingRequestTimeout
 Sets the timeout in seconds for single polling requests.
int pollingTimeout
 Sets the timeout in seconds at which the authorisation request has to be succeeded.
int secondsLeft
 This property holds the seconds left until the pollingTimeout timer times out.
Properties inherited from Fuoten::Component
Fuoten::AbstractConfigurationconfiguration
 Pointer to an AbstractConfiguration derived object.
Fuoten::Errorerror
 Pointer to an error object, if any error occurred.
bool inOperation
 Returns true while the request is in operation.
Fuoten::AbstractNotificatornotificator
 Pointer to an object derived from AbstractNotificator.
quint16 requestTimeout
 Timeout in seconds for network requests.
Fuoten::AbstractStoragestorage
 Pointer to an AbstractStorage derived object.
bool useStorage
 If true (the default), a local storage should be used in the successCallback() function to further process the request results.
Fuoten::WipeManagerwipeManager
 Pointer to a WipeManager to handle remote wipe requests.

Public Member Functions

 LoginFlowV2 (QObject *parent=nullptr)
 Constructs a new LoginFlowV2 object with the given parent.
 ~LoginFlowV2 () override
 Destroys the LoginFlowV2 object.
Q_INVOKABLE void execute () override
 Executes the API request.
int pollingInterval () const
 Returns the polling interval in seconds.
int pollingRequestTimeout () const
 Returns the timeout for the single polling requests in seconds.
int pollingTimeout () const
 Returns the polling timeout in seconds.
int secondsLeft () const
 Returns the remaining seconds until pollingTimeout times out.
void setPollingInterval (int pollingInterval)
 Sets the polling interval in seconds.
void setPollingRequestTimeout (int pollingRequestTimeout)
 Set the timeout for the single polling requests in seconsd.
void setPollingTimeout (int pollingTimeout)
 Sets the polling timeout in seconds.
Public Member Functions inherited from Fuoten::Component
 Component (QObject *parent=nullptr)
 Constructs a component with the given parent.
 ~Component () override
 Destroys the Component object.
AbstractConfigurationconfiguration () const
 Returns a pointer to the AbstractConfiguration that is currently set.
Errorerror () const
 Returns a pointer to an Error object, if any error occurred.
bool inOperation () const
 Returns true while the API request is running.
bool isUseStorageEnabled () const
 Getter function for the useStorage property.
AbstractNotificatornotificator () const
 Getter function for the notificator property.
quint16 requestTimeout () const
 Returns the currently set request timeout.
void setConfiguration (AbstractConfiguration *nAbstractConfiguration)
 Sets a pointer to a AbstractConfiguration to use for the API request.
void setNotificator (AbstractNotificator *notificator)
 Setter function for the notificator property.
void setRequestTimeout (quint16 seconds)
 Sets the timeout for the API request in seconds.
void setStorage (AbstractStorage *localStorage)
 Setter function for the storage property.
void setUseStorage (bool useStorage)
 Setter function for the useStorage property.
void setWipeManager (WipeManager *wipeManager)
 Setter function for the wipeManager property.
AbstractStoragestorage () const
 Getter function for the storage property.
WipeManagerwipeManager () const
 Getter function for the wipeManager property.

Signals

void gotLoginUrl (const QUrl &url)
 Emitted when the login url has been requested from the Nextcloud server.
void pollingIntervalChanged (int pollingInterval)
 Emitted when the pollingInterval has been changed.
void pollingRequestTimeoutChanged (int pollingRequestTimeout)
 Emitted when the pollingRequestTimeout has been changed.
void pollingTimeoutChanged (int pollingTimeout)
 Emitted when the pollingTimeout has been changed.
void secondsLeftChanged (int secondsLeft)
 Emitted every seconds when the polling is active.
Signals inherited from Fuoten::Component
void configurationChanged (Fuoten::AbstractConfiguration *configuration)
 This signal is emitted when the pointer to the AbstractConfiguration object changes.
void errorChanged (Fuoten::Error *error)
 This signal is emitted when the pointer to the Error object changes. error will be a nullptr if no error occurred or the current error has been reset.
void failed (Fuoten::Error *error)
 Emit this signal in a subclass when the request failed for some reason.
void inOperationChanged (bool inOperation)
 This signal is emitted when the in operation status changes.
void notificatorChanged (Fuoten::AbstractNotificator *notificator)
 Notifier signal for the notificator property.
void requestTimeoutChanged (quint16 requestTimeout)
 This signal is emitte when the timeout for the request changes.
void sslErrors (QNetworkReply *reply, const QList< QSslError > &errors)
 This signal is emitted if the SSL/TLS session encountered errors during the set up.
void storageChanged (Fuoten::AbstractStorage *storage)
 Notifier signal for the storage property.
void succeeded (const QJsonDocument &result)
 Emit this signal in a subclass when the request was successful.
void useStorageChanged (bool useStorage)
 Notifier signal for the useStorage property.
void wipeManagerChanged (Fuoten::WipeManager *wipeManager)
 Notifier signal for the wipeManager property.

Protected Member Functions

bool checkInput () override
 Always returns true.
void successCallback () override
 Extracts the login url and the polling data from the initial authorisation request.
Protected Member Functions inherited from Fuoten::Component
void addRequestHeader (const QByteArray &headerName, const QByteArray &headerValue)
 Adds a header to the HTTP request.
void addRequestHeaders (const QHash< QByteArray, QByteArray > &headers)
 Adds headers to the HTTP request.
virtual bool checkOutput ()
 Performs basic output checks.
virtual void extractError (QNetworkReply *reply)
 Extracts error data from the network reply.
QJsonDocument jsonResult () const
 Returns the JSON result document.
void notify (AbstractNotificator::Type type, QtMsgType severity, const QVariant &data) const
 Checks if a notificator has been set and will use it to notify the user.
void notify (const Error *e) const
 Checks if a notificator has been set and will use it to notify about an occured error.
QHash< QByteArray, QByteArrayrequestHeaders () const
 Returns the currently set HTTP headers for the request.
void sendRequest ()
 Sends the request to the server.
void setApiRoute (const QString &route)
 Sets the API route.
void setApiRoute (const QStringList &routeParts)
 Sets the API route constructed from a route part list.
void setError (Error *nError)
 Sets the pointer of the error property.
void setExpectedJSONType (ExpectedJSONType type)
 Sets the expected JSON type for initial output check.
void setInOperation (bool nInOperation)
 Sets the value of the inOperation property.
void setNetworkOperation (QNetworkAccessManager::Operation operation)
 Sets the operation the network manager should perform for this call.
void setPayload (const QByteArray &payload)
 Sets the payload for the request.
void setPayload (const QJsonObject &payload)
 Sets the payload for the request.
void setRequestHeaders (const QHash< QByteArray, QByteArray > &headers)
 Sets the headers to use for the HTTP request.
void setRequiresAuth (bool reqAuth)
 Set this to true if the request requires authentication.
void setUrlQuery (const QUrlQuery &query)
 Sets the URL query for the request.

Additional Inherited Members

Public Types inherited from Fuoten::Component
enum  ExpectedJSONType : quint8 { Empty = 0 , Array = 1 , Object = 2 }
 Defines the expected JSON type. More...
Static Public Member Functions inherited from Fuoten::Component
static AbstractConfigurationdefaultConfiguration ()
 Returns the global default configuration.
static QNetworkAccessManagerdefaultNam ()
 Returns the global network access manager.
static AbstractNotificatordefaultNotificator ()
 Returns the global default notificator.
static AbstractStoragedefaultStorage ()
 Returns the global default storage.
static WipeManagerdefaultWipeManager ()
 Returns the global default wipe manager.
static AbstractNamFactorynetworkAccessManagerFactory ()
 Returns the currently set network access manager factory.
static void setDefaultConfiguration (AbstractConfiguration *config)
 Sets the global default configuration.
static void setDefaultNam (QNetworkAccessManager *nam)
 Sets the global default network access manager.
static void setDefaultNotificator (AbstractNotificator *notificator)
 Sets the global default notificator.
static void setDefaultStorage (AbstractStorage *storage)
 Sets the global default storage.
static void setDefaultWipeManager (WipeManager *wipeManager)
 Sets the global default wipe manager.
static void setNetworkAccessManagerFactory (AbstractNamFactory *factory)
 Sets the network access manager factory. The factory will be used to create QNetworkAccessManager objects on demand. If no factory is set, a default QNetworkAccessManager object will be created. The Component class will take ownership of the created QNetworkAccessManager.

Detailed Description

Manages the Login Flow v2 to request an application password.

Nextcloud’s Login Flow can be used to request login credentials specific to every single client. This will assure that each client gets its own set of credentials and has the advantage that a client never stores the password of the user and that the user can revoke access on a per client basis from the web.

This class helps to use the Login Flow v2 that uses an external browser window (normally the user’s default browser) to request login credentials. The Nextcloud server to request the credentials from is read from Component::configuration, so there has to be at least the host information be set. You should also reimplement AbstractConfiguration::getLoginFlowUserAgent() because it is used to show the user a descriptive name of the application that requests the login credentials.

The first request will be sent to <server>/index.php/login/v2 to get the login url opened in the external browser and to the polling endpoint and the polling token. If that was successful, gotLoginUrl() will be emitted that will also have the login url for the user.

Directly after emitting gotLoginUrl() the polling for the credentials starts while the user authorizes the application. If the authorization succeedes, the requested credentials will be stored with AbstractConfiguration::setLoginFlowCredentials(), also the Component::succeeded() signal will be emitted containing the retreived JSON credential data.

If something failed, Component::failed() will be emitted and Component::error() will contain the Error data object.

Since
0.8.0
Mandatory properties
Component::configuration
API route
Not part of the News App API, uses general Nextcloud API at /index.php/login/v2
Method
POST

Property Documentation

◆ pollingInterval

int Fuoten::LoginFlowV2::pollingInterval
readwrite

Sets the interval in seconds at which polling requests are sent to the server.

The default value is 2 seconds. Unless the pollingTimeout timer times out or the authorization succeeded, n seconds after the last successful polling request, a new polling request will be sent.

Access functions:
boolpollingInterval() const
voidsetPollingInterval(int pollingInterval)
Notifier signal:
voidpollingIntervalChanged(int pollingInterval)

◆ pollingRequestTimeout

int Fuoten::LoginFlowV2::pollingRequestTimeout
readwrite

Sets the timeout in seconds for single polling requests.

The default value is 5 seconds. Every single polling request will time out after the set seconds if it does not receive an answer. After 5 consecutive timeouts, the login flow will be canceled, Component::error() will return a valid Error object and the Component::failed() signal will be emitted.

Access functions:
boolpollingRequestTimeout() const
voidsetPollingRequestTimeout(int pollingRequestTimeout)
Notifier signal:
voidpollingRequestTimeoutChanged(int pollingRequestTimeout)

◆ pollingTimeout

int Fuoten::LoginFlowV2::pollingTimeout
readwrite

Sets the timeout in seconds at which the authorisation request has to be succeeded.

The default value is 300 seconds. If this timeout expires, the login flow will be canceled and polling will be stopped. Component::error() will return a valid Error object and the Component::failed() signal will be emitted.

This property can not be changed while Component::inOperation() returns true.

Access functions:
boolpollingTimeout() const
voidsetPollingTimeout(int pollingTimeout)
Notifier signal:
voidpollingTimeoutChanged(int pollingTimeout)
See also
secondsLeft

◆ secondsLeft

int Fuoten::LoginFlowV2::secondsLeft
read

This property holds the seconds left until the pollingTimeout timer times out.

The default value is 0. While polling runs, secondsLeftChanged() will be emitted every second.

Access functions:
boolsecondsLeft() const
Notifier signal:
voidsecondsLeftChanged(int secondsLeft)
See also
pollingTimeout

Constructor & Destructor Documentation

◆ LoginFlowV2()

LoginFlowV2::LoginFlowV2 ( QObject * parent = nullptr)
explicit

Constructs a new LoginFlowV2 object with the given parent.

◆ ~LoginFlowV2()

LoginFlowV2::~LoginFlowV2 ( )
override

Destroys the LoginFlowV2 object.

Member Function Documentation

◆ checkInput()

bool LoginFlowV2::checkInput ( )
overrideprotectedvirtual

Always returns true.

Reimplemented from Fuoten::Component.

◆ execute()

void LoginFlowV2::execute ( )
overridevirtual

Executes the API request.

Implements Fuoten::Component.

◆ gotLoginUrl

void Fuoten::LoginFlowV2::gotLoginUrl ( const QUrl & url)
signal

Emitted when the login url has been requested from the Nextcloud server.

The emitted url should be opened by a web browser to load and show the authorization login page to the user. This signal is emitted in the successCallback().

◆ pollingInterval()

int LoginFlowV2::pollingInterval ( ) const

Returns the polling interval in seconds.

See also
pollingInterval, setPollingInterval(), pollingIntervalChanged()

◆ pollingIntervalChanged

void Fuoten::LoginFlowV2::pollingIntervalChanged ( int pollingInterval)
signal

Emitted when the pollingInterval has been changed.

See also
pollingInterval, pollingInterval(), setPollingInterval()

◆ pollingRequestTimeout()

int LoginFlowV2::pollingRequestTimeout ( ) const

Returns the timeout for the single polling requests in seconds.

See also
pollingRequestTimeout, setPollingRequestTimeout(), pollingRequestTimeoutChanged()

◆ pollingRequestTimeoutChanged

void Fuoten::LoginFlowV2::pollingRequestTimeoutChanged ( int pollingRequestTimeout)
signal

◆ pollingTimeout()

int LoginFlowV2::pollingTimeout ( ) const

Returns the polling timeout in seconds.

See also
pollingTimeout, setPollingTimeout(), pollingTimeoutChanged()

◆ pollingTimeoutChanged

void Fuoten::LoginFlowV2::pollingTimeoutChanged ( int pollingTimeout)
signal

Emitted when the pollingTimeout has been changed.

See also
pollingTimeout, pollingTimeout(), setPollingTimeout()

◆ secondsLeft()

int LoginFlowV2::secondsLeft ( ) const

Returns the remaining seconds until pollingTimeout times out.

The default value is 0.

See also
secondsLeft, secondsLeftChanged()

◆ secondsLeftChanged

void Fuoten::LoginFlowV2::secondsLeftChanged ( int secondsLeft)
signal

Emitted every seconds when the polling is active.

The secondsLeft are the remaining seconds until the pollingTimeout times out.

See also
secondsLeft, secondsLeft()

◆ setPollingInterval()

void LoginFlowV2::setPollingInterval ( int pollingInterval)

Sets the polling interval in seconds.

See also
pollingInterval, pollingInterval(), pollingIntervalChanged()

◆ setPollingRequestTimeout()

void LoginFlowV2::setPollingRequestTimeout ( int pollingRequestTimeout)

Set the timeout for the single polling requests in seconsd.

See also
pollingRequestTimeout, pollingRequestTimeout(), pollingRequestTimeoutChanged();

◆ setPollingTimeout()

void LoginFlowV2::setPollingTimeout ( int pollingTimeout)

Sets the polling timeout in seconds.

See also
pollingTimeout, pollingTimeout(), pollingTimeoutChanged()

◆ successCallback()

void LoginFlowV2::successCallback ( )
overrideprotectedvirtual

Extracts the login url and the polling data from the initial authorisation request.

If the returned data is valid, gotLoginUrl() will be emitted an the polling for the application password start immediatly.

Implements Fuoten::Component.


The documentation for this class was generated from the following files:
  • Fuoten/API/loginflowv2.h
  • build/Fuoten/FuotenQt5_autogen/include/moc_loginflowv2.cpp
  • Fuoten/API/loginflowv2.cpp