summaryrefslogtreecommitdiff
path: root/ucb
diff options
context:
space:
mode:
authorMihai Varga <mihai.mv13@gmail.com>2014-07-31 12:07:56 +0300
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-12-16 09:29:10 +0100
commit07e8b67b426d3e0addee9b1d434b7ee8f65469a3 (patch)
treefa693508b40565880fcac1d5329b28608ff087b5 /ucb
parent2a20b1782098766f9dd8ce422823fad18273afad (diff)
OneDrive authfallback request is now issued
Change-Id: I9ee1f087322d80cbdf8ca369fccb6b6b0336062e (cherry picked from commit 30298bc388f3e7c5b180904a8ad4f671e7b8b52b)
Diffstat (limited to 'ucb')
-rw-r--r--ucb/source/ucp/cmis/auth_provider.cxx48
-rw-r--r--ucb/source/ucp/cmis/auth_provider.hxx11
-rw-r--r--ucb/source/ucp/cmis/cmis_content.cxx4
-rw-r--r--ucb/source/ucp/cmis/cmis_repo_content.cxx4
4 files changed, 67 insertions, 0 deletions
diff --git a/ucb/source/ucp/cmis/auth_provider.cxx b/ucb/source/ucp/cmis/auth_provider.cxx
index bd00986a18b0..63e742f84282 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 f36d9a7b67ea..9fbf59983630 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 ad9fda424052..80c7ca13168b 100644
--- a/ucb/source/ucp/cmis/cmis_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_content.cxx
@@ -336,6 +336,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( ) );
@@ -354,10 +355,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 bb31b84c79ee..f140a15725ff 100644
--- a/ucb/source/ucp/cmis/cmis_repo_content.cxx
+++ b/ucb/source/ucp/cmis/cmis_repo_content.cxx
@@ -159,6 +159,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( ) );
@@ -179,10 +180,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( ) ),