summaryrefslogtreecommitdiffstats
path: root/external/libcmis/libcmis_oauth_pw_as_refreshtoken.patch.1
blob: a8cb06509421214cc83c188eb4146b63a4f91dd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
diff -ur libcmis.org/inc/libcmis/session.hxx libcmis/inc/libcmis/session.hxx
--- libcmis.org/inc/libcmis/session.hxx	2021-07-27 19:09:42.580249917 +0200
+++ libcmis/inc/libcmis/session.hxx	2021-07-27 19:10:02.368249199 +0200
@@ -95,6 +95,8 @@
                 certificate exception feature available on common web browser.
               */
             virtual void setNoSSLCertificateCheck( bool noCheck ) = 0;
+
+            virtual std::string getRefreshToken() { return ""; };
     };
 }
 
diff -ur libcmis.org/src/libcmis/gdrive-session.cxx libcmis/src/libcmis/gdrive-session.cxx
--- libcmis.org/src/libcmis/gdrive-session.cxx	2021-07-27 19:09:42.581249917 +0200
+++ libcmis/src/libcmis/gdrive-session.cxx	2021-07-27 19:10:02.369249198 +0200
@@ -70,6 +70,46 @@
 {
 }
 
+
+void GDriveSession::setOAuth2Data( libcmis::OAuth2DataPtr oauth2 )
+{
+    m_oauth2Handler = new OAuth2Handler( this, oauth2 );
+    m_oauth2Handler->setOAuth2Parser( OAuth2Providers::getOAuth2Parser( getBindingUrl( ) ) );
+
+    oauth2Authenticate( );
+}
+
+void GDriveSession::oauth2Authenticate()
+{
+    // treat the supplied password as refresh token
+    if (!m_password.empty())
+    {
+        try
+        {
+            m_inOAuth2Authentication = true;
+
+            m_oauth2Handler->setRefreshToken(m_password);
+            // Try to get new access tokens using the stored refreshtoken
+            m_oauth2Handler->refresh();
+            m_inOAuth2Authentication = false;
+        }
+        catch (const CurlException &e)
+        {
+            m_inOAuth2Authentication = false;
+            // refresh token expired or invalid, trigger initial auth (that in turn will hit the fallback with copy'n'paste method)
+            BaseSession::oauth2Authenticate();
+        }
+    }
+    else
+    {
+        BaseSession::oauth2Authenticate();
+    }
+}
+
+string GDriveSession::getRefreshToken() {
+    return HttpSession::getRefreshToken();
+}
+
 libcmis::RepositoryPtr GDriveSession::getRepository( )
 {
     // Return a dummy repository since GDrive doesn't have that notion
diff -ur libcmis.org/src/libcmis/gdrive-session.hxx libcmis/src/libcmis/gdrive-session.hxx
--- libcmis.org/src/libcmis/gdrive-session.hxx	2021-07-27 19:09:42.583249917 +0200
+++ libcmis/src/libcmis/gdrive-session.hxx	2021-07-27 19:10:02.369249198 +0200
@@ -57,8 +57,14 @@
 
         virtual std::vector< libcmis::ObjectTypePtr > getBaseTypes( );
 
+        virtual std::string getRefreshToken();
+
     private:
         GDriveSession( );
+
+        virtual void setOAuth2Data( libcmis::OAuth2DataPtr oauth2 );
+
+        void oauth2Authenticate( );
 };
 
 #endif /* _GDRIVE_SESSION_HXX_ */
diff -ur libcmis.org/src/libcmis/http-session.hxx libcmis/src/libcmis/http-session.hxx
--- libcmis.org/src/libcmis/http-session.hxx	2021-07-27 19:09:42.582249917 +0200
+++ libcmis/src/libcmis/http-session.hxx	2021-07-27 19:10:02.369249198 +0200
@@ -148,7 +148,7 @@
 
         void setNoSSLCertificateCheck( bool noCheck );
 
-        std::string getRefreshToken( );
+        virtual std::string getRefreshToken( );
 
     protected:
         HttpSession( );
diff -ur libcmis.org/src/libcmis/oauth2-handler.cxx libcmis/src/libcmis/oauth2-handler.cxx
--- libcmis.org/src/libcmis/oauth2-handler.cxx	2021-07-27 19:09:42.582249917 +0200
+++ libcmis/src/libcmis/oauth2-handler.cxx	2021-07-27 19:10:02.369249198 +0200
@@ -158,6 +158,11 @@
     return m_refresh;
 }
 
+void OAuth2Handler::setRefreshToken( string refreshToken )
+{
+    m_refresh = refreshToken;
+}
+
 string OAuth2Handler::getHttpHeader( )
 {
     string header;
diff -ur libcmis.org/src/libcmis/oauth2-handler.hxx libcmis/src/libcmis/oauth2-handler.hxx
--- libcmis.org/src/libcmis/oauth2-handler.hxx	2021-07-27 19:09:42.582249917 +0200
+++ libcmis/src/libcmis/oauth2-handler.hxx	2021-07-27 19:10:02.370249198 +0200
@@ -61,6 +61,7 @@
 
         std::string getAccessToken( ) ;
         std::string getRefreshToken( ) ;
+        void setRefreshToken( std::string refreshToken ) ;
 
         // adding HTTP auth header
         std::string getHttpHeader( ) ;
diff -ur libcmis.org/src/libcmis/onedrive-session.cxx libcmis/src/libcmis/onedrive-session.cxx
--- libcmis.org/src/libcmis/onedrive-session.cxx	2021-07-27 19:09:42.583249917 +0200
+++ libcmis/src/libcmis/onedrive-session.cxx	2021-07-27 19:10:02.370249198 +0200
@@ -68,6 +68,45 @@
 {
 }
 
+void OneDriveSession::setOAuth2Data( libcmis::OAuth2DataPtr oauth2 )
+{
+    m_oauth2Handler = new OAuth2Handler( this, oauth2 );
+    m_oauth2Handler->setOAuth2Parser( OAuth2Providers::getOAuth2Parser( getBindingUrl( ) ) );
+
+    oauth2Authenticate( );
+}
+
+void OneDriveSession::oauth2Authenticate()
+{
+    // treat the supplied password as refresh token
+    if (!m_password.empty())
+    {
+        try
+        {
+            m_inOAuth2Authentication = true;
+
+            m_oauth2Handler->setRefreshToken(m_password);
+            // Try to get new access tokens using the stored refreshtoken
+            m_oauth2Handler->refresh();
+            m_inOAuth2Authentication = false;
+        }
+        catch (const CurlException &e)
+        {
+            m_inOAuth2Authentication = false;
+            // refresh token expired or invalid, trigger initial auth (that in turn will hit the fallback with copy'n'paste method)
+            BaseSession::oauth2Authenticate();
+        }
+    }
+    else
+    {
+        BaseSession::oauth2Authenticate();
+    }
+}
+
+string OneDriveSession::getRefreshToken() {
+    return HttpSession::getRefreshToken();
+}
+
 libcmis::RepositoryPtr OneDriveSession::getRepository( )
 {
     // Return a dummy repository since OneDrive doesn't have that notion
diff -ur libcmis.org/src/libcmis/onedrive-session.hxx libcmis/src/libcmis/onedrive-session.hxx
--- libcmis.org/src/libcmis/onedrive-session.hxx	2021-07-27 19:09:42.583249917 +0200
+++ libcmis/src/libcmis/onedrive-session.hxx	2021-07-27 19:10:02.370249198 +0200
@@ -62,8 +62,14 @@
 
        bool isAPathMatch( Json objectJson, std::string path );
 
+       virtual std::string getRefreshToken();
+
     private:
         OneDriveSession( );
+
+        virtual void setOAuth2Data( libcmis::OAuth2DataPtr oauth2 );
+
+        void oauth2Authenticate( );
 };
 
 #endif /* _ONEDRIVE_SESSION_HXX_ */