[Libreoffice-commits] core.git: Branch 'feature/gsoc14-libcmis' - ucb/source

Mihai Varga mihai.mv13 at gmail.com
Mon Jun 30 00:13:00 PDT 2014


 ucb/source/ucp/cmis/auth_provider.cxx     |   35 ++++++++++++++++++++++++++++++
 ucb/source/ucp/cmis/auth_provider.hxx     |   11 +++++++++
 ucb/source/ucp/cmis/cmis_repo_content.cxx |    4 +++
 3 files changed, 50 insertions(+)

New commits:
commit b6909c3319b4200318cb178df21aeddb551b4159
Author: Mihai Varga <mihai.mv13 at gmail.com>
Date:   Mon Jun 30 10:12:13 2014 +0300

    AuthFallback request is sent correctly

diff --git a/ucb/source/ucp/cmis/auth_provider.cxx b/ucb/source/ucp/cmis/auth_provider.cxx
index bd00986..9a5d2e9 100644
--- a/ucb/source/ucp/cmis/auth_provider.cxx
+++ b/ucb/source/ucp/cmis/auth_provider.cxx
@@ -13,6 +13,7 @@
 #include <com/sun/star/task/XInteractionHandler.hpp>
 
 #include <ucbhelper/simpleauthenticationrequest.hxx>
+#include <ucbhelper/authenticationfallback.hxx>
 
 #include "auth_provider.hxx"
 
@@ -21,6 +22,8 @@ using namespace std;
 
 namespace cmis
 {
+    com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment> 
+        AuthProvider::sm_xEnv;
     bool AuthProvider::authenticationQuery( string& username, string& password )
     {
         if ( m_xEnv.is() )
@@ -36,6 +39,7 @@ namespace cmis
                         STD_TO_OUSTR( username ),
                         STD_TO_OUSTR( password ),
                         OUString(), true, false );
+
                 xIH->handle( xRequest.get() );
 
                 rtl::Reference< ucbhelper::InteractionContinuation > xSelection
@@ -62,6 +66,37 @@ namespace cmis
         }
         return false;
     }
+
+    char* AuthProvider::onedriveAuthCodeFallback( const char* url,
+            const char* /*username*/,
+            const char* /*password*/ )
+    {
+        OUString instructions = "Please open the following link in your browser and\n"
+            "paste the code from the URL you have been redirected to\n"
+            "in the box bellow. For example:\n"
+            "https://login.live.com/oauth20_desktop.srf?code=YOUR_CODE&lc=1033";
+        OUString url_oustr( url, strlen( url ), RTL_TEXTENCODING_UTF8 );
+        const com::sun::star::uno::Reference< 
+            com::sun::star::ucb::XCommandEnvironment> xEnv = getXEnv( );
+
+        if ( xEnv.is() )
+        {
+            uno::Reference< task::XInteractionHandler > xIH
+                = xEnv->getInteractionHandler();
+
+            if ( xIH.is() )
+            {
+                rtl::Reference< ucbhelper::AuthenticationFallbackRequest > xRequest
+                    = new ucbhelper::AuthenticationFallbackRequest (
+                            instructions, url_oustr );
+                xIH->handle( xRequest.get() );
+                rtl::Reference< ucbhelper::InteractionContinuation > xSelection
+                    = xRequest->getSelection();
+            }
+        }
+
+        return strdup( "" );
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/ucp/cmis/auth_provider.hxx b/ucb/source/ucp/cmis/auth_provider.hxx
index f36d9a7..9fbf599 100644
--- a/ucb/source/ucp/cmis/auth_provider.hxx
+++ b/ucb/source/ucp/cmis/auth_provider.hxx
@@ -18,6 +18,7 @@ namespace cmis
     class AuthProvider : public libcmis::AuthProvider
     {
         const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment>& m_xEnv;
+        static com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment> sm_xEnv;
         OUString m_sUrl;
         OUString m_sBindingUrl;
 
@@ -29,6 +30,16 @@ namespace cmis
                 m_xEnv( xEnv ), m_sUrl( sUrl ), m_sBindingUrl( sBindingUrl ) { }
 
             bool authenticationQuery( std::string& username, std::string& password ) SAL_OVERRIDE;
+
+            static char* onedriveAuthCodeFallback( const char* url,
+                    const char* /*username*/,
+                    const char* /*password*/ );
+
+            static void setXEnv( const com::sun::star::uno::Reference<
+                    com::sun::star::ucb::XCommandEnvironment>& xEnv ) { sm_xEnv = xEnv; }
+
+            static com::sun::star::uno::Reference< 
+                com::sun::star::ucb::XCommandEnvironment> getXEnv( ) { return sm_xEnv; }
     };
 }
 
diff --git a/ucb/source/ucp/cmis/cmis_repo_content.cxx b/ucb/source/ucp/cmis/cmis_repo_content.cxx
index 2516387..e364b43 100644
--- a/ucb/source/ucp/cmis/cmis_repo_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_repo_content.cxx
@@ -139,6 +139,7 @@ namespace cmis
 
             // Get the auth credentials
             AuthProvider authProvider( xEnv, m_xIdentifier->getContentIdentifier( ), m_aURL.getBindingUrl( ) );
+            AuthProvider::setXEnv( xEnv );
 
             string rUsername = OUSTR_TO_STDSTR( m_aURL.getUsername( ) );
             string rPassword = OUSTR_TO_STDSTR( m_aURL.getPassword( ) );
@@ -159,10 +160,13 @@ namespace cmis
                             ALFRESCO_CLOUD_SCOPE, ALFRESCO_CLOUD_REDIRECT_URI,
                             ALFRESCO_CLOUD_CLIENT_ID, ALFRESCO_CLOUD_CLIENT_SECRET ) );
                     if ( m_aURL.getBindingUrl( ) == ONEDRIVE_BASE_URL )
+                    {
+                        libcmis::SessionFactory::setOAuth2AuthCodeProvider( authProvider.onedriveAuthCodeFallback );
                         oauth2Data.reset( new libcmis::OAuth2Data(
                             ONEDRIVE_AUTH_URL, ONEDRIVE_TOKEN_URL,
                             ONEDRIVE_SCOPE, ONEDRIVE_REDIRECT_URI,
                             ONEDRIVE_CLIENT_ID, ONEDRIVE_CLIENT_SECRET ) );
+                    }
 
                     libcmis::Session* session = libcmis::SessionFactory::createSession(
                             OUSTR_TO_STDSTR( m_aURL.getBindingUrl( ) ),


More information about the Libreoffice-commits mailing list