1 diff -ur libcmis.org/src/libcmis/gdrive-document.cxx libcmis/src/libcmis/gdrive-document.cxx
2 --- libcmis.org/src/libcmis/gdrive-document.cxx 2021-07-27 19:11:02.679247008 +0200
3 +++ libcmis/src/libcmis/gdrive-document.cxx 2021-07-27 19:11:18.873246420 +0200
4 @@ -145,23 +145,17 @@
5 {
6 if ( !os.get( ) )
7 throw libcmis::Exception( "Missing stream" );
8 - if ( !isImmutable( ) )
9 - throw libcmis::Exception( string ( "Document " + getId( )+
10 - " is not editable" ) );
11 - string putUrl = getUploadUrl( ) + getId( );
12 - putUrl += "?uploadType=media";
13 -
14 - // If it's a Google document, convert it
15 - if ( isGoogleDoc( ) )
16 - putUrl += "&convert=true";
17 +
18 + string putUrl = GDRIVE_UPLOAD_LINK + getId( ) + "?uploadType=media";
19
20 // Upload stream
21 boost::shared_ptr< istream> is ( new istream ( os->rdbuf( ) ) );
22 vector <string> headers;
23 headers.push_back( string( "Content-Type: " ) + contentType );
24 + string res;
25 try
26 {
27 - getSession()->httpPutRequest( putUrl, *is, headers );
28 + res = getSession()->httpPatchRequest( putUrl, *is, headers )->getStream()->str();
29 }
30 catch ( const CurlException& e )
31 {
32 @@ -181,35 +175,10 @@
33 {
34 if ( !os.get( ) )
35 throw libcmis::Exception( "Missing stream" );
36 -
37 - if ( !isImmutable( ) )
38 - throw libcmis::Exception( string ( "Document " + getId( )+
39 - " is not editable" ) );
40 - string metaUrl = getUrl( );
41 -
42 - // If it's a Google document, convert it
43 - if ( isGoogleDoc( ) )
44 - metaUrl += "?convert=true";
45 -
46 - // Update file name meta information
47 - if ( !fileName.empty( ) && fileName != getContentFilename( ) )
48 - {
49 - Json metaJson;
50 - Json fileJson( fileName.c_str( ) );
51 - metaJson.add("title", fileJson );
52 -
53 - std::istringstream is( metaJson.toString( ) );
54 - vector<string> headers;
55 - headers.push_back( "Content-Type: application/json" );
56 - try
57 - {
58 - getSession()->httpPutRequest( metaUrl, is, headers );
59 - }
60 - catch ( const CurlException& e )
61 - {
62 - throw e.getCmisException( );
63 - }
64 - }
65 +
66 + // TODO: when would the filename need an update?
67 + if (!fileName.empty() && fileName != getContentFilename())
68 + std::cout << "filename change is not implemented in setContentStream" << std::endl;
69
70 // Upload stream
71 uploadStream( os, contentType );
72 @@ -251,7 +220,7 @@
73 vector< libcmis::DocumentPtr > GDriveDocument::getAllVersions( )
74 {
75 vector< libcmis::DocumentPtr > revisions;
76 - string versionUrl = getUrl( ) + "/revisions";
77 + string versionUrl = GDRIVE_METADATA_LINK + getId( ) + "/revisions";
78 // Run the http request to get the properties definition
79 string res;
80 try
81 @@ -263,7 +232,7 @@
82 throw e.getCmisException( );
83 }
84 Json jsonRes = Json::parse( res );
85 - Json::JsonVector objs = jsonRes["items"].getList( );
86 + Json::JsonVector objs = jsonRes["revisions"].getList( );
87
88 string parentId = getStringProperty( "cmis:parentId" );
89
90 diff -ur libcmis.org/src/libcmis/gdrive-folder.cxx libcmis/src/libcmis/gdrive-folder.cxx
91 --- libcmis.org/src/libcmis/gdrive-folder.cxx 2021-07-27 19:11:02.678247008 +0200
92 +++ libcmis/src/libcmis/gdrive-folder.cxx 2021-07-27 19:11:18.874246420 +0200
93 @@ -62,8 +62,8 @@
94 // Instead of sending multiple queries for children,
95 // we send a single query to search for objects where parents
96 // include the folderID.
97 - string query = getSession( )->getBindingUrl( ) +
98 - "/files?q=\"" + getId( ) + "\"+in+parents+and+trashed+=+false";
99 + string query = GDRIVE_METADATA_LINK + "?q=\"" + getId( ) + "\"+in+parents+and+trashed+=+false" +
100 + "&fields=files(kind,id,name,parents,mimeType,createdTime,modifiedTime,thumbnailLink,size)";
101
102 string res;
103 try
104 @@ -76,7 +76,7 @@
105 }
106
107 Json jsonRes = Json::parse( res );
108 - Json::JsonVector objs = jsonRes["items"].getList( );
109 + Json::JsonVector objs = jsonRes["files"].getList( );
110
111 // Create children objects from Json objects
112 for(unsigned int i = 0; i < objs.size(); i++)
113 @@ -95,7 +95,7 @@
114 string GDriveFolder::uploadProperties( Json properties )
115 {
116 // URL for uploading meta data
117 - string metaUrl = getSession()->getBindingUrl() + "/files/";
118 + string metaUrl = GDRIVE_METADATA_LINK + "?fields=kind,id,name,parents,mimeType,createdTime,modifiedTime";
119
120 // add parents to the properties
121 properties.add( "parents", GdriveUtils::createJsonFromParentId( getId( ) ) );
122 @@ -147,9 +147,15 @@
123
124 Json propsJson = GdriveUtils::toGdriveJson( properties );
125
126 - // Add filename to properties
127 - Json jsonFilename( fileName.c_str( ) );
128 - propsJson.add( "title", jsonFilename );
129 + if(!fileName.empty()) {
130 + // use provided filename
131 + Json jsonFilename( fileName.c_str( ) );
132 +
133 + propsJson.add( "name", jsonFilename );
134 + }
135 + if(!contentType.empty()) {
136 + propsJson.add( "mimeType", Json(contentType.c_str()));
137 + }
138
139 // Upload meta-datas
140 string res = uploadProperties( propsJson);
141 @@ -171,12 +177,9 @@
142 libcmis::UnfileObjects::Type /*unfile*/,
143 bool /*continueOnError*/ )
144 {
145 - // Object remove doesn't work with folder
146 - // Using trash instead
147 try
148 {
149 - istringstream is( "" );
150 - getSession( )->httpPostRequest( getUrl( ) + "/trash", is, "" );
151 + getSession( )->httpDeleteRequest( GDRIVE_METADATA_LINK + getId( ) );
152 }
153 catch ( const CurlException& e )
154 {
155 diff -ur libcmis.org/src/libcmis/gdrive-object.cxx libcmis/src/libcmis/gdrive-object.cxx
156 --- libcmis.org/src/libcmis/gdrive-object.cxx 2021-07-27 19:11:02.675247009 +0200
157 +++ libcmis/src/libcmis/gdrive-object.cxx 2021-07-27 19:11:18.874246420 +0200
158 @@ -89,8 +89,8 @@
159 property.reset( new GDriveProperty( it->first, it->second ) );
160 m_properties[ property->getPropertyType( )->getId()] = property;
161
162 - // we map "title" to both "cmis:name" and "cmis:getContentStreamFileName"
163 - if ( it->first == "title" )
164 + // we map "name" to both "cmis:name" and "cmis:getContentStreamFileName"
165 + if ( it->first == "name" )
166 {
167 property.reset( new GDriveProperty( "cmis:name", it->second) );
168 m_properties[ property->getPropertyType( )->getId()] = property;
169 @@ -142,16 +142,13 @@
170 {
171 if ( m_renditions.empty( ) )
172 {
173 - string downloadUrl = getStringProperty( "downloadUrl" );
174 - if ( !downloadUrl.empty( ) )
175 - {
176 - string mimeType = getStringProperty( "cmis:contentStreamMimeType" );
177 - if ( !mimeType.empty( ) )
178 - {
179 - RenditionPtr rendition(
180 - new Rendition( mimeType, mimeType, mimeType, downloadUrl ));
181 - m_renditions.push_back( rendition );
182 - }
183 + string downloadUrl = GDRIVE_METADATA_LINK + getId( ) + "?alt=media";
184 + string mimeType = getStringProperty( "cmis:contentStreamMimeType" );
185 + if ( !mimeType.empty( ) )
186 + {
187 + RenditionPtr rendition(
188 + new Rendition( mimeType, mimeType, mimeType, downloadUrl ));
189 + m_renditions.push_back( rendition );
190 }
191
192 vector< string > exportLinks = getMultiStringProperty( "exportLinks" );
193 @@ -192,7 +189,7 @@
194 {
195 vector< string > headers;
196 headers.push_back( "Content-Type: application/json" );
197 - response = getSession( )->httpPutRequest( getUrl( ), is, headers );
198 + response = getSession( )->httpPatchRequest( getUrl( ), is, headers );
199 }
200 catch ( const CurlException& e )
201 {
202 @@ -228,7 +225,7 @@
203 {
204 try
205 {
206 - getSession( )->httpDeleteRequest( getUrl( ) );
207 + getSession( )->httpDeleteRequest( GDRIVE_METADATA_LINK + getId( ) );
208 }
209 catch ( const CurlException& e )
210 {
211 @@ -239,8 +236,8 @@
212 void GDriveObject::move( FolderPtr /*source*/, FolderPtr destination )
213 {
214 Json parentsJson;
215 - Json parentsValue = GdriveUtils::createJsonFromParentId( destination->getId( ) );
216 - parentsJson.add( "parents", parentsValue );
217 + parentsJson.add( "addParents", Json(destination->getId( ).c_str()) );
218 + parentsJson.add( "removeParents", Json(getStringProperty( "cmis:parentId" ).c_str()) );
219
220 istringstream is( parentsJson.toString( ) );
221 libcmis::HttpResponsePtr response;
222 @@ -248,7 +245,7 @@
223 {
224 vector< string > headers;
225 headers.push_back( "Content-Type: application/json" );
226 - response = getSession( )->httpPutRequest( getUrl( ), is, headers );
227 + response = getSession( )->httpPatchRequest( getUrl( ), is, headers );
228 }
229 catch ( const CurlException& e )
230 {
231 @@ -262,12 +259,10 @@
232
233 string GDriveObject::getUrl( )
234 {
235 - return getSession( )->getBindingUrl( ) + "/files/" + getId( );
236 -}
237 -
238 -string GDriveObject::getUploadUrl( )
239 -{
240 - return GDRIVE_UPLOAD_LINKS;
241 + // thumbnailLink causes some operations to fail with internal server error,
242 + // see https://issuetracker.google.com/issues/36760667
243 + return GDRIVE_METADATA_LINK + getId( ) +
244 + "?fields=kind,id,name,parents,mimeType,createdTime,modifiedTime,size";
245 }
246
247 vector< string> GDriveObject::getMultiStringProperty( const string& propertyName )
248 diff -ur libcmis.org/src/libcmis/gdrive-repository.cxx libcmis/src/libcmis/gdrive-repository.cxx
249 --- libcmis.org/src/libcmis/gdrive-repository.cxx 2021-07-27 19:11:02.676247009 +0200
250 +++ libcmis/src/libcmis/gdrive-repository.cxx 2021-07-27 19:11:18.874246420 +0200
251 @@ -35,7 +35,7 @@
252 m_name = "Google Drive";
253 m_description = "Google Drive repository";
254 m_productName = "Google Drive";
255 - m_productVersion = "v2";
256 + m_productVersion = "v3";
257 m_rootId = "root";
258
259 m_capabilities[ ACL ] = "discover";
260 diff -ur libcmis.org/src/libcmis/gdrive-session.cxx libcmis/src/libcmis/gdrive-session.cxx
261 --- libcmis.org/src/libcmis/gdrive-session.cxx 2021-07-27 19:11:02.675247009 +0200
262 +++ libcmis/src/libcmis/gdrive-session.cxx 2021-07-27 19:11:18.874246420 +0200
263 @@ -124,9 +124,13 @@
264
265 libcmis::ObjectPtr GDriveSession::getObject( string objectId )
266 {
267 + if(objectId == "root") {
268 + return getRootFolder();
269 + }
270 // Run the http request to get the properties definition
271 string res;
272 - string objectLink = m_bindingUrl + "/files/" + objectId;
273 + string objectLink = GDRIVE_METADATA_LINK + objectId +
274 + "?fields=kind,id,name,parents,mimeType,createdTime,modifiedTime,thumbnailLink,size";
275 try
276 {
277 res = httpGetRequest( objectLink )->getStream()->str();
278 @@ -188,9 +192,10 @@
279 {
280 // Normal child case
281 // Ask for the ID of the child if there is any
282 - string childIdUrl = m_bindingUrl + "/files/" + objectId +
283 - "/children/?q=title+=+'" + segment +
284 - "'&fields=items:id";
285 + // somewhat flawed as names are not necessarily unique in GDrive...
286 + string query = libcmis::escape("'" + objectId + "' in parents and trashed = false and name='" + segment + "'");
287 +
288 + string childIdUrl = m_bindingUrl + "/files/?q=" + query + "&fields=files(id)";
289
290 string res;
291 try
292 @@ -204,7 +209,7 @@
293 Json jsonRes = Json::parse( res );
294
295 // Did we get an id?
296 - Json::JsonVector items = jsonRes["items"].getList();
297 + Json::JsonVector items = jsonRes["files"].getList();
298 if ( items.empty( ) )
299 throw libcmis::Exception( "Object not found: " + path, "objectNotFound" );
300
301 @@ -219,6 +224,27 @@
302 return getObject( objectId );
303 }
304
305 +libcmis::FolderPtr GDriveSession::getRootFolder()
306 +{
307 + // permissions/scope with just drive.file don't allow to get it with the "root" alias/by its actual object-ID
308 + Json propsJson;
309 +
310 + // GDrive folder is a file with a different mime type.
311 + string mimeType = GDRIVE_FOLDER_MIME_TYPE;
312 +
313 + // Add mimetype to the propsJson
314 + Json jsonMimeType( mimeType.c_str( ) );
315 + propsJson.add( "mimeType", jsonMimeType );
316 + propsJson.add( "id", "root" );
317 +
318 + // Upload meta-datas
319 + propsJson.add("cmis:name", "VirtualRoot");
320 +
321 + libcmis::FolderPtr folderPtr( new GDriveFolder( this, propsJson ) );
322 +
323 + return folderPtr;
324 +}
325 +
326 libcmis::ObjectTypePtr GDriveSession::getType( string id )
327 {
328 libcmis::ObjectTypePtr type( new GdriveObjectType( id ) );
329 diff -ur libcmis.org/src/libcmis/gdrive-session.hxx libcmis/src/libcmis/gdrive-session.hxx
330 --- libcmis.org/src/libcmis/gdrive-session.hxx 2021-07-27 19:11:02.675247009 +0200
331 +++ libcmis/src/libcmis/gdrive-session.hxx 2021-07-27 19:11:18.875246420 +0200
332 @@ -57,6 +57,8 @@
333
334 virtual std::vector< libcmis::ObjectTypePtr > getBaseTypes( );
335
336 + virtual libcmis::FolderPtr getRootFolder();
337 +
338 virtual std::string getRefreshToken();
339
340 private:
341 diff -ur libcmis.org/src/libcmis/gdrive-utils.cxx libcmis/src/libcmis/gdrive-utils.cxx
342 --- libcmis.org/src/libcmis/gdrive-utils.cxx 2021-07-27 19:11:02.677247008 +0200
343 +++ libcmis/src/libcmis/gdrive-utils.cxx 2021-07-27 19:11:18.875246420 +0200
344 @@ -44,17 +44,17 @@
345 convertedKey = "cmis:createdBy";
346 else if ( key == "description" )
347 convertedKey = "cmis:description";
348 - else if ( key == "createdDate" )
349 + else if ( key == "createdTime" )
350 convertedKey = "cmis:creationDate";
351 else if ( key == "lastModifyingUserName" )
352 convertedKey = "cmis:lastModifiedBy";
353 - else if ( key == "modifiedDate" )
354 + else if ( key == "modifiedTime" )
355 convertedKey = "cmis:lastModificationDate";
356 - else if ( key == "title" )
357 + else if ( key == "name" )
358 convertedKey = "cmis:contentStreamFileName";
359 else if ( key == "mimeType" )
360 convertedKey = "cmis:contentStreamMimeType";
361 - else if ( key == "fileSize" )
362 + else if ( key == "size" )
363 convertedKey = "cmis:contentStreamLength";
364 else if ( key == "editable" )
365 convertedKey = "cmis:isImmutable";
366 @@ -72,21 +72,21 @@
367 else if ( key == "cmis:createdBy" )
368 convertedKey = "ownerNames";
369 else if ( key == "cmis:creationDate" )
370 - convertedKey = "createdDate";
371 + convertedKey = "createdTime";
372 else if ( key == "cmis:description" )
373 convertedKey = "description";
374 else if ( key == "cmis:lastModifiedBy" )
375 convertedKey = "lastModifyingUserName";
376 else if ( key == "cmis:lastModificationDate" )
377 - convertedKey = "modifiedDate";
378 + convertedKey = "modifiedTime";
379 else if ( key == "cmis:contentStreamFileName" )
380 - convertedKey = "title";
381 + convertedKey = "name";
382 else if ( key == "cmis:name" )
383 - convertedKey = "title";
384 + convertedKey = "name";
385 else if ( key == "cmis:contentStreamMimeType" )
386 convertedKey = "mimeType";
387 else if ( key == "cmis:contentStreamLength" )
388 - convertedKey = "fileSize";
389 + convertedKey = "size";
390 else if ( key == "cmis:isImmutable" )
391 convertedKey = "editable";
392 else if ( key == "cmis:parentId" )
393 @@ -124,9 +124,9 @@
394 bool GdriveUtils::checkUpdatable( const string& key )
395 {
396 // taken from https://developers.google.com/drive/v2/reference/files
397 - bool updatable = ( key == "title" ||
398 + bool updatable = ( key == "name" ||
399 key == "description" ||
400 - key == "modifiedDate" ||
401 + key == "modifiedTime" ||
402 key == "lastViewedByMeDate" );
403 return updatable;
404 }
405 @@ -143,18 +143,11 @@
406
407 Json GdriveUtils::createJsonFromParentId( const string& parentId )
408 {
409 - Json parentValue( parentId.c_str( ) );
410 -
411 // parents is a Json array
412 Json firstParent;
413 - firstParent.add( "id", parentValue );
414 -
415 - Json::JsonVector parents;
416 - parents.insert( parents.begin( ), firstParent );
417 + firstParent.add( Json( parentId.c_str() ) );
418
419 - Json parentsValue( parents );
420 -
421 - return parentsValue;
422 + return firstParent;
423 }
424
425 vector< string > GdriveUtils::parseGdriveProperty( string key, Json json )
426 diff -ur libcmis.org/src/libcmis/gdrive-utils.hxx libcmis/src/libcmis/gdrive-utils.hxx
427 --- libcmis.org/src/libcmis/gdrive-utils.hxx 2021-07-27 19:11:02.677247008 +0200
428 +++ libcmis/src/libcmis/gdrive-utils.hxx 2021-07-27 19:11:18.875246420 +0200
429 @@ -35,7 +35,8 @@
430 #include "json-utils.hxx"
431
432 static const std::string GDRIVE_FOLDER_MIME_TYPE = "application/vnd.google-apps.folder" ;
433 -static const std::string GDRIVE_UPLOAD_LINKS = "https://www.googleapis.com/upload/drive/v2/files/";
434 +static const std::string GDRIVE_UPLOAD_LINK = "https://www.googleapis.com/upload/drive/v3/files/";
435 +static const std::string GDRIVE_METADATA_LINK = "https://www.googleapis.com/drive/v3/files/";
436
437 class GdriveUtils
438 {
439 diff -ur libcmis.org/src/libcmis/oauth2-handler.cxx libcmis/src/libcmis/oauth2-handler.cxx
440 --- libcmis.org/src/libcmis/oauth2-handler.cxx 2021-07-27 19:11:02.676247009 +0200
441 +++ libcmis/src/libcmis/oauth2-handler.cxx 2021-07-27 19:11:18.875246420 +0200
442 @@ -92,8 +92,11 @@
443 "code=" + authCode +
444 "&client_id=" + m_data->getClientId() +
445 "&redirect_uri=" + m_data->getRedirectUri() +
446 - "&scope=" + libcmis::escape( m_data->getScope() ) +
447 "&grant_type=authorization_code" ;
448 + if(boost::starts_with(m_data->getTokenUrl(), "https://oauth2.googleapis.com/"))
449 + post += "&client_secret=" + m_data->getClientSecret();
450 + else
451 + post += "&scope=" + libcmis::escape( m_data->getScope() );
452
453 istringstream is( post );
454
455 @@ -104,7 +107,7 @@
456 resp = m_session->httpPostRequest ( m_data->getTokenUrl(), is,
457 "application/x-www-form-urlencoded" );
458 }
459 - catch ( const CurlException& )
460 + catch ( const CurlException& e)
461 {
462 throw libcmis::Exception(
463 "Couldn't get tokens from the authorization code ");
464 @@ -122,6 +125,8 @@
465 "refresh_token=" + m_refresh +
466 "&client_id=" + m_data->getClientId() +
467 "&grant_type=refresh_token" ;
468 + if(boost::starts_with(m_data->getTokenUrl(), "https://oauth2.googleapis.com/"))
469 + post += "&client_secret=" + m_data->getClientSecret();
470
471 istringstream is( post );
472 libcmis::HttpResponsePtr resp;
473 @@ -130,7 +135,7 @@
474 resp = m_session->httpPostRequest( m_data->getTokenUrl( ), is,
475 "application/x-www-form-urlencoded" );
476 }
477 - catch (const CurlException& )
478 + catch (const CurlException& e )
479 {
480 throw libcmis::Exception( "Couldn't refresh token ");
481 }
482 diff -ur libcmis.org/src/libcmis/oauth2-providers.cxx libcmis/src/libcmis/oauth2-providers.cxx
483 --- libcmis.org/src/libcmis/oauth2-providers.cxx 2021-07-27 19:11:02.679247008 +0200
484 +++ libcmis/src/libcmis/oauth2-providers.cxx 2021-07-27 19:11:18.886246420 +0200
485 @@ -80,172 +80,8 @@
486
487 }
488
489 -string OAuth2Providers::OAuth2Gdrive( HttpSession* session, const string& authUrl,
490 - const string& username, const string& password )
491 -{
492 - /* This member function implements 'Google OAuth 2.0'
493 - *
494 - * The interaction is carried out by libcmis, with no web browser involved.
495 - *
496 - * Normal sequence (without 2FA) is:
497 - * 1) a get to activate login page
498 - * receive first login page, html format
499 - * 2) subsequent post to sent email
500 - * receive html page for password input
501 - * 3) subsequent post to send password
502 - * receive html page for application consent
503 - * 4) subsequent post to send a consent for the application
504 - * receive a single-use authorization code
505 - * this code is returned as a string
506 - *
507 - * Sequence with 2FA is:
508 - * 1) a get to activate login page
509 - * receive first login page, html format
510 - * 2) subsequent post to sent email
511 - * receive html page for password input
512 - * 3) subsequent post to send password
513 - * receive html page for pin input
514 - * 3b) subsequent post to send pin number
515 - * receive html page for application consent
516 - * 4) subsequent post to send a consent for the application
517 - * receive a single-use authorization code
518 - * this code is returned as a string
519 - */
520 -
521 - static const string CONTENT_TYPE( "application/x-www-form-urlencoded" );
522 - // STEP 1: get login page
523 - string res;
524 - try
525 - {
526 - // send the first get, receive the html login page
527 - res = session->httpGetRequest( authUrl )->getStream( )->str( );
528 - }
529 - catch ( const CurlException& )
530 - {
531 - return string( );
532 - }
533 -
534 - // STEP 2: send email
535 -
536 - string loginEmailPost, loginEmailLink;
537 - if ( !parseResponse( res.c_str( ), loginEmailPost, loginEmailLink ) )
538 - return string( );
539 -
540 - loginEmailPost += "Email=";
541 - loginEmailPost += escapeForm( username );
542 -
543 - istringstream loginEmailIs( loginEmailPost );
544 - string loginEmailRes;
545 - try
546 - {
547 - // send a post with user email, receive the html page for password input
548 - loginEmailRes = session->httpPostRequest ( loginEmailLink, loginEmailIs, CONTENT_TYPE )
549 - ->getStream( )->str( );
550 - }
551 - catch ( const CurlException& )
552 - {
553 - return string( );
554 - }
555 -
556 - // STEP 3: password page
557 -
558 - string loginPasswdPost, loginPasswdLink;
559 - if ( !parseResponse( loginEmailRes.c_str( ), loginPasswdPost, loginPasswdLink ) )
560 - return string( );
561 -
562 - loginPasswdPost += "Passwd=";
563 - loginPasswdPost += escapeForm( password );
564 -
565 - istringstream loginPasswdIs( loginPasswdPost );
566 - string loginPasswdRes;
567 - try
568 - {
569 - // send a post with user password, receive the application consent page
570 - loginPasswdRes = session->httpPostRequest ( loginPasswdLink, loginPasswdIs, CONTENT_TYPE )
571 - ->getStream( )->str( );
572 - }
573 - catch ( const CurlException& )
574 - {
575 - return string( );
576 - }
577 -
578 - string approvalPost, approvalLink;
579 - if ( !parseResponse( loginPasswdRes. c_str( ), approvalPost, approvalLink) )
580 - return string( );
581 -
582 - // when 2FA is enabled, link doesn't start with 'http'
583 - if ( approvalLink.compare(0, 4, "http") != 0 )
584 - {
585 - // STEP 3b: 2 Factor Authentication, pin code request
586 -
587 - string loginChallengePost( approvalPost );
588 - string loginChallengeLink( approvalLink );
589 -
590 - libcmis::OAuth2AuthCodeProvider fallbackProvider = libcmis::SessionFactory::getOAuth2AuthCodeProvider( );
591 - unique_ptr< char, void (*)( void * ) > pin{ fallbackProvider( "", "", "" ), free };
592 -
593 - if( !pin )
594 - {
595 - // unset OAuth2AuthCode Provider to avoid showing pin request again in the HttpSession::oauth2Authenticate
596 - libcmis::SessionFactory::setOAuth2AuthCodeProvider( NULL );
597 - return string( );
598 - }
599 -
600 - loginChallengeLink = "https://accounts.google.com" + loginChallengeLink;
601 - loginChallengePost += string( PIN_INPUT_NAME ) + "=";
602 - loginChallengePost += string( pin.get() );
603 -
604 - istringstream loginChallengeIs( loginChallengePost );
605 - string loginChallengeRes;
606 - try
607 - {
608 - // send a post with pin, receive the application consent page
609 - loginChallengeRes = session->httpPostRequest ( loginChallengeLink, loginChallengeIs, CONTENT_TYPE )
610 - ->getStream( )->str( );
611 - }
612 - catch ( const CurlException& )
613 - {
614 - return string( );
615 - }
616 -
617 - approvalPost = string();
618 - approvalLink = string();
619 -
620 - if ( !parseResponse( loginChallengeRes. c_str( ), approvalPost, approvalLink) )
621 - return string( );
622 - }
623 - else if( approvalLink.compare( "https://accounts.google.com/ServiceLoginAuth" ) == 0 )
624 - {
625 - // wrong password,
626 - // unset OAuth2AuthCode Provider to avoid showing pin request again in the HttpSession::oauth2Authenticate
627 - libcmis::SessionFactory::setOAuth2AuthCodeProvider( NULL );
628 - return string( );
629 - }
630 -
631 - // STEP 4: allow libcmis to access google drive
632 - approvalPost += "submit_access=true";
633 -
634 - istringstream approvalIs( approvalPost );
635 - string approvalRes;
636 - try
637 - {
638 - // send a post with application consent
639 - approvalRes = session->httpPostRequest ( approvalLink, approvalIs,
640 - CONTENT_TYPE) ->getStream( )->str( );
641 - }
642 - catch ( const CurlException& e )
643 - {
644 - throw e.getCmisException( );
645 - }
646 -
647 - // Take the authentication code from the text bar
648 - string code = parseCode( approvalRes.c_str( ) );
649 -
650 - return code;
651 -}
652 -
653 -string OAuth2Providers::OAuth2Onedrive( HttpSession* /*session*/, const string& /*authUrl*/,
654 - const string& /*username*/, const string& /*password*/ )
655 +string OAuth2Providers::OAuth2Dummy( HttpSession* /*session*/, const string& /*authUrl*/,
656 + const string& /*username*/, const string& /*password*/ )
657 {
658 return string( );
659 }
660 @@ -314,12 +150,8 @@
661 // For Alfresco in the cloud, only match the hostname as there can be several
662 // binding URLs created with it.
663 return OAuth2Alfresco;
664 - else if ( boost::starts_with( url, "https://www.googleapis.com/drive/v2" ) )
665 - return OAuth2Gdrive;
666 - else if ( boost::starts_with( url, "https://graph.microsoft.com/v1.0" ) )
667 - return OAuth2Onedrive;
668
669 - return OAuth2Gdrive;
670 + return OAuth2Dummy;
671 }
672
673 int OAuth2Providers::parseResponse ( const char* response, string& post, string& link )
674 diff -ur libcmis.org/src/libcmis/oauth2-providers.hxx libcmis/src/libcmis/oauth2-providers.hxx
675 --- libcmis.org/src/libcmis/oauth2-providers.hxx 2021-07-27 19:11:02.678247008 +0200
676 +++ libcmis/src/libcmis/oauth2-providers.hxx 2021-07-27 19:11:18.886246420 +0200
677 @@ -39,12 +39,8 @@
678 class OAuth2Providers
679 {
680 public :
681 - static std::string OAuth2Gdrive( HttpSession* session, const std::string& authUrl,
682 + static std::string OAuth2Dummy( HttpSession* session, const std::string& authUrl,
683 const std::string& username, const std::string& password );
684 -
685 - static std::string OAuth2Onedrive( HttpSession* session, const std::string& authUrl,
686 - const std::string& username, const std::string& password );
687 -
688 static std::string OAuth2Alfresco( HttpSession* session, const std::string& authUrl,
689 const std::string& username, const std::string& password );
690
691 diff -ur libcmis.org/src/libcmis/session-factory.cxx libcmis/src/libcmis/session-factory.cxx
692 --- libcmis.org/src/libcmis/session-factory.cxx 2021-07-27 19:11:02.679247008 +0200
693 +++ libcmis/src/libcmis/session-factory.cxx 2021-07-27 19:11:18.886246420 +0200
694 @@ -66,7 +66,7 @@
695 if ( !bindingUrl.empty( ) )
696 {
697 // Try the special cases based on the binding URL
698 - if ( bindingUrl == "https://www.googleapis.com/drive/v2" )
699 + if ( bindingUrl == "https://www.googleapis.com/drive/v3" )
700 {
701 session = new GDriveSession( bindingUrl, username, password,
702 oauth2, verbose );
|