Skip to content

Commit

Permalink
fix GoogleDrive auth problem
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterSoft24 committed Nov 28, 2020
1 parent 12c651e commit a61248e
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build/*
*.pro.user*
ccross-fuse/*
ccross-fuse-worker/*
.directory
3 changes: 3 additions & 0 deletions CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Change log:

### v1.4.7
- fix GoogleDrive auth problem (**WARNING!! This version has a new Google API Key, and this means that a previous GoogleDrive auth will be broken**)

### v1.4.6
- fix console log printing and segfaults caused by it
### v1.4.5
Expand Down
10 changes: 8 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# The CloudCross Project

## Current version: 1.4.6
Release date: **2020-01-16**
## Current version: 1.4.7
Release date: **2020-11-28**

Author: **Kamensky Vladimir**


***

**WARNING!! This version has a new Google API Key, and this means that a previous GoogleDrive auth will be broken**

***


The CloudCross is a open source project for a synchronization between your devices and various cloud storages. This software is a cross-platform and could be run on Linux, Windows and Mac OS.

Expand Down
Binary file removed build/debug/ccross-app/ccross
Binary file not shown.
Binary file removed build/debug/ccross-curl-executor/ccross-curl
Binary file not shown.
2 changes: 2 additions & 0 deletions ccross-app/include/mscloudprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class MSCloudProvider : public QObject

public:

int skipRedirectsCount =0;

MSNetworkProxy* proxyServer;

QString currentPath;// directory where program was run
Expand Down
2 changes: 1 addition & 1 deletion ccross-app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

#define APP_MAJOR_VERSION 1
#define APP_MINOR_VERSION 4
#define APP_BUILD_NUMBER "6"
#define APP_BUILD_NUMBER "7"

#define CCROSS_HOME_DIR ".ccross"
#define CCROSS_CONFIG_FILE "ccross.conf"
Expand Down
65 changes: 37 additions & 28 deletions ccross-app/src/GoogleDrive/msgoogledrive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,39 @@ bool MSGoogleDrive::auth(){
connect(this,SIGNAL(oAuthError(QString,MSCloudProvider*)),this,SLOT(onAuthFinished(QString, MSCloudProvider*)));


MSHttpRequest* req=new MSHttpRequest(this->proxyServer);
// MSHttpRequest* req=new MSHttpRequest(this->proxyServer);

req->setRequestUrl(QStringLiteral("https://accounts.google.com/o/oauth2/v2/auth"));
req->setMethod(QStringLiteral("get"));
// req->setRequestUrl(QStringLiteral("https://accounts.google.com/o/oauth2/v2/auth"));
// req->setMethod(QStringLiteral("get"));

// req->addQueryItem(QStringLiteral("scope"), QStringLiteral("https://www.googleapis.com/auth/drive+https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+https://docs.google.com/feeds/+https://docs.googleusercontent.com/+https://spreadsheets.google.com/feeds/"));
req->addQueryItem(QStringLiteral("scope"), QStringLiteral("https://www.googleapis.com/auth/drive"));
req->addQueryItem(QStringLiteral("redirect_uri"), QStringLiteral("http://127.0.0.1:1973"));
req->addQueryItem(QStringLiteral("response_type"), QStringLiteral("code"));
req->addQueryItem(QStringLiteral("client_id"), QStringLiteral("834415955748-oq0p2m5dro2bvh3bu0o5bp19ok3qrs3f.apps.googleusercontent.com"));
req->addQueryItem(QStringLiteral("access_type"), QStringLiteral("offline"));
req->addQueryItem(QStringLiteral("approval_prompt"), QStringLiteral("force"));
req->addQueryItem(QStringLiteral("state"), QStringLiteral("1"));
//// req->addQueryItem(QStringLiteral("scope"), QStringLiteral("https://www.googleapis.com/auth/drive"));
// req->addQueryItem(QStringLiteral("redirect_uri"), QStringLiteral("http://127.0.0.1:1973"));
// req->addQueryItem(QStringLiteral("response_type"), QStringLiteral("code"));
// req->addQueryItem(QStringLiteral("client_id"), QStringLiteral("251547413210-t1iem90k7hobv18fl2qtfbckic22lml3.apps.googleusercontent.com"));
//// req->addQueryItem(QStringLiteral("access_type"), QStringLiteral("offline"));
//// req->addQueryItem(QStringLiteral("approval_prompt"), QStringLiteral("force"));
//// req->addQueryItem(QStringLiteral("state"), QStringLiteral("1"));

req->exec();
// req->exec();


if(!req->replyOK()){
req->printReplyError();
delete(req);
this->providerAuthStatus=false;
return false;
}
// if(!req->replyOK()){
// req->printReplyError();
// delete(req);
// this->providerAuthStatus=false;
// return false;
// }

QString r = "https://accounts.google.com/o/oauth2/v2/auth?";
r.append("client_id=251547413210-t1iem90k7hobv18fl2qtfbckic22lml3.apps.googleusercontent.com&scope=https://www.googleapis.com/auth/drive+https://www.googleapis.com/auth/userinfo.email+https://www.googleapis.com/auth/userinfo.profile+https://docs.google.com/feeds/+https://docs.googleusercontent.com/+https://spreadsheets.google.com/feeds/&");
r.append("redirect_uri=http%3a//127.0.0.1:1973&");
r.append("response_type=code&");
r.append("access_type=offline&");
r.append("approval_prompt=force&state=1&");
// r.append("client_id=251547413210-t1iem90k7hobv18fl2qtfbckic22lml3.apps.googleusercontent.com");

this->skipRedirectsCount = 1;
this->startListener(1973);

// if(!this->testReplyBodyForError(req->readReplyText())){
Expand All @@ -96,17 +105,17 @@ bool MSGoogleDrive::auth(){


qInfo()<< QStringLiteral("-------------------------------------") ;
qInfo()<< tr("The CloudCross needs a follow permissions:");
qInfo()<< tr(" - Full access to your GoogleDrive content (https://www.googleapis.com/auth/drive)")<<endl;
// qInfo()<< tr("The CloudCross needs a follow permissions:") << endl;
// qInfo()<< tr(" - Full access to your GoogleDrive content (https://www.googleapis.com/auth/drive)")<<endl;

qInfo()<< tr("Please go to this URL and confirm application credentials") ;
qInfo()<< tr("Please go to this URL and confirm application credentials") <<endl ;


qInfo() << req->replyURL();
qInfo() << r;
qInfo() ;
;

delete(req);
// delete(req);

QEventLoop loop;
connect(this, SIGNAL(providerAuthComplete()), &loop, SLOT(quit()));
Expand Down Expand Up @@ -137,8 +146,8 @@ bool MSGoogleDrive::onAuthFinished(const QString &html, MSCloudProvider *provide
req->setRequestUrl(QStringLiteral("https://www.googleapis.com/oauth2/v4/token"));
req->setMethod(QStringLiteral("post"));

req->addQueryItem(QStringLiteral("client_id"), QStringLiteral("834415955748-oq0p2m5dro2bvh3bu0o5bp19ok3qrs3f.apps.googleusercontent.com"));
req->addQueryItem(QStringLiteral("client_secret"), QStringLiteral("YMBWydU58CvF3UP9CSna-BwS"));
req->addQueryItem(QStringLiteral("client_id"), QStringLiteral("251547413210-t1iem90k7hobv18fl2qtfbckic22lml3.apps.googleusercontent.com"));
req->addQueryItem(QStringLiteral("client_secret"), QStringLiteral("k_SO_6HgLC02gZfy3mMy4P46"));
req->addQueryItem(QStringLiteral("code"), html.trimmed());
req->addQueryItem(QStringLiteral("grant_type"), QStringLiteral("authorization_code"));
req->addQueryItem(QStringLiteral("redirect_uri"), QStringLiteral("http://127.0.0.1:1973"));
Expand Down Expand Up @@ -290,8 +299,8 @@ bool MSGoogleDrive::refreshToken(){
req->setMethod(QStringLiteral("post"));

req->addQueryItem(QStringLiteral("refresh_token"), this->token);
req->addQueryItem(QStringLiteral("client_id"), QStringLiteral("834415955748-oq0p2m5dro2bvh3bu0o5bp19ok3qrs3f.apps.googleusercontent.com"));
req->addQueryItem(QStringLiteral("client_secret"), QStringLiteral("YMBWydU58CvF3UP9CSna-BwS"));
req->addQueryItem(QStringLiteral("client_id"), QStringLiteral("251547413210-t1iem90k7hobv18fl2qtfbckic22lml3.apps.googleusercontent.com"));
req->addQueryItem(QStringLiteral("client_secret"), QStringLiteral("k_SO_6HgLC02gZfy3mMy4P46"));
req->addQueryItem(QStringLiteral("grant_type"), QStringLiteral("refresh_token"));

req->exec();
Expand Down Expand Up @@ -2234,7 +2243,7 @@ bool MSGoogleDrive::remote_file_insert(MSFSObject *object){
}


QString uploadURI = req->getReplyHeader(QByteArray("Location"));// header(QNetworkRequest::LocationHeader).toString();
QString uploadURI = req->getReplyHeader(QByteArray("location"));// header(QNetworkRequest::LocationHeader).toString();

req->replyText.clear();

Expand Down Expand Up @@ -2510,7 +2519,7 @@ bool MSGoogleDrive::remote_file_update(MSFSObject *object){
return false;
}

QString uploadURI = req->getReplyHeader(QByteArray("Location"));// header(QNetworkRequest::LocationHeader).toString();
QString uploadURI = req->getReplyHeader(QByteArray("location"));// header(QNetworkRequest::LocationHeader).toString();

delete(req);

Expand Down
4 changes: 4 additions & 0 deletions ccross-app/src/common/mscloudprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ QString MSCloudProvider::generateRandom(int count){

void MSCloudProvider::onIncomingConnection(){

if(this->skipRedirectsCount > 0){
this->skipRedirectsCount--;
return;
}

this->oauthListenerSocket = this->oauthListener->nextPendingConnection();
//QHostAddress pa=this->oauthListenerSocket->co;
Expand Down

0 comments on commit a61248e

Please sign in to comment.