@@ -65,6 +65,10 @@ class oauth2_authorizer
6565 u.append_query (U (" client_id" ), m_client_key);
6666 u.append_query (U (" redirect_uri" ), m_redirect_uri);
6767 u.append_query (U (" state" ), state);
68+
69+ // Note: this is only needed for Live client
70+ u.append_query (U (" scope" ), " wl.signin" );
71+
6872 return u.to_string ();
6973 }
7074
@@ -195,6 +199,9 @@ static const utility::string_t s_linkedin_secret(U(""));
195199static const utility::string_t s_facebook_key (U(" " ));
196200static const utility::string_t s_facebook_secret (U(" " ));
197201
202+ static const utility::string_t s_live_key (U(" " ));
203+ static const utility::string_t s_live_secret (U(" " ));
204+
198205// TODO: Generate state per authorization request?
199206static const utility::string_t s_state (U(" 1234ABCD" ));
200207
@@ -248,6 +255,23 @@ static string_t linkedin_authorize()
248255 return authorizer.obtain_token (auth_code, false ).get ();
249256}
250257
258+ static string_t live_authorize ()
259+ {
260+ oauth2_authorizer authorizer (s_live_key, s_live_secret,
261+ U (" https://login.live.com/oauth20_authorize.srf" ),
262+ U (" https://login.live.com/oauth20_token.srf" ),
263+ U (" http://mydomain987564728.com:80/" )); // must be a real domain name
264+
265+ utility::string_t auth_code;
266+ {
267+ oauth2_code_listener listener (authorizer.redirect_uri (), s_state);
268+ open_browser (authorizer.get_authorization_uri (s_state));
269+ auth_code = listener.listen_for_code ().get ();
270+ }
271+
272+ return authorizer.obtain_token (auth_code).get ();
273+ }
274+
251275static void dropbox_client ()
252276{
253277 oauth2_config dropbox_cfg (dropbox_authorize ());
@@ -267,26 +291,26 @@ static void dropbox_client()
267291 ucout << " Metadata: " << api.request (methods::GET, U (" metadata/sandbox/hello_world.txt" )).get ().extract_json ().get () << std::endl;
268292
269293 ucout << " Downloading 'hello_world.txt' file contents (text):" << std::endl;
270- string_t content_string = content.request (methods::GET, " files/sandbox/hello_world.txt" ).get ().extract_string ().get ();
294+ string_t content_string = content.request (methods::GET, U ( " files/sandbox/hello_world.txt" ) ).get ().extract_string ().get ();
271295 ucout << " Contents: '" << content_string << " '" << std::endl;
272296 ucout << " Downloading 'test_image.jpg' file contents (binary):" << std::endl;
273- std::vector<unsigned char > content_vector = content.request (methods::GET, " files/sandbox/test_image.jpg" ).get ().extract_vector ().get ();
297+ std::vector<unsigned char > content_vector = content.request (methods::GET, U ( " files/sandbox/test_image.jpg" ) ).get ().extract_vector ().get ();
274298 ucout << " Contents size: " << (content_vector.size () / 1024 ) << " KiB" << std::endl;
275299
276300 ucout << " Uploading 'test_put.txt' file with contents 'Testing POST' (text):" << std::endl;
277301 ucout << " Response: "
278- << content.request (methods::POST, " files_put/sandbox/test_put.txt" , " Testing POST" ).get ().extract_string ().get ()
302+ << content.request (methods::POST, U ( " files_put/sandbox/test_put.txt" ), U ( " Testing POST" ) ).get ().extract_string ().get ()
279303 << std::endl;
280304 ucout << " Uploading 'test_image_copy.jpg' (copy of 'test_image.jpg'):" << std::endl;
281305 ucout << " Response: "
282- << content.request (methods::PUT, " files_put/sandbox/test_image_copy.jpg" ,
306+ << content.request (methods::PUT, U ( " files_put/sandbox/test_image_copy.jpg" ) ,
283307 concurrency::streams::bytestream::open_istream (std::move (content_vector))).get ().extract_string ().get ()
284308 << std::endl;
285309
286310 ucout << " Deleting uploaded file 'test_put.txt':" << std::endl;
287- ucout << " Response: " << api.request (methods::POST, " fileops/delete?root=sandbox&path=test_put.txt" ).get ().extract_string ().get () << std::endl;
311+ ucout << " Response: " << api.request (methods::POST, U ( " fileops/delete?root=sandbox&path=test_put.txt" ) ).get ().extract_string ().get () << std::endl;
288312 ucout << " Deleting uploaded file 'test_image_copy.jpg':" << std::endl;
289- ucout << " Response: " << api.request (methods::POST, " fileops/delete?root=sandbox&path=test_image_copy.jpg" ).get ().extract_string ().get () << std::endl;
313+ ucout << " Response: " << api.request (methods::POST, U ( " fileops/delete?root=sandbox&path=test_image_copy.jpg" ) ).get ().extract_string ().get () << std::endl;
290314#endif
291315}
292316
@@ -308,6 +332,17 @@ static void linkedin_client()
308332#endif
309333}
310334
335+ static void live_client ()
336+ {
337+ oauth2_config live_cfg (live_authorize ());
338+
339+ http_client_config config;
340+ config.set_oauth2 (live_cfg);
341+
342+ http_client api (U (" https://apis.live.net/v5.0" ), config);
343+ auto x = api.request (methods::GET, U (" me?access_token=wl.signin" )).get ();
344+ }
345+
311346#ifdef _MS_WINDOWS
312347int wmain (int argc, wchar_t *argv[])
313348#else
@@ -316,8 +351,9 @@ int main(int argc, char *argv[])
316351{
317352 ucout << " Running oauth2 sample..." << std::endl;
318353
319- linkedin_client ();
320- dropbox_client ();
354+ // linkedin_client();
355+ // dropbox_client();
356+ live_client ();
321357
322358 ucout << " Done." << std::endl;
323359 return 0 ;
0 commit comments