/usr/include/qt5qevercloud/oauth.h is in qt5qevercloud-dev 3.0.3+ds-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | /**
* Original work: Copyright (c) 2014 Sergey Skoblikov
* Modified work: Copyright (c) 2015-2016 Dmitry Ivanov
*
* This file is a part of QEverCloud project and is distributed under the terms of MIT license:
* https://opensource.org/licenses/MIT
*/
#ifndef QEVERCLOUD_OAUTH_H
#define QEVERCLOUD_OAUTH_H
// Workarounding https://bugreports.qt.io/browse/QTBUG-28885
#if defined(_MSC_VER) && (_MSC_VER <= 1600)
#define QT_NO_UNICODE_LITERAL
#endif
#include "generated/types.h"
#include "export.h"
#include "qt4helpers.h"
#include <QDialog>
#include <QString>
namespace qevercloud {
/**
* @brief Sets the function to use for nonce generation for OAuth authentication.
*
* The default algorithm uses qrand() so do not forget to call qsrand() in your application!
*
* qrand() is not guaranteed to be cryptographically strong. I try to amend the fact by using
* QUuid::createUuid() which uses /dev/urandom if it's availabe. But this is no guarantee either.
* So if you want total control over nonce generation you can write you own algorithm.
*
* setNonceGenerator is NOT thread safe.
*/
void setNonceGenerator(quint64 (*nonceGenerator)());
/** @cond HIDDEN_SYMBOLS */
class EvernoteOAuthWebViewPrivate;
/** @endcond */
/**
* @brief The class is tailored specifically for OAuth authorization with Evernote.
*
* While it is functional by itself you probably will prefer to use EvernoteOAuthDialog.
*
* %Note that you have to include QEverCloudOAuth.h header.
*
* By deafult EvernoteOAuthWebView uses qrand() for generating nonce so do not forget to call qsrand()
* in your application. See @link setNonceGenerator @endlink If you want more control over nonce generation.
*/
class QEVERCLOUD_EXPORT EvernoteOAuthWebView: public QWidget
{
Q_OBJECT
public:
EvernoteOAuthWebView(QWidget * parent = Q_NULLPTR);
/**
* This function starts the OAuth sequence. In the end of the sequence will be emitted one of the signals: authenticationSuceeded or authenticationFailed.
*
* Do not call the function while its call is in effect, i.e. one of the signals is not emitted.
*
* @param host
* Evernote host to authorize with. You need one of this:
* <ul>
* <li>"www.evernote.com" - the production service. It's the default value.</li>
* <li>"sandox.evernote.com" - the developers "sandbox" service</li>
* </ul>
* @param consumerKey
* get it <a href="http://dev.evernote.com/doc/">from the Evernote</a>
* @param consumerSecret
* along with this
*/
void authenticate(QString host, QString consumerKey, QString consumerSecret);
/** @return true if the last call to authenticate resulted in a successful authentication. */
bool isSucceeded() const;
/** @return error message resulted from the last call to authenticate */
QString oauthError() const;
/** Holds data that is returned by Evernote on a succesful authentication */
struct OAuthResult
{
QString noteStoreUrl; ///< note store url for the user; no need to question UserStore::getNoteStoreUrl for it.
Timestamp expires; ///< authenticationToken time of expiration.
QString shardId; ///< usually is not used
UserID userId; ///< same as PublicUserInfo::userId
QString webApiUrlPrefix; ///< see PublicUserInfo::webApiUrlPrefix
QString authenticationToken; ///< This is what this all was for!
};
/** @returns the result of the last authentication, i.e. authenticate() call.*/
OAuthResult oauthResult() const;
/** The method is useful to specify default size for a EverOAuthWebView. */
void setSizeHint(QSize sizeHint);
virtual QSize sizeHint() const Q_DECL_OVERRIDE;
Q_SIGNALS:
/** Emitted when the OAuth sequence started with authenticate() call is finished */
void authenticationFinished(bool success);
/** Emitted when the OAuth sequence is succesfully finished. Call oauthResult() to get the data.*/
void authenticationSuceeded();
/** Emitted when the OAuth sequence is finished with a failure. Some error info may be availabe with errorText().*/
void authenticationFailed();
private:
EvernoteOAuthWebViewPrivate * const d_ptr;
Q_DECLARE_PRIVATE(EvernoteOAuthWebView)
};
/** @cond HIDDEN_SYMBOLS */
class EvernoteOAuthDialogPrivate;
/** @endcond */
/**
* @brief Authorizes your app with the Evernote service by means of OAuth authentication.
*
* Intended usage:
*
@code
#include <QEverCloudOAuth.h>
OAuthDialog d(myConsumerKey, myConsumerSecret);
if(d.exec() == QDialog::Accepted) {
OAuthDialog::OAuthResult res = d.oauthResult();
// Connect to Evernote
...
} else {
QString errorText = d.oauthError();
// handle an authentication error
...
}
@endcode
*
* %Note that you have to include QEverCloudOAuth.h header.
*
* By default EvernoteOAuthDialog uses qrand() for generating nonce so do not forget to call qsrand()
* in your application. See @link setNonceGenerator @endlink If you want more control over nonce generation.
*/
class QEVERCLOUD_EXPORT EvernoteOAuthDialog: public QDialog
{
public:
typedef EvernoteOAuthWebView::OAuthResult OAuthResult;
/** Constructs the dialog.
*
* @param host
* Evernote host to authorize with. You need one of this:
* <ul>
* <li>"www.evernote.com" - the production service. It's the default value.</li>
* <li>"sandox.evernote.com" - the developers "sandbox" service</li>
* </ul>
* @param consumerKey
* get it <a href="http://dev.evernote.com/doc/">from the Evernote</a>
* @param consumerSecret
* along with this
*/
EvernoteOAuthDialog(QString consumerKey, QString consumerSecret, QString host = QStringLiteral("www.evernote.com"), QWidget * parent = Q_NULLPTR);
~EvernoteOAuthDialog();
/**
* The dialog adjusts its initial size automatically based on the conatined QWebView preffered size.
* Use this method to set the size.
*
* @param sizeHint will be used as the preffered size of the contained QWebView.
*/
void setWebViewSizeHint(QSize sizeHint);
/** @return true in case of a succesful authentication.
* You probably better chech exec() return value instead.
*/
bool isSucceeded() const;
/**
* @return In case of an authentification error may return some information about the error.
*/
QString oauthError() const;
/**
* @return the result of a succesful authentication.
*/
OAuthResult oauthResult() const;
/**
* @return
* QDialog::Accepted on a succesful authentication.
*/
#if QT_VERSION < 0x050000
int exec();
#else
virtual int exec() Q_DECL_OVERRIDE;
#endif
/** Shows the dialog as a window modal dialog, returning immediately.
*/
#if QT_VERSION < 0x050000
void open();
#else
virtual void open() Q_DECL_OVERRIDE;
#endif
private:
EvernoteOAuthDialogPrivate * const d_ptr;
Q_DECLARE_PRIVATE(EvernoteOAuthDialog)
};
} // namespace qevercloud
#endif // QEVERCLOUD_OAUTH_H
|