1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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
;
25 com::sun::star::uno::Reference
< com::sun::star::ucb::XCommandEnvironment
>
26 AuthProvider::sm_xEnv
;
27 bool AuthProvider::authenticationQuery( string
& username
, string
& password
)
31 uno::Reference
< task::XInteractionHandler
> xIH
32 = m_xEnv
->getInteractionHandler();
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
);
55 ucbhelper::InteractionSupplyAuthentication
> & xSupp
56 = xRequest
->getAuthenticationSupplier();
58 username
= OUSTR_TO_STDSTR( xSupp
->getUserName() );
59 password
= OUSTR_TO_STDSTR( xSupp
->getPassword() );
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( );
83 uno::Reference
< task::XInteractionHandler
> xIH
84 = xEnv
->getInteractionHandler();
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( ) );
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */