Kaydet (Commit) 30298bc3 authored tarafından Mihai Varga's avatar Mihai Varga Kaydeden (comit) Miklos Vajna

OneDrive authfallback request is now issued

Change-Id: I9ee1f087322d80cbdf8ca369fccb6b6b0336062e
üst a3b93ed6
......@@ -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: */
......@@ -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; }
};
}
......
......@@ -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( ) ),
......
......@@ -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( ) ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment