diff options
author | Szymon Kłos <eszkadev@gmail.com> | 2016-05-15 00:52:50 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2016-05-16 07:24:23 +0000 |
commit | 511db54e95d02292417d7cd076e4bd6d50956d64 (patch) | |
tree | ab8b4d46a35b1c9cc52679e966e0786bd18ca916 /ucb | |
parent | 5e54d9e9bc856520808a446f20575e29a50d017b (diff) |
tdf#87938 libcmis: Google 2FA implementation
2 Factor Authentication for Google Drive, changes:
+ parsing additional page with challenge - pin code verification
+ calling the interaction dialog requesting the code
+ dialog title changed to more general: Authentication Code
+ dialog shows url field only if not empty
Change-Id: Idb3ebbad6a12849b9e50af87b46324bfbe966bab
Reviewed-on: https://gerrit.libreoffice.org/25002
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: David Tardon <dtardon@redhat.com>
Diffstat (limited to 'ucb')
-rw-r--r-- | ucb/source/ucp/cmis/auth_provider.cxx | 42 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/auth_provider.hxx | 4 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_content.cxx | 3 | ||||
-rw-r--r-- | ucb/source/ucp/cmis/cmis_repo_content.cxx | 3 |
4 files changed, 52 insertions, 0 deletions
diff --git a/ucb/source/ucp/cmis/auth_provider.cxx b/ucb/source/ucp/cmis/auth_provider.cxx index 64cb84ecd6ca..0c3e4c0ec52f 100644 --- a/ucb/source/ucp/cmis/auth_provider.cxx +++ b/ucb/source/ucp/cmis/auth_provider.cxx @@ -110,6 +110,48 @@ namespace cmis return strdup( "" ); } + + char* AuthProvider::gdriveAuthCodeFallback( const char* /*url*/, + const char* /*username*/, + const char* /*password*/ ) + { + OUString instructions = "PIN:"; + OUString url_oustr( "" ); + const css::uno::Reference< + css::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 977254a8877c..e633e95bd012 100644 --- a/ucb/source/ucp/cmis/auth_provider.hxx +++ b/ucb/source/ucp/cmis/auth_provider.hxx @@ -34,6 +34,10 @@ namespace cmis const char* /*username*/, const char* /*password*/ ); + static char* gdriveAuthCodeFallback( const char* /*url*/, + const char* /*username*/, + const char* /*password*/ ); + static void setXEnv( const css::uno::Reference< css::ucb::XCommandEnvironment>& xEnv ) { sm_xEnv = xEnv; } static const css::uno::Reference< css::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 dea8ec7b01ef..b097a6f4e0ca 100644 --- a/ucb/source/ucp/cmis/cmis_content.cxx +++ b/ucb/source/ucp/cmis/cmis_content.cxx @@ -376,10 +376,13 @@ namespace cmis // Initiate a CMIS session and register it as we found nothing libcmis::OAuth2DataPtr oauth2Data; if ( m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL ) + { + libcmis::SessionFactory::setOAuth2AuthCodeProvider( authProvider.gdriveAuthCodeFallback ); oauth2Data.reset( new libcmis::OAuth2Data( GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL, GDRIVE_SCOPE, GDRIVE_REDIRECT_URI, GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET ) ); + } if ( m_aURL.getBindingUrl().startsWith( ALFRESCO_CLOUD_BASE_URL ) ) oauth2Data.reset( new libcmis::OAuth2Data( ALFRESCO_CLOUD_AUTH_URL, ALFRESCO_CLOUD_TOKEN_URL, diff --git a/ucb/source/ucp/cmis/cmis_repo_content.cxx b/ucb/source/ucp/cmis/cmis_repo_content.cxx index 75b3790510e5..cc1df948df44 100644 --- a/ucb/source/ucp/cmis/cmis_repo_content.cxx +++ b/ucb/source/ucp/cmis/cmis_repo_content.cxx @@ -175,10 +175,13 @@ namespace cmis // Create a session to get repositories libcmis::OAuth2DataPtr oauth2Data; if ( m_aURL.getBindingUrl( ) == GDRIVE_BASE_URL ) + { + libcmis::SessionFactory::setOAuth2AuthCodeProvider( authProvider.gdriveAuthCodeFallback ); oauth2Data.reset( new libcmis::OAuth2Data( GDRIVE_AUTH_URL, GDRIVE_TOKEN_URL, GDRIVE_SCOPE, GDRIVE_REDIRECT_URI, GDRIVE_CLIENT_ID, GDRIVE_CLIENT_SECRET ) ); + } if ( m_aURL.getBindingUrl().startsWith( ALFRESCO_CLOUD_BASE_URL ) ) oauth2Data.reset( new libcmis::OAuth2Data( ALFRESCO_CLOUD_AUTH_URL, ALFRESCO_CLOUD_TOKEN_URL, |