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