fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / cmis / auth_provider.cxx
blob500b601b7179225ffe5612152619a7761109033b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #define OUSTR_TO_STDSTR(s) string( OUStringToOString( s, RTL_TEXTENCODING_UTF8 ).getStr() )
11 #define STD_TO_OUSTR( str ) OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
13 #include <com/sun/star/task/XInteractionHandler.hpp>
15 #include <ucbhelper/simpleauthenticationrequest.hxx>
16 #include <ucbhelper/authenticationfallback.hxx>
18 #include "auth_provider.hxx"
20 using namespace com::sun::star;
21 using namespace std;
23 namespace cmis
25 com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment>
26 AuthProvider::sm_xEnv;
27 bool AuthProvider::authenticationQuery( string& username, string& password )
29 if ( m_xEnv.is() )
31 uno::Reference< task::XInteractionHandler > xIH
32 = m_xEnv->getInteractionHandler();
34 if ( xIH.is() )
36 rtl::Reference< ucbhelper::SimpleAuthenticationRequest > xRequest
37 = new ucbhelper::SimpleAuthenticationRequest(
38 m_sUrl, m_sBindingUrl, OUString(),
39 STD_TO_OUSTR( username ),
40 STD_TO_OUSTR( password ),
41 OUString(), true, false, false );
42 xIH->handle( xRequest.get() );
44 rtl::Reference< ucbhelper::InteractionContinuation > xSelection
45 = xRequest->getSelection();
47 if ( xSelection.is() )
49 // Handler handled the request.
50 uno::Reference< task::XInteractionAbort > xAbort(
51 xSelection.get(), uno::UNO_QUERY );
52 if ( !xAbort.is() )
54 const rtl::Reference<
55 ucbhelper::InteractionSupplyAuthentication > & xSupp
56 = xRequest->getAuthenticationSupplier();
58 username = OUSTR_TO_STDSTR( xSupp->getUserName() );
59 password = OUSTR_TO_STDSTR( xSupp->getPassword() );
61 return true;
66 return false;
69 char* AuthProvider::onedriveAuthCodeFallback( const char* url,
70 const char* /*username*/,
71 const char* /*password*/ )
73 OUString instructions = "Open the following link in your browser and "
74 "paste the code from the URL you have been redirected to in the "
75 "box below. For example:\n"
76 "https://login.live.com/oauth20_desktop.srf?code=YOUR_CODE&lc=1033";
77 OUString url_oustr( url, strlen( url ), RTL_TEXTENCODING_UTF8 );
78 const com::sun::star::uno::Reference<
79 com::sun::star::ucb::XCommandEnvironment> xEnv = getXEnv( );
81 if ( xEnv.is() )
83 uno::Reference< task::XInteractionHandler > xIH
84 = xEnv->getInteractionHandler();
86 if ( xIH.is() )
88 rtl::Reference< ucbhelper::AuthenticationFallbackRequest > xRequest
89 = new ucbhelper::AuthenticationFallbackRequest (
90 instructions, url_oustr );
92 xIH->handle( xRequest.get() );
94 rtl::Reference< ucbhelper::InteractionContinuation > xSelection
95 = xRequest->getSelection();
97 if ( xSelection.is() )
99 // Handler handled the request.
100 const rtl::Reference< ucbhelper::InteractionAuthFallback >&
101 xAuthFallback = xRequest->getAuthFallbackInter( );
102 if ( xAuthFallback.is() )
104 OUString code = xAuthFallback->getCode( );
105 return strdup( OUSTR_TO_STDSTR( code ).c_str( ) );
111 return strdup( "" );
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */