Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / external / libcmis / libcmis-fix-google-drive.patch
blob77961ce8086301d1abd8bff0f587fa8645e4d192
1 diff -aru old-src/src/libcmis/oauth2-providers.cxx new-src/src/libcmis/oauth2-providers.cxx
2 --- old-src/src/libcmis/oauth2-providers.cxx 2016-03-01 17:14:26.000000000 +0100
3 +++ new-src/src/libcmis/oauth2-providers.cxx 2016-04-28 11:28:25.233803971 +0200
4 @@ -37,11 +37,28 @@
5 string OAuth2Providers::OAuth2Gdrive( HttpSession* session, const string& authUrl,
6 const string& username, const string& password )
8 + /* This member function implements 'Google OAuth 2.0'
9 + *
10 + * The interaction is carried out by libcmis, with no web browser involved.
11 + *
12 + * Normal sequence (without 2FA) is:
13 + * 1) a get to activate login page
14 + * receive first login page, html format
15 + * 2) subsequent post to sent email
16 + * receive html page for password input
17 + * 3) subsequent post to send password
18 + * receive html page for application consent
19 + * 4) subsequent post to send a consent for the application
20 + * receive a single-use authorization code
21 + * this code is returned as a string
22 + */
24 static const string CONTENT_TYPE( "application/x-www-form-urlencoded" );
25 // STEP 1: Log in
26 string res;
27 try
29 + // send the first get, receive the html login page
30 res = session->httpGetRequest( authUrl )->getStream( )->str( );
32 catch ( const CurlException& e )
33 @@ -49,20 +66,39 @@
34 return string( );
37 - string loginPost, loginLink;
38 - if ( !parseResponse( res.c_str( ), loginPost, loginLink ) )
39 + string loginEmailPost, loginEmailLink;
40 + if ( !parseResponse( res.c_str( ), loginEmailPost, loginEmailLink ) )
41 + return string( );
43 + loginEmailPost += "Email=";
44 + loginEmailPost += string( username );
46 + istringstream loginEmailIs( loginEmailPost );
47 + string loginEmailRes;
48 + try
49 + {
50 + // send a post with user email, receive the html page for password input
51 + loginEmailRes = session->httpPostRequest ( loginEmailLink, loginEmailIs, CONTENT_TYPE )
52 + ->getStream( )->str( );
53 + }
54 + catch ( const CurlException& e )
55 + {
56 + return string( );
57 + }
59 + string loginPasswdPost, loginPasswdLink;
60 + if ( !parseResponse( loginEmailRes.c_str( ), loginPasswdPost, loginPasswdLink ) )
61 return string( );
63 - loginPost += "Email=";
64 - loginPost += string( username );
65 - loginPost += "&Passwd=";
66 - loginPost += string( password );
68 - istringstream loginIs( loginPost );
69 - string loginRes;
70 - try
72 + loginPasswdPost += "&Passwd=";
73 + loginPasswdPost += string( password );
75 + istringstream loginPasswdIs( loginPasswdPost );
76 + string loginPasswdRes;
77 + try
79 - loginRes = session->httpPostRequest ( loginLink, loginIs, CONTENT_TYPE )
80 + // send a post with user password, receive the application consent page
81 + loginPasswdRes = session->httpPostRequest ( loginPasswdLink, loginPasswdIs, CONTENT_TYPE )
82 ->getStream( )->str( );
84 catch ( const CurlException& e )
85 @@ -71,8 +107,8 @@
88 // STEP 2: allow libcmis to access google drive
89 - string approvalPost, approvalLink;
90 - if ( !parseResponse( loginRes. c_str( ), approvalPost, approvalLink) )
91 + string approvalPost, approvalLink;
92 + if ( !parseResponse( loginPasswdRes. c_str( ), approvalPost, approvalLink) )
93 return string( );
94 approvalPost += "submit_access=true";
96 @@ -80,7 +116,8 @@
97 string approvalRes;
98 try
100 - approvalRes = session->httpPostRequest ( approvalLink, approvalIs,
101 + // send a post with application consent
102 + approvalRes = session->httpPostRequest ( approvalLink, approvalIs,
103 CONTENT_TYPE) ->getStream( )->str( );
105 catch ( const CurlException& e )
106 Only in new-src/src/libcmis: oauth2-providers.cxx~