onedrive: Fix authentication
Discontinue use of obsolete auth endpoints. Update the name of the settings group as well since the existing skydrive settings are no longer useful. Reference: https://docs.microsoft.com/en-us/onedrive/developer/rest-api/concepts/migrating-from-live-sdk
This commit is contained in:
parent
565110e223
commit
7b5d2fd79f
@ -102,15 +102,17 @@ QByteArray OAuthenticator::ParseHttpRequest(const QByteArray& request) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OAuthenticator::RequestAccessToken(const QByteArray& code,
|
void OAuthenticator::RequestAccessToken(const QByteArray& code,
|
||||||
const QUrl& url) {
|
const QUrl& redirect_url) {
|
||||||
typedef QPair<QString, QString> Param;
|
typedef QPair<QString, QString> Param;
|
||||||
QList<Param> parameters;
|
QList<Param> parameters;
|
||||||
parameters << Param("code", code) << Param("client_id", client_id_)
|
parameters << Param("code", code) << Param("client_id", client_id_)
|
||||||
<< Param("client_secret", client_secret_)
|
|
||||||
<< Param("grant_type", "authorization_code")
|
<< Param("grant_type", "authorization_code")
|
||||||
// Even though we don't use this URI anymore, it must match the
|
// Even though we don't use this URI anymore, it must match the
|
||||||
// original one.
|
// original one.
|
||||||
<< Param("redirect_uri", url.toString());
|
<< Param("redirect_uri", redirect_url.toString());
|
||||||
|
if (!client_secret_.isEmpty()) {
|
||||||
|
parameters << Param("client_secret", client_secret_);
|
||||||
|
}
|
||||||
|
|
||||||
QStringList params;
|
QStringList params;
|
||||||
for (const Param& p : parameters) {
|
for (const Param& p : parameters) {
|
||||||
|
@ -74,7 +74,7 @@ class OAuthenticator : public QObject {
|
|||||||
static const char* kRemoteURL;
|
static const char* kRemoteURL;
|
||||||
|
|
||||||
QByteArray ParseHttpRequest(const QByteArray& request) const;
|
QByteArray ParseHttpRequest(const QByteArray& request) const;
|
||||||
void RequestAccessToken(const QByteArray& code, const QUrl& url);
|
void RequestAccessToken(const QByteArray& code, const QUrl& redirect_url);
|
||||||
void SetExpiryTime(int expires_in_seconds);
|
void SetExpiryTime(int expires_in_seconds);
|
||||||
|
|
||||||
NetworkAccessManager network_;
|
NetworkAccessManager network_;
|
||||||
|
@ -36,14 +36,16 @@ namespace {
|
|||||||
|
|
||||||
static const char* kServiceId = "skydrive";
|
static const char* kServiceId = "skydrive";
|
||||||
|
|
||||||
static const char* kClientId = "0000000040111F16";
|
static const char* kClientId = "905def38-34d2-4e32-8ba7-c37bcc329047";
|
||||||
static const char* kClientSecret = "w2ClguSX0jG56cBl1CeUniypTBRjXt2Z";
|
static const char* kClientSecret = "";
|
||||||
|
|
||||||
|
// https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow
|
||||||
static const char* kOAuthEndpoint =
|
static const char* kOAuthEndpoint =
|
||||||
"https://login.live.com/oauth20_authorize.srf";
|
"https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
|
||||||
static const char* kOAuthTokenEndpoint =
|
static const char* kOAuthTokenEndpoint =
|
||||||
"https://login.live.com/oauth20_token.srf";
|
"https://login.microsoftonline.com/common/oauth2/v2.0/token";
|
||||||
static const char* kOAuthScope = "wl.basic wl.skydrive wl.offline_access";
|
static const char* kOAuthScope =
|
||||||
|
"User.Read Files.Read Files.Read.All offline_access";
|
||||||
|
|
||||||
static const char* kLiveUserInfo = "https://apis.live.net/v5.0/me";
|
static const char* kLiveUserInfo = "https://apis.live.net/v5.0/me";
|
||||||
static const char* kSkydriveBase = "https://apis.live.net/v5.0/";
|
static const char* kSkydriveBase = "https://apis.live.net/v5.0/";
|
||||||
@ -51,7 +53,7 @@ static const char* kSkydriveBase = "https://apis.live.net/v5.0/";
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
const char* SkydriveService::kServiceName = "OneDrive";
|
const char* SkydriveService::kServiceName = "OneDrive";
|
||||||
const char* SkydriveService::kSettingsGroup = "Skydrive";
|
const char* SkydriveService::kSettingsGroup = "OneDrive";
|
||||||
|
|
||||||
SkydriveService::SkydriveService(Application* app, InternetModel* parent)
|
SkydriveService::SkydriveService(Application* app, InternetModel* parent)
|
||||||
: CloudFileService(app, parent, kServiceName, kServiceId,
|
: CloudFileService(app, parent, kServiceName, kServiceId,
|
||||||
@ -73,7 +75,7 @@ QString SkydriveService::refresh_token() const {
|
|||||||
|
|
||||||
void SkydriveService::Connect() {
|
void SkydriveService::Connect() {
|
||||||
OAuthenticator* oauth = new OAuthenticator(
|
OAuthenticator* oauth = new OAuthenticator(
|
||||||
kClientId, kClientSecret, OAuthenticator::RedirectStyle::REMOTE, this);
|
kClientId, kClientSecret, OAuthenticator::RedirectStyle::LOCALHOST, this);
|
||||||
if (!refresh_token().isEmpty()) {
|
if (!refresh_token().isEmpty()) {
|
||||||
oauth->RefreshAuthorisation(kOAuthTokenEndpoint, refresh_token());
|
oauth->RefreshAuthorisation(kOAuthTokenEndpoint, refresh_token());
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user