Blame SOURCES/0001-Revert-tdf-101630-gdrive-support-w-oAuth-and-Drive-A.patch

17f16b
From 12f14a6c9d2b5034df53646bbc57774c0c83ecaa Mon Sep 17 00:00:00 2001
17f16b
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
17f16b
Date: Fri, 3 Sep 2021 09:13:03 +0100
17f16b
Subject: [PATCH] Revert "tdf#101630 - gdrive support w/oAuth and Drive API v3"
17f16b
17f16b
This reverts commit 854c03ebc94aae205b85d0c9d342048baf93e9a9.
17f16b
---
17f16b
 Repository.mk                                 |   2 +-
17f16b
 config_host/config_oauth2.h.in                |   8 +-
17f16b
 external/libcmis/UnpackedTarball_libcmis.mk   |   2 -
17f16b
 external/libcmis/libcmis_gdrive.patch.1       | 702 ------------------
17f16b
 .../libcmis_oauth_pw_as_refreshtoken.patch.1  | 185 -----
17f16b
 .../data/org/openoffice/Office/Common.xcu     |   2 +-
17f16b
 ucb/source/ucp/cmis/auth_provider.cxx         | 130 +---
17f16b
 ucb/source/ucp/cmis/auth_provider.hxx         |   8 +-
17f16b
 ucb/source/ucp/cmis/cmis_content.cxx          |  21 +-
17f16b
 ucb/source/ucp/cmis/cmis_repo_content.cxx     |   4 +-
17f16b
 10 files changed, 56 insertions(+), 1008 deletions(-)
17f16b
 delete mode 100644 external/libcmis/libcmis_gdrive.patch.1
17f16b
 delete mode 100644 external/libcmis/libcmis_oauth_pw_as_refreshtoken.patch.1
17f16b
17f16b
diff --git a/Repository.mk b/Repository.mk
17f16b
index 23c268775fcf..c887d9b4297d 100644
17f16b
--- a/Repository.mk
17f16b
+++ b/Repository.mk
17f16b
@@ -432,7 +432,7 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,ooo, \
17f16b
 	ucpexpand1 \
17f16b
 	ucpext \
17f16b
 	ucpimage \
17f16b
-	$(if $(ENABLE_LIBCMIS),ucpcmis1) \
17f16b
+	ucpcmis1 \
17f16b
 	ucptdoc1 \
17f16b
 	unordf \
17f16b
 	unoxml \
17f16b
diff --git a/config_host/config_oauth2.h.in b/config_host/config_oauth2.h.in
17f16b
index 9945dda3dda5..a95015b41f3e 100644
17f16b
--- a/config_host/config_oauth2.h.in
17f16b
+++ b/config_host/config_oauth2.h.in
17f16b
@@ -15,13 +15,13 @@
17f16b
 
17f16b
 
17f16b
 /* Google Drive settings */
17f16b
-#define GDRIVE_BASE_URL "https://www.googleapis.com/drive/v3"
17f16b
+#define GDRIVE_BASE_URL "https://www.googleapis.com/drive/v2"
17f16b
 #define GDRIVE_CLIENT_ID ""
17f16b
 #define GDRIVE_CLIENT_SECRET ""
17f16b
-#define GDRIVE_AUTH_URL "https://accounts.google.com/o/oauth2/v2/auth"
17f16b
-#define GDRIVE_TOKEN_URL "https://oauth2.googleapis.com/token"
17f16b
+#define GDRIVE_AUTH_URL "https://accounts.google.com/o/oauth2/auth"
17f16b
+#define GDRIVE_TOKEN_URL "https://accounts.google.com/o/oauth2/token"
17f16b
 #define GDRIVE_REDIRECT_URI "urn:ietf:wg:oauth:2.0:oob"
17f16b
-#define GDRIVE_SCOPE "https://www.googleapis.com/auth/drive.file"
17f16b
+#define GDRIVE_SCOPE "https://www.googleapis.com/auth/drive"
17f16b
 
17f16b
 
17f16b
 /* Alfresco Cloud */
17f16b
diff --git a/external/libcmis/UnpackedTarball_libcmis.mk b/external/libcmis/UnpackedTarball_libcmis.mk
17f16b
index 8398853e4511..a5be3078c95a 100644
17f16b
--- a/external/libcmis/UnpackedTarball_libcmis.mk
17f16b
+++ b/external/libcmis/UnpackedTarball_libcmis.mk
17f16b
@@ -17,8 +17,6 @@ $(eval $(call gb_UnpackedTarball_add_patches,libcmis, \
17f16b
 	external/libcmis/libcmis-libxml2_compatibility.patch \
17f16b
 	external/libcmis/0001-rename-class-GetObject-to-avoid-name-clash-on-Window.patch \
17f16b
 	external/libcmis/libcmis_onedrive.patch \
17f16b
-	external/libcmis/libcmis_oauth_pw_as_refreshtoken.patch.1 \
17f16b
-	external/libcmis/libcmis_gdrive.patch.1 \
17f16b
 ))
17f16b
 
17f16b
 # vim: set noet sw=4 ts=4:
17f16b
diff --git a/external/libcmis/libcmis_gdrive.patch.1 b/external/libcmis/libcmis_gdrive.patch.1
17f16b
deleted file mode 100644
17f16b
index 24ff65d1ef15..000000000000
17f16b
--- a/external/libcmis/libcmis_gdrive.patch.1
17f16b
+++ /dev/null
17f16b
@@ -1,702 +0,0 @@
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-document.cxx libcmis/src/libcmis/gdrive-document.cxx
17f16b
---- libcmis.org/src/libcmis/gdrive-document.cxx	2021-07-27 19:11:02.679247008 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-document.cxx	2021-07-27 19:11:18.873246420 +0200
17f16b
-@@ -145,23 +145,17 @@
17f16b
- {
17f16b
-     if ( !os.get( ) )
17f16b
-         throw libcmis::Exception( "Missing stream" );
17f16b
--    if ( !isImmutable( ) )
17f16b
--        throw libcmis::Exception( string ( "Document " + getId( )+ 
17f16b
--                                    " is not editable" ) );
17f16b
--    string putUrl = getUploadUrl( ) + getId( );
17f16b
--    putUrl += "?uploadType=media";
17f16b
--    
17f16b
--    // If it's a Google document, convert it 
17f16b
--    if ( isGoogleDoc( ) )
17f16b
--        putUrl  += "&convert=true";
17f16b
-+
17f16b
-+    string putUrl = GDRIVE_UPLOAD_LINK + getId( ) + "?uploadType=media";
17f16b
- 
17f16b
-     // Upload stream
17f16b
-     boost::shared_ptr< istream> is ( new istream ( os->rdbuf( ) ) );
17f16b
-     vector <string> headers;
17f16b
-     headers.push_back( string( "Content-Type: " ) + contentType );
17f16b
-+    string res;
17f16b
-     try
17f16b
-     {
17f16b
--        getSession()->httpPutRequest( putUrl, *is, headers );
17f16b
-+        res = getSession()->httpPatchRequest( putUrl, *is, headers )->getStream()->str();
17f16b
-     }
17f16b
-     catch ( const CurlException& e )
17f16b
-     {
17f16b
-@@ -181,35 +175,10 @@
17f16b
- {
17f16b
-     if ( !os.get( ) )
17f16b
-         throw libcmis::Exception( "Missing stream" );
17f16b
--    
17f16b
--    if ( !isImmutable( ) )
17f16b
--        throw libcmis::Exception( string ( "Document " + getId( )+ 
17f16b
--                                    " is not editable" ) );
17f16b
--    string metaUrl = getUrl( );
17f16b
--
17f16b
--    // If it's a Google document, convert it 
17f16b
--    if ( isGoogleDoc( ) )
17f16b
--        metaUrl += "?convert=true";
17f16b
--
17f16b
--    // Update file name meta information
17f16b
--    if ( !fileName.empty( ) && fileName != getContentFilename( ) )
17f16b
--    {
17f16b
--        Json metaJson;
17f16b
--        Json fileJson( fileName.c_str( ) );
17f16b
--        metaJson.add("title", fileJson );
17f16b
--
17f16b
--        std::istringstream is( metaJson.toString( ) );
17f16b
--        vector<string> headers;
17f16b
--        headers.push_back( "Content-Type: application/json" );
17f16b
--        try
17f16b
--        {
17f16b
--            getSession()->httpPutRequest( metaUrl, is, headers );
17f16b
--        }
17f16b
--        catch ( const CurlException& e )
17f16b
--        {
17f16b
--            throw e.getCmisException( );
17f16b
--        }
17f16b
--    }
17f16b
-+
17f16b
-+    // TODO: when would the filename need an update?
17f16b
-+    if (!fileName.empty() && fileName != getContentFilename())
17f16b
-+        std::cout << "filename change is not implemented in setContentStream" << std::endl;
17f16b
- 
17f16b
-     // Upload stream
17f16b
-     uploadStream( os, contentType );
17f16b
-@@ -251,7 +220,7 @@
17f16b
- vector< libcmis::DocumentPtr > GDriveDocument::getAllVersions( ) 
17f16b
- {   
17f16b
-     vector< libcmis::DocumentPtr > revisions;
17f16b
--    string versionUrl = getUrl( ) + "/revisions";
17f16b
-+    string versionUrl = GDRIVE_METADATA_LINK + getId( ) + "/revisions";
17f16b
-     // Run the http request to get the properties definition
17f16b
-     string res;
17f16b
-     try
17f16b
-@@ -263,7 +232,7 @@
17f16b
-         throw e.getCmisException( );
17f16b
-     }
17f16b
-     Json jsonRes = Json::parse( res );        
17f16b
--    Json::JsonVector objs = jsonRes["items"].getList( );
17f16b
-+    Json::JsonVector objs = jsonRes["revisions"].getList( );
17f16b
-    
17f16b
-     string parentId = getStringProperty( "cmis:parentId" );
17f16b
- 
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-folder.cxx libcmis/src/libcmis/gdrive-folder.cxx
17f16b
---- libcmis.org/src/libcmis/gdrive-folder.cxx	2021-07-27 19:11:02.678247008 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-folder.cxx	2021-07-27 19:11:18.874246420 +0200
17f16b
-@@ -62,8 +62,8 @@
17f16b
-     // Instead of sending multiple queries for children,
17f16b
-     // we send a single query to search for objects where parents
17f16b
-     // include the folderID.
17f16b
--    string query = getSession( )->getBindingUrl( ) + 
17f16b
--        "/files?q=\"" + getId( ) + "\"+in+parents+and+trashed+=+false";
17f16b
-+    string query = GDRIVE_METADATA_LINK + "?q=\"" + getId( ) + "\"+in+parents+and+trashed+=+false" +
17f16b
-+        "&fields=files(kind,id,name,parents,mimeType,createdTime,modifiedTime,thumbnailLink,size)";
17f16b
- 
17f16b
-     string res;
17f16b
-     try
17f16b
-@@ -76,7 +76,7 @@
17f16b
-     }
17f16b
- 
17f16b
-     Json jsonRes = Json::parse( res );
17f16b
--    Json::JsonVector objs = jsonRes["items"].getList( );
17f16b
-+    Json::JsonVector objs = jsonRes["files"].getList( );
17f16b
-     
17f16b
-     // Create children objects from Json objects
17f16b
-     for(unsigned int i = 0; i < objs.size(); i++)
17f16b
-@@ -95,7 +95,7 @@
17f16b
- string GDriveFolder::uploadProperties( Json properties )
17f16b
- {
17f16b
-     // URL for uploading meta data
17f16b
--    string metaUrl =  getSession()->getBindingUrl() + "/files/";
17f16b
-+    string metaUrl =  GDRIVE_METADATA_LINK + "?fields=kind,id,name,parents,mimeType,createdTime,modifiedTime";
17f16b
- 
17f16b
-     // add parents to the properties    
17f16b
-     properties.add( "parents", GdriveUtils::createJsonFromParentId( getId( ) ) );
17f16b
-@@ -147,9 +147,15 @@
17f16b
-     
17f16b
-     Json propsJson = GdriveUtils::toGdriveJson( properties );
17f16b
- 
17f16b
--    // Add filename to properties
17f16b
--    Json jsonFilename( fileName.c_str( ) );
17f16b
--    propsJson.add( "title", jsonFilename );
17f16b
-+    if(!fileName.empty()) {
17f16b
-+        // use provided filename
17f16b
-+        Json jsonFilename( fileName.c_str( ) );
17f16b
-+
17f16b
-+        propsJson.add( "name", jsonFilename );
17f16b
-+    }
17f16b
-+    if(!contentType.empty()) {
17f16b
-+        propsJson.add( "mimeType", Json(contentType.c_str()));
17f16b
-+    }
17f16b
-     
17f16b
-     // Upload meta-datas
17f16b
-     string res = uploadProperties( propsJson);
17f16b
-@@ -171,12 +177,9 @@
17f16b
-     libcmis::UnfileObjects::Type /*unfile*/, 
17f16b
-     bool /*continueOnError*/ ) 
17f16b
- {
17f16b
--    // Object remove doesn't work with folder
17f16b
--    // Using trash instead
17f16b
-     try
17f16b
-     {   
17f16b
--        istringstream is( "" );
17f16b
--        getSession( )->httpPostRequest( getUrl( ) + "/trash", is, "" );
17f16b
-+        getSession( )->httpDeleteRequest( GDRIVE_METADATA_LINK + getId( ) );
17f16b
-     }
17f16b
-     catch ( const CurlException& e )
17f16b
-     {
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-object.cxx libcmis/src/libcmis/gdrive-object.cxx
17f16b
---- libcmis.org/src/libcmis/gdrive-object.cxx	2021-07-27 19:11:02.675247009 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-object.cxx	2021-07-27 19:11:18.874246420 +0200
17f16b
-@@ -89,8 +89,8 @@
17f16b
-             property.reset( new GDriveProperty( it->first, it->second ) );
17f16b
-             m_properties[ property->getPropertyType( )->getId()] = property;
17f16b
-            
17f16b
--            // we map "title" to both "cmis:name" and "cmis:getContentStreamFileName"
17f16b
--            if ( it->first == "title" )
17f16b
-+            // we map "name" to both "cmis:name" and "cmis:getContentStreamFileName"
17f16b
-+            if ( it->first == "name" )
17f16b
-             {
17f16b
-                 property.reset( new GDriveProperty( "cmis:name", it->second) );
17f16b
-                 m_properties[ property->getPropertyType( )->getId()] = property;
17f16b
-@@ -142,16 +142,13 @@
17f16b
- {
17f16b
-     if ( m_renditions.empty( ) )
17f16b
-     {
17f16b
--        string downloadUrl = getStringProperty( "downloadUrl" );
17f16b
--        if ( !downloadUrl.empty( ) )
17f16b
--        {
17f16b
--            string mimeType = getStringProperty( "cmis:contentStreamMimeType" );
17f16b
--            if ( !mimeType.empty( ) )
17f16b
--            { 
17f16b
--                RenditionPtr rendition( 
17f16b
--                    new Rendition( mimeType, mimeType, mimeType, downloadUrl ));
17f16b
--                m_renditions.push_back( rendition );
17f16b
--            }
17f16b
-+        string downloadUrl = GDRIVE_METADATA_LINK + getId( ) + "?alt=media";
17f16b
-+        string mimeType = getStringProperty( "cmis:contentStreamMimeType" );
17f16b
-+        if ( !mimeType.empty( ) )
17f16b
-+        {
17f16b
-+            RenditionPtr rendition(
17f16b
-+                new Rendition( mimeType, mimeType, mimeType, downloadUrl ));
17f16b
-+            m_renditions.push_back( rendition );
17f16b
-         }
17f16b
- 
17f16b
-         vector< string > exportLinks = getMultiStringProperty( "exportLinks" );
17f16b
-@@ -192,7 +189,7 @@
17f16b
-     {   
17f16b
-         vector< string > headers;
17f16b
-         headers.push_back( "Content-Type: application/json" );
17f16b
--        response = getSession( )->httpPutRequest( getUrl( ), is, headers );
17f16b
-+        response = getSession( )->httpPatchRequest( getUrl( ), is, headers );
17f16b
-     }
17f16b
-     catch ( const CurlException& e )
17f16b
-     {   
17f16b
-@@ -228,7 +225,7 @@
17f16b
- {
17f16b
-     try
17f16b
-     {
17f16b
--        getSession( )->httpDeleteRequest( getUrl( ) );
17f16b
-+        getSession( )->httpDeleteRequest( GDRIVE_METADATA_LINK + getId( ) );
17f16b
-     }
17f16b
-     catch ( const CurlException& e )
17f16b
-     {
17f16b
-@@ -239,8 +236,8 @@
17f16b
- void GDriveObject::move( FolderPtr /*source*/, FolderPtr destination ) 
17f16b
- {  
17f16b
-     Json parentsJson;
17f16b
--    Json parentsValue = GdriveUtils::createJsonFromParentId( destination->getId( ) );
17f16b
--    parentsJson.add( "parents", parentsValue );
17f16b
-+    parentsJson.add( "addParents", Json(destination->getId( ).c_str()) );
17f16b
-+    parentsJson.add( "removeParents", Json(getStringProperty( "cmis:parentId" ).c_str()) );
17f16b
-     
17f16b
-     istringstream is( parentsJson.toString( ) );
17f16b
-     libcmis::HttpResponsePtr response;
17f16b
-@@ -248,7 +245,7 @@
17f16b
-     {   
17f16b
-         vector< string > headers;
17f16b
-         headers.push_back( "Content-Type: application/json" );
17f16b
--        response = getSession( )->httpPutRequest( getUrl( ), is, headers );
17f16b
-+        response = getSession( )->httpPatchRequest( getUrl( ), is, headers );
17f16b
-     }
17f16b
-     catch ( const CurlException& e )
17f16b
-     {   
17f16b
-@@ -262,12 +259,10 @@
17f16b
- 
17f16b
- string GDriveObject::getUrl( )
17f16b
- {
17f16b
--    return getSession( )->getBindingUrl( ) + "/files/" + getId( );
17f16b
--}
17f16b
--
17f16b
--string GDriveObject::getUploadUrl( )
17f16b
--{
17f16b
--    return GDRIVE_UPLOAD_LINKS;
17f16b
-+    // thumbnailLink causes some operations to fail with internal server error,
17f16b
-+    // see https://issuetracker.google.com/issues/36760667
17f16b
-+    return GDRIVE_METADATA_LINK + getId( ) +
17f16b
-+                "?fields=kind,id,name,parents,mimeType,createdTime,modifiedTime,size";
17f16b
- }
17f16b
- 
17f16b
- vector< string> GDriveObject::getMultiStringProperty( const string& propertyName )
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-repository.cxx libcmis/src/libcmis/gdrive-repository.cxx
17f16b
---- libcmis.org/src/libcmis/gdrive-repository.cxx	2021-07-27 19:11:02.676247009 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-repository.cxx	2021-07-27 19:11:18.874246420 +0200
17f16b
-@@ -35,7 +35,7 @@
17f16b
-     m_name = "Google Drive";
17f16b
-     m_description = "Google Drive repository";
17f16b
-     m_productName = "Google Drive";
17f16b
--    m_productVersion = "v2";
17f16b
-+    m_productVersion = "v3";
17f16b
-     m_rootId = "root";
17f16b
-  
17f16b
-     m_capabilities[ ACL ] = "discover";
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-session.cxx libcmis/src/libcmis/gdrive-session.cxx
17f16b
---- libcmis.org/src/libcmis/gdrive-session.cxx	2021-07-27 19:11:02.675247009 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-session.cxx	2021-07-27 19:11:18.874246420 +0200
17f16b
-@@ -124,9 +124,13 @@
17f16b
- 
17f16b
- libcmis::ObjectPtr GDriveSession::getObject( string objectId )
17f16b
- {
17f16b
-+    if(objectId == "root") {
17f16b
-+        return getRootFolder();
17f16b
-+    }
17f16b
-     // Run the http request to get the properties definition
17f16b
-     string res;
17f16b
--    string objectLink = m_bindingUrl + "/files/" + objectId;
17f16b
-+    string objectLink = GDRIVE_METADATA_LINK + objectId +
17f16b
-+         "?fields=kind,id,name,parents,mimeType,createdTime,modifiedTime,thumbnailLink,size";
17f16b
-     try
17f16b
-     {
17f16b
-         res = httpGetRequest( objectLink )->getStream()->str();
17f16b
-@@ -188,9 +192,10 @@
17f16b
-         {
17f16b
-             // Normal child case
17f16b
-             // Ask for the ID of the child if there is any
17f16b
--            string childIdUrl = m_bindingUrl + "/files/" + objectId +
17f16b
--                                "/children/?q=title+=+'" + segment +
17f16b
--                                "'&fields=items:id";
17f16b
-+            // somewhat flawed as names are not necessarily unique in GDrive...
17f16b
-+            string query = libcmis::escape("'" + objectId + "' in parents and trashed = false and name='" + segment + "'");
17f16b
-+
17f16b
-+            string childIdUrl = m_bindingUrl + "/files/?q=" + query + "&fields=files(id)";
17f16b
- 
17f16b
-             string res;
17f16b
-             try
17f16b
-@@ -204,7 +209,7 @@
17f16b
-             Json jsonRes = Json::parse( res );
17f16b
- 
17f16b
-             // Did we get an id?
17f16b
--            Json::JsonVector items = jsonRes["items"].getList();
17f16b
-+            Json::JsonVector items = jsonRes["files"].getList();
17f16b
-             if ( items.empty( ) )
17f16b
-                 throw libcmis::Exception( "Object not found: " + path, "objectNotFound" );
17f16b
- 
17f16b
-@@ -219,6 +224,27 @@
17f16b
-     return getObject( objectId );
17f16b
- }
17f16b
- 
17f16b
-+libcmis::FolderPtr GDriveSession::getRootFolder()
17f16b
-+{
17f16b
-+    // permissions/scope with just drive.file don't allow to get it with the "root" alias/by its actual object-ID
17f16b
-+    Json propsJson;
17f16b
-+
17f16b
-+    // GDrive folder is a file with a different mime type.
17f16b
-+    string mimeType = GDRIVE_FOLDER_MIME_TYPE;
17f16b
-+
17f16b
-+    // Add mimetype to the propsJson
17f16b
-+    Json jsonMimeType( mimeType.c_str( ) );
17f16b
-+    propsJson.add( "mimeType", jsonMimeType );
17f16b
-+    propsJson.add( "id", "root" );
17f16b
-+
17f16b
-+    // Upload meta-datas
17f16b
-+    propsJson.add("cmis:name", "VirtualRoot");
17f16b
-+
17f16b
-+    libcmis::FolderPtr folderPtr( new GDriveFolder( this, propsJson ) );
17f16b
-+
17f16b
-+    return folderPtr;
17f16b
-+}
17f16b
-+
17f16b
- libcmis::ObjectTypePtr GDriveSession::getType( string id )
17f16b
- {
17f16b
-     libcmis::ObjectTypePtr type( new GdriveObjectType( id ) );
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-session.hxx libcmis/src/libcmis/gdrive-session.hxx
17f16b
---- libcmis.org/src/libcmis/gdrive-session.hxx	2021-07-27 19:11:02.675247009 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-session.hxx	2021-07-27 19:11:18.875246420 +0200
17f16b
-@@ -57,6 +57,8 @@
17f16b
- 
17f16b
-         virtual std::vector< libcmis::ObjectTypePtr > getBaseTypes( );
17f16b
- 
17f16b
-+        virtual libcmis::FolderPtr getRootFolder();
17f16b
-+
17f16b
-         virtual std::string getRefreshToken();
17f16b
- 
17f16b
-     private:
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-utils.cxx libcmis/src/libcmis/gdrive-utils.cxx
17f16b
---- libcmis.org/src/libcmis/gdrive-utils.cxx	2021-07-27 19:11:02.677247008 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-utils.cxx	2021-07-27 19:11:18.875246420 +0200
17f16b
-@@ -44,17 +44,17 @@
17f16b
-         convertedKey = "cmis:createdBy";
17f16b
-     else if ( key == "description" )
17f16b
-         convertedKey = "cmis:description";
17f16b
--    else if ( key == "createdDate" )
17f16b
-+    else if ( key == "createdTime" )
17f16b
-         convertedKey = "cmis:creationDate";
17f16b
-     else if ( key == "lastModifyingUserName" )
17f16b
-         convertedKey = "cmis:lastModifiedBy";
17f16b
--    else if ( key == "modifiedDate" )
17f16b
-+    else if ( key == "modifiedTime" )
17f16b
-         convertedKey = "cmis:lastModificationDate";
17f16b
--    else if ( key == "title" )
17f16b
-+    else if ( key == "name" )
17f16b
-         convertedKey = "cmis:contentStreamFileName";
17f16b
-     else if ( key == "mimeType" )
17f16b
-         convertedKey = "cmis:contentStreamMimeType";
17f16b
--    else if ( key == "fileSize" )
17f16b
-+    else if ( key == "size" )
17f16b
-         convertedKey = "cmis:contentStreamLength";
17f16b
-     else if ( key == "editable" )
17f16b
-         convertedKey = "cmis:isImmutable";
17f16b
-@@ -72,21 +72,21 @@
17f16b
-     else if ( key == "cmis:createdBy" )
17f16b
-         convertedKey = "ownerNames";
17f16b
-     else if ( key == "cmis:creationDate" )
17f16b
--        convertedKey = "createdDate";
17f16b
-+        convertedKey = "createdTime";
17f16b
-     else if ( key == "cmis:description" )
17f16b
-         convertedKey = "description";
17f16b
-     else if ( key == "cmis:lastModifiedBy" )
17f16b
-         convertedKey = "lastModifyingUserName";
17f16b
-     else if ( key == "cmis:lastModificationDate" )
17f16b
--        convertedKey = "modifiedDate";
17f16b
-+        convertedKey = "modifiedTime";
17f16b
-     else if ( key == "cmis:contentStreamFileName" )
17f16b
--        convertedKey = "title";
17f16b
-+        convertedKey = "name";
17f16b
-     else if ( key == "cmis:name" )
17f16b
--        convertedKey = "title";
17f16b
-+        convertedKey = "name";
17f16b
-     else if ( key == "cmis:contentStreamMimeType" )
17f16b
-         convertedKey = "mimeType";
17f16b
-     else if ( key == "cmis:contentStreamLength" )
17f16b
--        convertedKey = "fileSize";
17f16b
-+        convertedKey = "size";
17f16b
-     else if ( key == "cmis:isImmutable" )
17f16b
-         convertedKey = "editable";
17f16b
-     else if ( key == "cmis:parentId" )
17f16b
-@@ -124,9 +124,9 @@
17f16b
- bool GdriveUtils::checkUpdatable( const string& key )
17f16b
- {
17f16b
-     // taken from https://developers.google.com/drive/v2/reference/files
17f16b
--    bool updatable = ( key == "title" ||
17f16b
-+    bool updatable = ( key == "name" ||
17f16b
-                   key == "description" ||
17f16b
--                  key == "modifiedDate" ||
17f16b
-+                  key == "modifiedTime" ||
17f16b
-                   key == "lastViewedByMeDate" );
17f16b
-     return updatable;    
17f16b
- }
17f16b
-@@ -143,18 +143,11 @@
17f16b
- 
17f16b
- Json GdriveUtils::createJsonFromParentId( const string& parentId )
17f16b
- {
17f16b
--    Json parentValue( parentId.c_str( ) );
17f16b
--    
17f16b
-     // parents is a Json array
17f16b
-     Json firstParent;
17f16b
--    firstParent.add( "id", parentValue );
17f16b
--    
17f16b
--    Json::JsonVector parents;
17f16b
--    parents.insert( parents.begin( ), firstParent );
17f16b
-+    firstParent.add( Json( parentId.c_str() ) );
17f16b
-     
17f16b
--    Json parentsValue( parents );
17f16b
--
17f16b
--    return parentsValue;
17f16b
-+    return firstParent;
17f16b
- }
17f16b
- 
17f16b
- vector< string > GdriveUtils::parseGdriveProperty( string key, Json json )
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-utils.hxx libcmis/src/libcmis/gdrive-utils.hxx
17f16b
---- libcmis.org/src/libcmis/gdrive-utils.hxx	2021-07-27 19:11:02.677247008 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-utils.hxx	2021-07-27 19:11:18.875246420 +0200
17f16b
-@@ -35,7 +35,8 @@
17f16b
- #include "json-utils.hxx"
17f16b
- 
17f16b
- static const std::string GDRIVE_FOLDER_MIME_TYPE = "application/vnd.google-apps.folder" ;
17f16b
--static const std::string GDRIVE_UPLOAD_LINKS = "https://www.googleapis.com/upload/drive/v2/files/";
17f16b
-+static const std::string GDRIVE_UPLOAD_LINK = "https://www.googleapis.com/upload/drive/v3/files/";
17f16b
-+static const std::string GDRIVE_METADATA_LINK = "https://www.googleapis.com/drive/v3/files/";
17f16b
- 
17f16b
- class GdriveUtils
17f16b
- {
17f16b
-diff -ur libcmis.org/src/libcmis/oauth2-handler.cxx libcmis/src/libcmis/oauth2-handler.cxx
17f16b
---- libcmis.org/src/libcmis/oauth2-handler.cxx	2021-07-27 19:11:02.676247009 +0200
17f16b
-+++ libcmis/src/libcmis/oauth2-handler.cxx	2021-07-27 19:11:18.875246420 +0200
17f16b
-@@ -92,8 +92,11 @@
17f16b
-         "code="              + authCode +
17f16b
-         "&client_id="        + m_data->getClientId() +
17f16b
-         "&redirect_uri="     + m_data->getRedirectUri() +
17f16b
--        "&scope="            + libcmis::escape( m_data->getScope() ) +
17f16b
-         "&grant_type=authorization_code" ;
17f16b
-+    if(boost::starts_with(m_data->getTokenUrl(), "https://oauth2.googleapis.com/"))
17f16b
-+        post += "&client_secret="    + m_data->getClientSecret();
17f16b
-+    else
17f16b
-+        post += "&scope="            + libcmis::escape( m_data->getScope() );
17f16b
- 
17f16b
-     istringstream is( post );
17f16b
- 
17f16b
-@@ -104,7 +107,7 @@
17f16b
-         resp = m_session->httpPostRequest ( m_data->getTokenUrl(), is,
17f16b
-                                         "application/x-www-form-urlencoded" );
17f16b
-     }
17f16b
--    catch ( const CurlException& )
17f16b
-+    catch ( const CurlException& e)
17f16b
-     {
17f16b
-         throw libcmis::Exception(
17f16b
-                 "Couldn't get tokens from the authorization code ");
17f16b
-@@ -122,6 +125,8 @@
17f16b
-         "refresh_token="     + m_refresh +
17f16b
-         "&client_id="        + m_data->getClientId() +
17f16b
-         "&grant_type=refresh_token" ;
17f16b
-+    if(boost::starts_with(m_data->getTokenUrl(), "https://oauth2.googleapis.com/"))
17f16b
-+        post += "&client_secret="    + m_data->getClientSecret();
17f16b
- 
17f16b
-     istringstream is( post );
17f16b
-     libcmis::HttpResponsePtr resp;
17f16b
-@@ -130,7 +135,7 @@
17f16b
-         resp = m_session->httpPostRequest( m_data->getTokenUrl( ), is,
17f16b
-                                            "application/x-www-form-urlencoded" );
17f16b
-     }
17f16b
--    catch (const CurlException& )
17f16b
-+    catch (const CurlException& e )
17f16b
-     {
17f16b
-         throw libcmis::Exception( "Couldn't refresh token ");
17f16b
-     }
17f16b
-diff -ur libcmis.org/src/libcmis/oauth2-providers.cxx libcmis/src/libcmis/oauth2-providers.cxx
17f16b
---- libcmis.org/src/libcmis/oauth2-providers.cxx	2021-07-27 19:11:02.679247008 +0200
17f16b
-+++ libcmis/src/libcmis/oauth2-providers.cxx	2021-07-27 19:11:18.886246420 +0200
17f16b
-@@ -80,172 +80,8 @@
17f16b
- 
17f16b
- }
17f16b
- 
17f16b
--string OAuth2Providers::OAuth2Gdrive( HttpSession* session, const string& authUrl,
17f16b
--                                      const string& username, const string& password )
17f16b
--{
17f16b
--    /* This member function implements 'Google OAuth 2.0'
17f16b
--     *
17f16b
--     * The interaction is carried out by libcmis, with no web browser involved.
17f16b
--     *
17f16b
--     * Normal sequence (without 2FA) is:
17f16b
--     * 1) a get to activate login page
17f16b
--     *    receive first login page, html format
17f16b
--     * 2) subsequent post to sent email
17f16b
--     *    receive html page for password input
17f16b
--     * 3) subsequent post to send password
17f16b
--     *    receive html page for application consent
17f16b
--     * 4) subsequent post to send a consent for the application
17f16b
--     *    receive a single-use authorization code
17f16b
--     *    this code is returned as a string
17f16b
--     *
17f16b
--     * Sequence with 2FA is:
17f16b
--     * 1) a get to activate login page
17f16b
--     *    receive first login page, html format
17f16b
--     * 2) subsequent post to sent email
17f16b
--     *    receive html page for password input
17f16b
--     * 3) subsequent post to send password
17f16b
--     *    receive html page for pin input
17f16b
--     * 3b) subsequent post to send pin number
17f16b
--     *    receive html page for application consent
17f16b
--     * 4) subsequent post to send a consent for the application
17f16b
--     *    receive a single-use authorization code
17f16b
--     *    this code is returned as a string
17f16b
--     */
17f16b
--
17f16b
--    static const string CONTENT_TYPE( "application/x-www-form-urlencoded" );
17f16b
--    // STEP 1: get login page
17f16b
--    string res;
17f16b
--    try
17f16b
--    {
17f16b
--        // send the first get, receive the html login page
17f16b
--        res = session->httpGetRequest( authUrl )->getStream( )->str( );
17f16b
--    }
17f16b
--    catch ( const CurlException& )
17f16b
--    {
17f16b
--        return string( );
17f16b
--    }
17f16b
--
17f16b
--    // STEP 2: send email
17f16b
--
17f16b
--    string loginEmailPost, loginEmailLink;
17f16b
--    if ( !parseResponse( res.c_str( ), loginEmailPost, loginEmailLink ) )
17f16b
--        return string( );
17f16b
--
17f16b
--    loginEmailPost += "Email=";
17f16b
--    loginEmailPost += escapeForm( username );
17f16b
--
17f16b
--    istringstream loginEmailIs( loginEmailPost );
17f16b
--    string loginEmailRes;
17f16b
--    try
17f16b
--    {
17f16b
--        // send a post with user email, receive the html page for password input
17f16b
--        loginEmailRes = session->httpPostRequest ( loginEmailLink, loginEmailIs, CONTENT_TYPE )
17f16b
--                        ->getStream( )->str( );
17f16b
--    }
17f16b
--    catch ( const CurlException& )
17f16b
--    {
17f16b
--        return string( );
17f16b
--    }
17f16b
--
17f16b
--    // STEP 3: password page
17f16b
--
17f16b
--    string loginPasswdPost, loginPasswdLink;
17f16b
--    if ( !parseResponse( loginEmailRes.c_str( ), loginPasswdPost, loginPasswdLink ) )
17f16b
--        return string( );
17f16b
--
17f16b
--    loginPasswdPost += "Passwd=";
17f16b
--    loginPasswdPost += escapeForm( password );
17f16b
--
17f16b
--    istringstream loginPasswdIs( loginPasswdPost );
17f16b
--    string loginPasswdRes;
17f16b
--    try
17f16b
--    {
17f16b
--        // send a post with user password, receive the application consent page
17f16b
--        loginPasswdRes = session->httpPostRequest ( loginPasswdLink, loginPasswdIs, CONTENT_TYPE )
17f16b
--                        ->getStream( )->str( );
17f16b
--    }
17f16b
--    catch ( const CurlException& )
17f16b
--    {
17f16b
--        return string( );
17f16b
--    }
17f16b
--
17f16b
--    string approvalPost, approvalLink;
17f16b
--    if ( !parseResponse( loginPasswdRes. c_str( ), approvalPost, approvalLink) )
17f16b
--        return string( );
17f16b
--
17f16b
--    // when 2FA is enabled, link doesn't start with 'http'
17f16b
--    if ( approvalLink.compare(0, 4, "http") != 0 )
17f16b
--    {
17f16b
--        // STEP 3b: 2 Factor Authentication, pin code request
17f16b
--
17f16b
--        string loginChallengePost( approvalPost );
17f16b
--        string loginChallengeLink( approvalLink );
17f16b
--
17f16b
--        libcmis::OAuth2AuthCodeProvider fallbackProvider = libcmis::SessionFactory::getOAuth2AuthCodeProvider( );
17f16b
--        unique_ptr< char, void (*)( void * ) > pin{ fallbackProvider( "", "", "" ), free };
17f16b
--
17f16b
--        if( !pin )
17f16b
--        {
17f16b
--            // unset OAuth2AuthCode Provider to avoid showing pin request again in the HttpSession::oauth2Authenticate
17f16b
--            libcmis::SessionFactory::setOAuth2AuthCodeProvider( NULL );
17f16b
--            return string( );
17f16b
--        }
17f16b
--
17f16b
--        loginChallengeLink = "https://accounts.google.com" + loginChallengeLink;
17f16b
--        loginChallengePost += string( PIN_INPUT_NAME ) + "=";
17f16b
--        loginChallengePost += string( pin.get() );
17f16b
--
17f16b
--        istringstream loginChallengeIs( loginChallengePost );
17f16b
--        string loginChallengeRes;
17f16b
--        try
17f16b
--        {
17f16b
--            // send a post with pin, receive the application consent page
17f16b
--            loginChallengeRes = session->httpPostRequest ( loginChallengeLink, loginChallengeIs, CONTENT_TYPE )
17f16b
--                            ->getStream( )->str( );
17f16b
--        }
17f16b
--        catch ( const CurlException& )
17f16b
--        {
17f16b
--            return string( );
17f16b
--        }
17f16b
--
17f16b
--        approvalPost = string();
17f16b
--        approvalLink = string();
17f16b
--
17f16b
--        if ( !parseResponse( loginChallengeRes. c_str( ), approvalPost, approvalLink) )
17f16b
--            return string( );
17f16b
--    }
17f16b
--    else if( approvalLink.compare( "https://accounts.google.com/ServiceLoginAuth" ) == 0 )
17f16b
--    {
17f16b
--        // wrong password,
17f16b
--        // unset OAuth2AuthCode Provider to avoid showing pin request again in the HttpSession::oauth2Authenticate
17f16b
--        libcmis::SessionFactory::setOAuth2AuthCodeProvider( NULL );
17f16b
--        return string( );
17f16b
--    }
17f16b
--
17f16b
--    // STEP 4: allow libcmis to access google drive
17f16b
--    approvalPost += "submit_access=true";
17f16b
--
17f16b
--    istringstream approvalIs( approvalPost );
17f16b
--    string approvalRes;
17f16b
--    try
17f16b
--    {
17f16b
--        // send a post with application consent
17f16b
--        approvalRes = session->httpPostRequest ( approvalLink, approvalIs,
17f16b
--                            CONTENT_TYPE) ->getStream( )->str( );
17f16b
--    }
17f16b
--    catch ( const CurlException& e )
17f16b
--    {
17f16b
--        throw e.getCmisException( );
17f16b
--    }
17f16b
--
17f16b
--    // Take the authentication code from the text bar
17f16b
--    string code = parseCode( approvalRes.c_str( ) );
17f16b
--
17f16b
--    return code;
17f16b
--}
17f16b
--
17f16b
--string OAuth2Providers::OAuth2Onedrive( HttpSession* /*session*/, const string& /*authUrl*/,
17f16b
--                                      const string& /*username*/, const string& /*password*/ )
17f16b
-+string OAuth2Providers::OAuth2Dummy( HttpSession* /*session*/, const string& /*authUrl*/,
17f16b
-+                                     const string& /*username*/, const string& /*password*/ )
17f16b
- {
17f16b
-     return string( );
17f16b
- }
17f16b
-@@ -314,12 +150,8 @@
17f16b
-         // For Alfresco in the cloud, only match the hostname as there can be several
17f16b
-         // binding URLs created with it.
17f16b
-         return OAuth2Alfresco;
17f16b
--    else if ( boost::starts_with( url, "https://www.googleapis.com/drive/v2" ) )
17f16b
--        return OAuth2Gdrive;
17f16b
--    else if ( boost::starts_with( url, "https://graph.microsoft.com/v1.0" ) )
17f16b
--        return OAuth2Onedrive;
17f16b
- 
17f16b
--    return OAuth2Gdrive;
17f16b
-+    return OAuth2Dummy;
17f16b
- }
17f16b
- 
17f16b
- int OAuth2Providers::parseResponse ( const char* response, string& post, string& link )
17f16b
-diff -ur libcmis.org/src/libcmis/oauth2-providers.hxx libcmis/src/libcmis/oauth2-providers.hxx
17f16b
---- libcmis.org/src/libcmis/oauth2-providers.hxx	2021-07-27 19:11:02.678247008 +0200
17f16b
-+++ libcmis/src/libcmis/oauth2-providers.hxx	2021-07-27 19:11:18.886246420 +0200
17f16b
-@@ -39,12 +39,8 @@
17f16b
- class OAuth2Providers
17f16b
- {
17f16b
-     public :
17f16b
--        static std::string OAuth2Gdrive( HttpSession* session, const std::string& authUrl, 
17f16b
-+        static std::string OAuth2Dummy( HttpSession* session, const std::string& authUrl,
17f16b
-                                        const std::string& username, const std::string& password );
17f16b
--
17f16b
--        static std::string OAuth2Onedrive( HttpSession* session, const std::string& authUrl, 
17f16b
--                                       const std::string& username, const std::string& password );
17f16b
--
17f16b
-         static std::string OAuth2Alfresco( HttpSession* session, const std::string& authUrl, 
17f16b
-                                        const std::string& username, const std::string& password );
17f16b
- 
17f16b
-diff -ur libcmis.org/src/libcmis/session-factory.cxx libcmis/src/libcmis/session-factory.cxx
17f16b
---- libcmis.org/src/libcmis/session-factory.cxx	2021-07-27 19:11:02.679247008 +0200
17f16b
-+++ libcmis/src/libcmis/session-factory.cxx	2021-07-27 19:11:18.886246420 +0200
17f16b
-@@ -66,7 +66,7 @@
17f16b
-         if ( !bindingUrl.empty( ) )
17f16b
-         {
17f16b
-             // Try the special cases based on the binding URL
17f16b
--            if ( bindingUrl == "https://www.googleapis.com/drive/v2" )
17f16b
-+            if ( bindingUrl == "https://www.googleapis.com/drive/v3" )
17f16b
-             {
17f16b
-                 session = new GDriveSession( bindingUrl, username, password,
17f16b
-                                              oauth2, verbose );
17f16b
diff --git a/external/libcmis/libcmis_oauth_pw_as_refreshtoken.patch.1 b/external/libcmis/libcmis_oauth_pw_as_refreshtoken.patch.1
17f16b
deleted file mode 100644
17f16b
index a8cb06509421..000000000000
17f16b
--- a/external/libcmis/libcmis_oauth_pw_as_refreshtoken.patch.1
17f16b
+++ /dev/null
17f16b
@@ -1,185 +0,0 @@
17f16b
-diff -ur libcmis.org/inc/libcmis/session.hxx libcmis/inc/libcmis/session.hxx
17f16b
---- libcmis.org/inc/libcmis/session.hxx	2021-07-27 19:09:42.580249917 +0200
17f16b
-+++ libcmis/inc/libcmis/session.hxx	2021-07-27 19:10:02.368249199 +0200
17f16b
-@@ -95,6 +95,8 @@
17f16b
-                 certificate exception feature available on common web browser.
17f16b
-               */
17f16b
-             virtual void setNoSSLCertificateCheck( bool noCheck ) = 0;
17f16b
-+
17f16b
-+            virtual std::string getRefreshToken() { return ""; };
17f16b
-     };
17f16b
- }
17f16b
- 
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-session.cxx libcmis/src/libcmis/gdrive-session.cxx
17f16b
---- libcmis.org/src/libcmis/gdrive-session.cxx	2021-07-27 19:09:42.581249917 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-session.cxx	2021-07-27 19:10:02.369249198 +0200
17f16b
-@@ -70,6 +70,46 @@
17f16b
- {
17f16b
- }
17f16b
- 
17f16b
-+
17f16b
-+void GDriveSession::setOAuth2Data( libcmis::OAuth2DataPtr oauth2 )
17f16b
-+{
17f16b
-+    m_oauth2Handler = new OAuth2Handler( this, oauth2 );
17f16b
-+    m_oauth2Handler->setOAuth2Parser( OAuth2Providers::getOAuth2Parser( getBindingUrl( ) ) );
17f16b
-+
17f16b
-+    oauth2Authenticate( );
17f16b
-+}
17f16b
-+
17f16b
-+void GDriveSession::oauth2Authenticate()
17f16b
-+{
17f16b
-+    // treat the supplied password as refresh token
17f16b
-+    if (!m_password.empty())
17f16b
-+    {
17f16b
-+        try
17f16b
-+        {
17f16b
-+            m_inOAuth2Authentication = true;
17f16b
-+
17f16b
-+            m_oauth2Handler->setRefreshToken(m_password);
17f16b
-+            // Try to get new access tokens using the stored refreshtoken
17f16b
-+            m_oauth2Handler->refresh();
17f16b
-+            m_inOAuth2Authentication = false;
17f16b
-+        }
17f16b
-+        catch (const CurlException &e)
17f16b
-+        {
17f16b
-+            m_inOAuth2Authentication = false;
17f16b
-+            // refresh token expired or invalid, trigger initial auth (that in turn will hit the fallback with copy'n'paste method)
17f16b
-+            BaseSession::oauth2Authenticate();
17f16b
-+        }
17f16b
-+    }
17f16b
-+    else
17f16b
-+    {
17f16b
-+        BaseSession::oauth2Authenticate();
17f16b
-+    }
17f16b
-+}
17f16b
-+
17f16b
-+string GDriveSession::getRefreshToken() {
17f16b
-+    return HttpSession::getRefreshToken();
17f16b
-+}
17f16b
-+
17f16b
- libcmis::RepositoryPtr GDriveSession::getRepository( )
17f16b
- {
17f16b
-     // Return a dummy repository since GDrive doesn't have that notion
17f16b
-diff -ur libcmis.org/src/libcmis/gdrive-session.hxx libcmis/src/libcmis/gdrive-session.hxx
17f16b
---- libcmis.org/src/libcmis/gdrive-session.hxx	2021-07-27 19:09:42.583249917 +0200
17f16b
-+++ libcmis/src/libcmis/gdrive-session.hxx	2021-07-27 19:10:02.369249198 +0200
17f16b
-@@ -57,8 +57,14 @@
17f16b
- 
17f16b
-         virtual std::vector< libcmis::ObjectTypePtr > getBaseTypes( );
17f16b
- 
17f16b
-+        virtual std::string getRefreshToken();
17f16b
-+
17f16b
-     private:
17f16b
-         GDriveSession( );
17f16b
-+
17f16b
-+        virtual void setOAuth2Data( libcmis::OAuth2DataPtr oauth2 );
17f16b
-+
17f16b
-+        void oauth2Authenticate( );
17f16b
- };
17f16b
- 
17f16b
- #endif /* _GDRIVE_SESSION_HXX_ */
17f16b
-diff -ur libcmis.org/src/libcmis/http-session.hxx libcmis/src/libcmis/http-session.hxx
17f16b
---- libcmis.org/src/libcmis/http-session.hxx	2021-07-27 19:09:42.582249917 +0200
17f16b
-+++ libcmis/src/libcmis/http-session.hxx	2021-07-27 19:10:02.369249198 +0200
17f16b
-@@ -148,7 +148,7 @@
17f16b
- 
17f16b
-         void setNoSSLCertificateCheck( bool noCheck );
17f16b
- 
17f16b
--        std::string getRefreshToken( );
17f16b
-+        virtual std::string getRefreshToken( );
17f16b
- 
17f16b
-     protected:
17f16b
-         HttpSession( );
17f16b
-diff -ur libcmis.org/src/libcmis/oauth2-handler.cxx libcmis/src/libcmis/oauth2-handler.cxx
17f16b
---- libcmis.org/src/libcmis/oauth2-handler.cxx	2021-07-27 19:09:42.582249917 +0200
17f16b
-+++ libcmis/src/libcmis/oauth2-handler.cxx	2021-07-27 19:10:02.369249198 +0200
17f16b
-@@ -158,6 +158,11 @@
17f16b
-     return m_refresh;
17f16b
- }
17f16b
- 
17f16b
-+void OAuth2Handler::setRefreshToken( string refreshToken )
17f16b
-+{
17f16b
-+    m_refresh = refreshToken;
17f16b
-+}
17f16b
-+
17f16b
- string OAuth2Handler::getHttpHeader( )
17f16b
- {
17f16b
-     string header;
17f16b
-diff -ur libcmis.org/src/libcmis/oauth2-handler.hxx libcmis/src/libcmis/oauth2-handler.hxx
17f16b
---- libcmis.org/src/libcmis/oauth2-handler.hxx	2021-07-27 19:09:42.582249917 +0200
17f16b
-+++ libcmis/src/libcmis/oauth2-handler.hxx	2021-07-27 19:10:02.370249198 +0200
17f16b
-@@ -61,6 +61,7 @@
17f16b
- 
17f16b
-         std::string getAccessToken( ) ;
17f16b
-         std::string getRefreshToken( ) ;
17f16b
-+        void setRefreshToken( std::string refreshToken ) ;
17f16b
- 
17f16b
-         // adding HTTP auth header
17f16b
-         std::string getHttpHeader( ) ;
17f16b
-diff -ur libcmis.org/src/libcmis/onedrive-session.cxx libcmis/src/libcmis/onedrive-session.cxx
17f16b
---- libcmis.org/src/libcmis/onedrive-session.cxx	2021-07-27 19:09:42.583249917 +0200
17f16b
-+++ libcmis/src/libcmis/onedrive-session.cxx	2021-07-27 19:10:02.370249198 +0200
17f16b
-@@ -68,6 +68,45 @@
17f16b
- {
17f16b
- }
17f16b
- 
17f16b
-+void OneDriveSession::setOAuth2Data( libcmis::OAuth2DataPtr oauth2 )
17f16b
-+{
17f16b
-+    m_oauth2Handler = new OAuth2Handler( this, oauth2 );
17f16b
-+    m_oauth2Handler->setOAuth2Parser( OAuth2Providers::getOAuth2Parser( getBindingUrl( ) ) );
17f16b
-+
17f16b
-+    oauth2Authenticate( );
17f16b
-+}
17f16b
-+
17f16b
-+void OneDriveSession::oauth2Authenticate()
17f16b
-+{
17f16b
-+    // treat the supplied password as refresh token
17f16b
-+    if (!m_password.empty())
17f16b
-+    {
17f16b
-+        try
17f16b
-+        {
17f16b
-+            m_inOAuth2Authentication = true;
17f16b
-+
17f16b
-+            m_oauth2Handler->setRefreshToken(m_password);
17f16b
-+            // Try to get new access tokens using the stored refreshtoken
17f16b
-+            m_oauth2Handler->refresh();
17f16b
-+            m_inOAuth2Authentication = false;
17f16b
-+        }
17f16b
-+        catch (const CurlException &e)
17f16b
-+        {
17f16b
-+            m_inOAuth2Authentication = false;
17f16b
-+            // refresh token expired or invalid, trigger initial auth (that in turn will hit the fallback with copy'n'paste method)
17f16b
-+            BaseSession::oauth2Authenticate();
17f16b
-+        }
17f16b
-+    }
17f16b
-+    else
17f16b
-+    {
17f16b
-+        BaseSession::oauth2Authenticate();
17f16b
-+    }
17f16b
-+}
17f16b
-+
17f16b
-+string OneDriveSession::getRefreshToken() {
17f16b
-+    return HttpSession::getRefreshToken();
17f16b
-+}
17f16b
-+
17f16b
- libcmis::RepositoryPtr OneDriveSession::getRepository( )
17f16b
- {
17f16b
-     // Return a dummy repository since OneDrive doesn't have that notion
17f16b
-diff -ur libcmis.org/src/libcmis/onedrive-session.hxx libcmis/src/libcmis/onedrive-session.hxx
17f16b
---- libcmis.org/src/libcmis/onedrive-session.hxx	2021-07-27 19:09:42.583249917 +0200
17f16b
-+++ libcmis/src/libcmis/onedrive-session.hxx	2021-07-27 19:10:02.370249198 +0200
17f16b
-@@ -62,8 +62,14 @@
17f16b
- 
17f16b
-        bool isAPathMatch( Json objectJson, std::string path );
17f16b
- 
17f16b
-+       virtual std::string getRefreshToken();
17f16b
-+
17f16b
-     private:
17f16b
-         OneDriveSession( );
17f16b
-+
17f16b
-+        virtual void setOAuth2Data( libcmis::OAuth2DataPtr oauth2 );
17f16b
-+
17f16b
-+        void oauth2Authenticate( );
17f16b
- };
17f16b
- 
17f16b
- #endif /* _ONEDRIVE_SESSION_HXX_ */
17f16b
diff --git a/officecfg/registry/data/org/openoffice/Office/Common.xcu b/officecfg/registry/data/org/openoffice/Office/Common.xcu
17f16b
index fde7c90f9b26..816d22bc993c 100644
17f16b
--- a/officecfg/registry/data/org/openoffice/Office/Common.xcu
17f16b
+++ b/officecfg/registry/data/org/openoffice/Office/Common.xcu
17f16b
@@ -433,7 +433,7 @@
17f16b
     </prop>
17f16b
     <prop oor:name="CmisServersUrls">
17f16b
       <value>
17f16b
-        <it>https://www.googleapis.com/drive/v3</it>
17f16b
+        <it>https://www.googleapis.com/drive/v2</it>
17f16b
         <it>https://graph.microsoft.com/v1.0</it>
17f16b
         <it>https://api.alfresco.com/cmis/versions/1.0/atom/</it>
17f16b
         <it></it>
17f16b
diff --git a/ucb/source/ucp/cmis/auth_provider.cxx b/ucb/source/ucp/cmis/auth_provider.cxx
17f16b
index c4407f47cc3f..dd7b4f9f1e3c 100644
17f16b
--- a/ucb/source/ucp/cmis/auth_provider.cxx
17f16b
+++ b/ucb/source/ucp/cmis/auth_provider.cxx
17f16b
@@ -11,10 +11,7 @@
17f16b
 #define STD_TO_OUSTR( str ) OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
17f16b
 
17f16b
 #include <com/sun/star/task/XInteractionHandler.hpp>
17f16b
-#include <com/sun/star/task/PasswordContainer.hpp>
17f16b
-#include <com/sun/star/task/XPasswordContainer2.hpp>
17f16b
 
17f16b
-#include <comphelper/processfactory.hxx>
17f16b
 #include <ucbhelper/simpleauthenticationrequest.hxx>
17f16b
 #include <ucbhelper/authenticationfallback.hxx>
17f16b
 
17f16b
@@ -67,91 +64,6 @@ namespace cmis
17f16b
         return false;
17f16b
     }
17f16b
 
17f16b
-    string AuthProvider::getRefreshToken(string& rUsername)
17f16b
-    {
17f16b
-        string refreshToken;
17f16b
-        const css::uno::Reference<css::ucb::XCommandEnvironment> xEnv = getXEnv();
17f16b
-        if (xEnv.is())
17f16b
-        {
17f16b
-            uno::Reference<task::XInteractionHandler> xIH = xEnv->getInteractionHandler();
17f16b
-
17f16b
-            if (rUsername.empty())
17f16b
-            {
17f16b
-                rtl::Reference<ucbhelper::SimpleAuthenticationRequest> xRequest
17f16b
-                    = new ucbhelper::SimpleAuthenticationRequest(
17f16b
-                        m_sUrl, m_sBindingUrl,
17f16b
-                        ucbhelper::SimpleAuthenticationRequest::EntityType::ENTITY_NA, OUString(),
17f16b
-                        ucbhelper::SimpleAuthenticationRequest::EntityType::ENTITY_MODIFY,
17f16b
-                        STD_TO_OUSTR(rUsername),
17f16b
-                        ucbhelper::SimpleAuthenticationRequest::EntityType::ENTITY_NA, OUString());
17f16b
-                xIH->handle(xRequest.get());
17f16b
-
17f16b
-                rtl::Reference<ucbhelper::InteractionContinuation> xSelection
17f16b
-                    = xRequest->getSelection();
17f16b
-
17f16b
-                if (xSelection.is())
17f16b
-                {
17f16b
-                    // Handler handled the request.
17f16b
-                    uno::Reference<task::XInteractionAbort> xAbort(xSelection.get(),
17f16b
-                                                                   uno::UNO_QUERY);
17f16b
-                    if (!xAbort.is())
17f16b
-                    {
17f16b
-                        const rtl::Reference<ucbhelper::InteractionSupplyAuthentication>& xSupp
17f16b
-                            = xRequest->getAuthenticationSupplier();
17f16b
-
17f16b
-                        rUsername = OUSTR_TO_STDSTR(xSupp->getUserName());
17f16b
-                    }
17f16b
-                }
17f16b
-            }
17f16b
-
17f16b
-            uno::Reference<uno::XComponentContext> xContext
17f16b
-                = ::comphelper::getProcessComponentContext();
17f16b
-            uno::Reference<task::XPasswordContainer2> xMasterPasswd
17f16b
-                = task::PasswordContainer::create(xContext);
17f16b
-            if (xMasterPasswd->hasMasterPassword())
17f16b
-            {
17f16b
-                xMasterPasswd->authorizateWithMasterPassword(xIH);
17f16b
-            }
17f16b
-            if (xMasterPasswd->isPersistentStoringAllowed())
17f16b
-            {
17f16b
-                task::UrlRecord aRec
17f16b
-                    = xMasterPasswd->findForName(m_sBindingUrl, STD_TO_OUSTR(rUsername), xIH);
17f16b
-                if (aRec.UserList.hasElements() && aRec.UserList[0].Passwords.hasElements())
17f16b
-                    refreshToken = OUSTR_TO_STDSTR(aRec.UserList[0].Passwords[0]);
17f16b
-            }
17f16b
-        }
17f16b
-        return refreshToken;
17f16b
-    }
17f16b
-
17f16b
-    bool AuthProvider::storeRefreshToken(const string& username, const string& password,
17f16b
-                                         const string& refreshToken)
17f16b
-    {
17f16b
-        if (refreshToken.empty())
17f16b
-            return false;
17f16b
-        if (password == refreshToken)
17f16b
-            return true;
17f16b
-        const css::uno::Reference<css::ucb::XCommandEnvironment> xEnv = getXEnv();
17f16b
-        if (xEnv.is())
17f16b
-        {
17f16b
-            uno::Reference<task::XInteractionHandler> xIH = xEnv->getInteractionHandler();
17f16b
-            uno::Reference<uno::XComponentContext> xContext
17f16b
-                = ::comphelper::getProcessComponentContext();
17f16b
-            uno::Reference<task::XPasswordContainer2> xMasterPasswd
17f16b
-                = task::PasswordContainer::create(xContext);
17f16b
-            uno::Sequence<OUString> aPasswd{ STD_TO_OUSTR(refreshToken) };
17f16b
-            if (xMasterPasswd->isPersistentStoringAllowed())
17f16b
-            {
17f16b
-                if (xMasterPasswd->hasMasterPassword())
17f16b
-                {
17f16b
-                    xMasterPasswd->authorizateWithMasterPassword(xIH);
17f16b
-                }
17f16b
-                xMasterPasswd->addPersistent(m_sBindingUrl, STD_TO_OUSTR(username), aPasswd, xIH);
17f16b
-                return true;
17f16b
-            }
17f16b
-        }
17f16b
-        return false;
17f16b
-    }
17f16b
-
17f16b
     css::uno::WeakReference< css::ucb::XCommandEnvironment> AuthProvider::sm_xEnv;
17f16b
 
17f16b
     void AuthProvider::setXEnv(const css::uno::Reference< css::ucb::XCommandEnvironment>& xEnv )
17f16b
@@ -164,7 +76,7 @@ namespace cmis
17f16b
         return sm_xEnv;
17f16b
     }
17f16b
 
17f16b
-    char* AuthProvider::copyWebAuthCodeFallback( const char* url,
17f16b
+    char* AuthProvider::onedriveAuthCodeFallback( const char* url,
17f16b
             const char* /*username*/,
17f16b
             const char* /*password*/ )
17f16b
     {
17f16b
@@ -208,6 +120,46 @@ namespace cmis
17f16b
 
17f16b
         return strdup( "" );
17f16b
     }
17f16b
+
17f16b
+    char* AuthProvider::gdriveAuthCodeFallback( const char* /*url*/,
17f16b
+            const char* /*username*/,
17f16b
+            const char* /*password*/ )
17f16b
+    {
17f16b
+        const css::uno::Reference<
17f16b
+            css::ucb::XCommandEnvironment> xEnv = getXEnv( );
17f16b
+
17f16b
+        if ( xEnv.is() )
17f16b
+        {
17f16b
+            uno::Reference< task::XInteractionHandler > xIH
17f16b
+                = xEnv->getInteractionHandler();
17f16b
+
17f16b
+            if ( xIH.is() )
17f16b
+            {
17f16b
+                rtl::Reference< ucbhelper::AuthenticationFallbackRequest > xRequest
17f16b
+                    = new ucbhelper::AuthenticationFallbackRequest (
17f16b
+                            "PIN:", "" );
17f16b
+
17f16b
+                xIH->handle( xRequest.get() );
17f16b
+
17f16b
+                rtl::Reference< ucbhelper::InteractionContinuation > xSelection
17f16b
+                    = xRequest->getSelection();
17f16b
+
17f16b
+                if ( xSelection.is() )
17f16b
+                {
17f16b
+                    // Handler handled the request.
17f16b
+                    const rtl::Reference< ucbhelper::InteractionAuthFallback >&
17f16b
+                        xAuthFallback = xRequest->getAuthFallbackInter( );
17f16b
+                    if ( xAuthFallback.is() )
17f16b
+                    {
17f16b
+                        OUString code = xAuthFallback->getCode( );
17f16b
+                        return strdup( OUSTR_TO_STDSTR( code ).c_str( ) );
17f16b
+                    }
17f16b
+                }
17f16b
+            }
17f16b
+        }
17f16b
+
17f16b
+        return strdup( "" );
17f16b
+    }
17f16b
 }
17f16b
 
17f16b
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
17f16b
diff --git a/ucb/source/ucp/cmis/auth_provider.hxx b/ucb/source/ucp/cmis/auth_provider.hxx
17f16b
index 462f7edba54d..24430401d278 100644
17f16b
--- a/ucb/source/ucp/cmis/auth_provider.hxx
17f16b
+++ b/ucb/source/ucp/cmis/auth_provider.hxx
17f16b
@@ -39,11 +39,11 @@ namespace cmis
17f16b
 
17f16b
             bool authenticationQuery( std::string& username, std::string& password ) override;
17f16b
 
17f16b
-            std::string getRefreshToken( std::string& username );
17f16b
-            bool storeRefreshToken(const std::string& username, const std::string& password,
17f16b
-                                   const std::string& refreshToken);
17f16b
+            static char* onedriveAuthCodeFallback( const char* url,
17f16b
+                    const char* /*username*/,
17f16b
+                    const char* /*password*/ );
17f16b
 
17f16b
-            static char* copyWebAuthCodeFallback( const char* url,
17f16b
+            static char* gdriveAuthCodeFallback( const char* /*url*/,
17f16b
                     const char* /*username*/,
17f16b
                     const char* /*password*/ );
17f16b
 
17f16b
diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx
17f16b
index edb13ddf2457..355575d185d1 100644
17f16b
--- a/ucb/source/ucp/cmis/cmis_content.cxx
17f16b
+++ b/ucb/source/ucp/cmis/cmis_content.cxx
17f16b
@@ -347,15 +347,12 @@ namespace cmis
17f16b
             string rPassword = OUSTR_TO_STDSTR( m_aURL.getPassword( ) );
17f16b
 
17f16b
             bool bSkipInitialPWAuth = false;
17f16b
-            if (m_aURL.getBindingUrl() == ONEDRIVE_BASE_URL
17f16b
-                || m_aURL.getBindingUrl() == GDRIVE_BASE_URL)
17f16b
-            {
17f16b
+            if ( m_aURL.getBindingUrl( ) == ONEDRIVE_BASE_URL ) {
17f16b
                 // skip the initial username and pw-auth prompt, the only supported method is the
17f16b
                 // auth-code-fallback one (login with your browser, copy code into the dialog)
17f16b
                 // TODO: if LO were to listen on localhost for the request, it would be much nicer
17f16b
                 // user experience
17f16b
                 bSkipInitialPWAuth = true;
17f16b
-                rPassword = aAuthProvider.getRefreshToken(rUsername);
17f16b
             }
17f16b
 
17f16b
             bool bIsDone = false;
17f16b
@@ -368,9 +365,7 @@ namespace cmis
17f16b
                     libcmis::OAuth2DataPtr oauth2Data;
17f16b
                     if ( m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL )
17f16b
                     {
17f16b
-                        // reset the skip, so user gets a chance to cancel
17f16b
-                        bSkipInitialPWAuth = false;
17f16b
-                        libcmis::SessionFactory::setOAuth2AuthCodeProvider(AuthProvider::copyWebAuthCodeFallback);
17f16b
+                        libcmis::SessionFactory::setOAuth2AuthCodeProvider(AuthProvider::gdriveAuthCodeFallback);
17f16b
                         oauth2Data.reset( new libcmis::OAuth2Data(
17f16b
                             GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL,
17f16b
                             GDRIVE_SCOPE, GDRIVE_REDIRECT_URI,
17f16b
@@ -385,7 +380,7 @@ namespace cmis
17f16b
                     {
17f16b
                         // reset the skip, so user gets a chance to cancel
17f16b
                         bSkipInitialPWAuth = false;
17f16b
-                        libcmis::SessionFactory::setOAuth2AuthCodeProvider(AuthProvider::copyWebAuthCodeFallback);
17f16b
+                        libcmis::SessionFactory::setOAuth2AuthCodeProvider(AuthProvider::onedriveAuthCodeFallback);
17f16b
                         oauth2Data.reset( new libcmis::OAuth2Data(
17f16b
                             ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
17f16b
                             ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
17f16b
@@ -417,12 +412,6 @@ namespace cmis
17f16b
                         else
17f16b
                         {
17f16b
                             m_pProvider->registerSession(sSessionId, m_aURL.getUsername( ), m_pSession);
17f16b
-                            if (m_aURL.getBindingUrl() == ONEDRIVE_BASE_URL
17f16b
-                                || m_aURL.getBindingUrl() == GDRIVE_BASE_URL)
17f16b
-                            {
17f16b
-                                aAuthProvider.storeRefreshToken(rUsername, rPassword,
17f16b
-                                                                m_pSession->getRefreshToken());
17f16b
-                            }
17f16b
                         }
17f16b
 
17f16b
                         bIsDone = true;
17f16b
@@ -430,10 +419,7 @@ namespace cmis
17f16b
                     catch( const libcmis::Exception & e )
17f16b
                     {
17f16b
                         if ( e.getType() != "permissionDenied" )
17f16b
-                        {
17f16b
-                            SAL_INFO("ucb.ucp.cmis", "Unexpected libcmis exception: " << e.what());
17f16b
                             throw;
17f16b
-                        }
17f16b
                     }
17f16b
                 }
17f16b
                 else
17f16b
@@ -525,7 +511,6 @@ namespace cmis
17f16b
                 }
17f16b
                 catch ( const libcmis::Exception& )
17f16b
                 {
17f16b
-                    SAL_INFO( "ucb.ucp.cmis", "object: " << OUSTR_TO_STDSTR(m_sObjectId));
17f16b
                     throw libcmis::Exception( "Object not found" );
17f16b
                 }
17f16b
             }
17f16b
diff --git a/ucb/source/ucp/cmis/cmis_repo_content.cxx b/ucb/source/ucp/cmis/cmis_repo_content.cxx
17f16b
index 1bec3152b3b6..d98da53d5e2d 100644
17f16b
--- a/ucb/source/ucp/cmis/cmis_repo_content.cxx
17f16b
+++ b/ucb/source/ucp/cmis/cmis_repo_content.cxx
17f16b
@@ -165,7 +165,7 @@ namespace cmis
17f16b
                     libcmis::OAuth2DataPtr oauth2Data;
17f16b
                     if ( m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL )
17f16b
                     {
17f16b
-                        libcmis::SessionFactory::setOAuth2AuthCodeProvider( AuthProvider::copyWebAuthCodeFallback );
17f16b
+                        libcmis::SessionFactory::setOAuth2AuthCodeProvider( AuthProvider::gdriveAuthCodeFallback );
17f16b
                         oauth2Data.reset( new libcmis::OAuth2Data(
17f16b
                             GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL,
17f16b
                             GDRIVE_SCOPE, GDRIVE_REDIRECT_URI,
17f16b
@@ -178,7 +178,7 @@ namespace cmis
17f16b
                             ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET ) );
17f16b
                     if ( m_aURL.getBindingUrl( ) == ONEDRIVE_BASE_URL )
17f16b
                     {
17f16b
-                        libcmis::SessionFactory::setOAuth2AuthCodeProvider( AuthProvider::copyWebAuthCodeFallback );
17f16b
+                        libcmis::SessionFactory::setOAuth2AuthCodeProvider( AuthProvider::onedriveAuthCodeFallback );
17f16b
                         oauth2Data.reset( new libcmis::OAuth2Data(
17f16b
                             ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
17f16b
                             ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
17f16b
-- 
17f16b
2.31.1
17f16b