ucb/source/ucp/cmis/auth_provider.cxx | 48 ++++++++++++++++++++++++++++++ ucb/source/ucp/cmis/auth_provider.hxx | 11 ++++++ ucb/source/ucp/cmis/cmis_content.cxx | 4 ++ ucb/source/ucp/cmis/cmis_repo_content.cxx | 4 ++ 4 files changed, 67 insertions(+)
New commits: commit dad477120de1201e34a06f30c8bd800d79b831c2 Author: Mihai Varga <mihai.m...@gmail.com> Date: Thu Jul 31 12:07:56 2014 +0300 OnDrive authfallback request is now issued diff --git a/ucb/source/ucp/cmis/auth_provider.cxx b/ucb/source/ucp/cmis/auth_provider.cxx index bd00986..63e742f 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() ) @@ -62,6 +65,51 @@ 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(); + + if ( xSelection.is() ) + { + // Handler handled the request. + const rtl::Reference< ucbhelper::InteractionAuthFallback >& + xAuthFallback = xRequest->getAuthFallbackInter( ); + if ( xAuthFallback.is() ) + { + OUString code = xAuthFallback->getCode( ); + return strdup( OUSTR_TO_STDSTR( code ).c_str( ) ); + } + } + } + } + + 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_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx index 29d43c3..15c3ec9 100644 --- a/ucb/source/ucp/cmis/cmis_content.cxx +++ b/ucb/source/ucp/cmis/cmis_content.cxx @@ -334,6 +334,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( ) ); @@ -352,10 +353,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 ) ); + } m_pSession = libcmis::SessionFactory::createSession( OUSTR_TO_STDSTR( m_aURL.getBindingUrl( ) ), diff --git a/ucb/source/ucp/cmis/cmis_repo_content.cxx b/ucb/source/ucp/cmis/cmis_repo_content.cxx index c6f6ff3..02be8eb2 100644 --- a/ucb/source/ucp/cmis/cmis_repo_content.cxx +++ b/ucb/source/ucp/cmis/cmis_repo_content.cxx @@ -158,6 +158,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( ) ); @@ -178,10 +179,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 ) ); + } boost::scoped_ptr<libcmis::Session> session(libcmis::SessionFactory::createSession( OUSTR_TO_STDSTR( m_aURL.getBindingUrl( ) ), _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits