libfuoten 0.8.1
Qt based library to access the ownCloud/Nextcloud News App API
Loading...
Searching...
No Matches
LoginFlowV2 Class Reference

#include <Fuoten/API/LoginFlowV2>

Inheritance diagram for LoginFlowV2:
Component

Properties

int pollingInterval
int pollingRequestTimeout
int pollingTimeout
int secondsLeft
Properties inherited from Component
Fuoten::AbstractConfigurationconfiguration
Fuoten::Errorerror
bool inOperation
Fuoten::AbstractNotificatornotificator
quint16 requestTimeout
Fuoten::AbstractStoragestorage
bool useStorage
Fuoten::WipeManagerwipeManager

Public Member Functions

 LoginFlowV2 (QObject *parent=nullptr)
 ~LoginFlowV2 () override
Q_INVOKABLE void execute () override
int pollingInterval () const
int pollingRequestTimeout () const
int pollingTimeout () const
int secondsLeft () const
void setPollingInterval (int pollingInterval)
void setPollingRequestTimeout (int pollingRequestTimeout)
void setPollingTimeout (int pollingTimeout)
Public Member Functions inherited from Component
 Component (QObject *parent=nullptr)
 ~Component () override
AbstractConfigurationconfiguration () const
Errorerror () const
bool inOperation () const
bool isUseStorageEnabled () const
AbstractNotificatornotificator () const
quint16 requestTimeout () const
void setConfiguration (AbstractConfiguration *nAbstractConfiguration)
void setNotificator (AbstractNotificator *notificator)
void setRequestTimeout (quint16 seconds)
void setStorage (AbstractStorage *localStorage)
void setUseStorage (bool useStorage)
void setWipeManager (WipeManager *wipeManager)
AbstractStoragestorage () const
WipeManagerwipeManager () const

Signals

void gotLoginUrl (const QUrl &url)
void pollingIntervalChanged (int pollingInterval)
void pollingRequestTimeoutChanged (int pollingRequestTimeout)
void pollingTimeoutChanged (int pollingTimeout)
void secondsLeftChanged (int secondsLeft)
Signals inherited from Component
void configurationChanged (Fuoten::AbstractConfiguration *configuration)
void errorChanged (Fuoten::Error *error)
void failed (Fuoten::Error *error)
void inOperationChanged (bool inOperation)
void notificatorChanged (Fuoten::AbstractNotificator *notificator)
void requestTimeoutChanged (quint16 requestTimeout)
void sslErrors (QNetworkReply *reply, const QList< QSslError > &errors)
void storageChanged (Fuoten::AbstractStorage *storage)
void succeeded (const QJsonDocument &result)
void useStorageChanged (bool useStorage)
void wipeManagerChanged (Fuoten::WipeManager *wipeManager)

Protected Member Functions

bool checkInput () override
void successCallback () override
Protected Member Functions inherited from Component
void addRequestHeader (const QByteArray &headerName, const QByteArray &headerValue)
void addRequestHeaders (const QHash< QByteArray, QByteArray > &headers)
virtual bool checkOutput ()
virtual void extractError (QNetworkReply *reply)
QJsonDocument jsonResult () const
void notify (AbstractNotificator::Type type, QtMsgType severity, const QVariant &data) const
void notify (const Error *e) const
QHash< QByteArray, QByteArray > requestHeaders () const
void sendRequest ()
void setApiRoute (const QString &route)
void setApiRoute (const QStringList &routeParts)
void setError (Error *nError)
void setExpectedJSONType (ExpectedJSONType type)
void setInOperation (bool nInOperation)
void setNetworkOperation (QNetworkAccessManager::Operation operation)
void setPayload (const QByteArray &payload)
void setPayload (const QJsonObject &payload)
void setRequestHeaders (const QHash< QByteArray, QByteArray > &headers)
void setRequiresAuth (bool reqAuth)
void setUrlQuery (const QUrlQuery &query)

Additional Inherited Members

Public Types inherited from Component
enum  ExpectedJSONType : quint8 { Empty = 0 , Array = 1 , Object = 2 }
Static Public Member Functions inherited from Component
static AbstractConfigurationdefaultConfiguration ()
static AbstractNotificatordefaultNotificator ()
static AbstractStoragedefaultStorage ()
static WipeManagerdefaultWipeManager ()
static AbstractNamFactorynetworkAccessManagerFactory ()
static void setDefaultConfiguration (AbstractConfiguration *config)
static void setDefaultNotificator (AbstractNotificator *notificator)
static void setDefaultStorage (AbstractStorage *storage)
static void setDefaultWipeManager (WipeManager *wipeManager)
static void setNetworkAccessManagerFactory (AbstractNamFactory *factory)

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 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 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 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 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 ( QObject * parent = nullptr)
explicit

Constructs a new LoginFlowV2 object with the given parent.

◆ ~LoginFlowV2()

~LoginFlowV2 ( )
override

Destroys the LoginFlowV2 object.

Member Function Documentation

◆ checkInput()

bool checkInput ( )
overrideprotectedvirtual

Always returns true.

Reimplemented from Component.

◆ execute()

void execute ( )
overridevirtual

Executes the API request.

Implements Component.

◆ gotLoginUrl

void 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 pollingInterval ( ) const

Returns the polling interval in seconds.

See also
pollingInterval, setPollingInterval(), pollingIntervalChanged()

◆ pollingIntervalChanged

void pollingIntervalChanged ( int pollingInterval)
signal

Emitted when the pollingInterval has been changed.

See also
pollingInterval, pollingInterval(), setPollingInterval()

◆ pollingRequestTimeout()

int pollingRequestTimeout ( ) const

Returns the timeout for the single polling requests in seconds.

See also
pollingRequestTimeout, setPollingRequestTimeout(), pollingRequestTimeoutChanged()

◆ pollingRequestTimeoutChanged

void pollingRequestTimeoutChanged ( int pollingRequestTimeout)
signal

◆ pollingTimeout()

int pollingTimeout ( ) const

Returns the polling timeout in seconds.

See also
pollingTimeout, setPollingTimeout(), pollingTimeoutChanged()

◆ pollingTimeoutChanged

void pollingTimeoutChanged ( int pollingTimeout)
signal

Emitted when the pollingTimeout has been changed.

See also
pollingTimeout, pollingTimeout(), setPollingTimeout()

◆ secondsLeft()

int secondsLeft ( ) const

Returns the remaining seconds until pollingTimeout times out.

The default value is 0.

See also
secondsLeft, secondsLeftChanged()

◆ secondsLeftChanged

void 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 setPollingInterval ( int pollingInterval)

Sets the polling interval in seconds.

See also
pollingInterval, pollingInterval(), pollingIntervalChanged()

◆ setPollingRequestTimeout()

void setPollingRequestTimeout ( int pollingRequestTimeout)

Set the timeout for the single polling requests in seconsd.

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

◆ setPollingTimeout()

void setPollingTimeout ( int pollingTimeout)

Sets the polling timeout in seconds.

See also
pollingTimeout, pollingTimeout(), pollingTimeoutChanged()

◆ successCallback()

void 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 Component.