onedrive.html 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <script src="//js.live.net/v5.0/wl.js"></script>
  6. </head>
  7. <body>
  8. <script>
  9. // Extract authentication info from redirect URL in popup window
  10. function getAuthInfoFromUrl()
  11. {
  12. if (window.location.hash != null)
  13. {
  14. try
  15. {
  16. var result = new Object();
  17. var authResponse = window.location.hash.substring(1);
  18. var params = authResponse.split('&');
  19. for (var i = 0; i < params.length; i++)
  20. {
  21. idx = params[i].indexOf('=');
  22. if (idx > 0)
  23. {
  24. result[params[i].substring(0, idx)] = params[i].substring(idx + 1);
  25. }
  26. }
  27. return result;
  28. }
  29. catch (e)
  30. {
  31. // ignores parsing errors
  32. }
  33. }
  34. return null;
  35. };
  36. // Puts the current token into a cookie
  37. function setCookie(token, expiresInSeconds)
  38. {
  39. var expiration = new Date();
  40. if (token != null)
  41. {
  42. expiration.setTime(expiration.getTime() + expiresInSeconds * 1000);
  43. var cookie = 'odauth=' + token +'; path=/; expires=' + expiration.toUTCString();
  44. if (document.location.protocol.toLowerCase() == 'https')
  45. {
  46. cookie = cookie + ';secure';
  47. }
  48. document.cookie = cookie;
  49. }
  50. else
  51. {
  52. expiration.setYear(expiration.getFullYear() - 1);
  53. document.cookie = 'odauth=; expires=' + expiration.toUTCString();
  54. }
  55. };
  56. // Main flow after authentication popup redirects to callback URI
  57. var authInfo = getAuthInfoFromUrl();
  58. var token = null;
  59. if (authInfo != null)
  60. {
  61. token = authInfo['access_token'];
  62. var expiry = parseInt(authInfo['expires_in']);
  63. setCookie(token, expiry);
  64. }
  65. // Continues execution of main program flow
  66. try
  67. {
  68. if (window.opener != null)
  69. {
  70. window.opener.onAuthenticated(token, window);
  71. }
  72. }
  73. catch (e)
  74. {
  75. // ignores no opener
  76. }
  77. </script>
  78. </body>
  79. </html>