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
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'
10 + * The interaction is carried out by libcmis, with no web browser involved.
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
24 static const string CONTENT_TYPE( "application/x-www-form-urlencoded" );
29 + // send the first get, receive the html login page
30 res = session->httpGetRequest( authUrl )->getStream( )->str( );
32 catch ( const CurlException& e )
37 - string loginPost, loginLink;
38 - if ( !parseResponse( res.c_str( ), loginPost, loginLink ) )
39 + string loginEmailPost, loginEmailLink;
40 + if ( !parseResponse( res.c_str( ), loginEmailPost, loginEmailLink ) )
43 + loginEmailPost += "Email=";
44 + loginEmailPost += string( username );
46 + istringstream loginEmailIs( loginEmailPost );
47 + string loginEmailRes;
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( );
54 + catch ( const CurlException& e )
59 + string loginPasswdPost, loginPasswdLink;
60 + if ( !parseResponse( loginEmailRes.c_str( ), loginPasswdPost, loginPasswdLink ) )
63 - loginPost += "Email=";
64 - loginPost += string( username );
65 - loginPost += "&Passwd=";
66 - loginPost += string( password );
68 - istringstream loginIs( loginPost );
72 + loginPasswdPost += "&Passwd=";
73 + loginPasswdPost += string( password );
75 + istringstream loginPasswdIs( loginPasswdPost );
76 + string loginPasswdRes;
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 )
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) )
94 approvalPost += "submit_access=true";
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~