You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

2 years ago
  1. var APP_CLIENT_ID = "8509ba61-9451-4960-94d8-10934d5365cc";
  2. var REDIRECT_URL = "https://www.origtek.com:8016/Page/Calendar_Test.html";
  3. var authEndpoint = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?';
  4. var redirectUri = 'https://www.origtek.com:8016/Page/Calendar_Test.html';
  5. var appId = APP_CLIENT_ID;
  6. var scopes = 'openid profile User.Read Mail.Read';
  7. function buildAuthUrl() {
  8. // Generate random values for state and nonce
  9. sessionStorage.authState = guid();
  10. sessionStorage.authNonce = guid();
  11. var authParams = {
  12. response_type: 'id_token token',
  13. client_id: appId,
  14. redirect_uri: redirectUri,
  15. scope: scopes,
  16. state: sessionStorage.authState,
  17. nonce: sessionStorage.authNonce,
  18. response_mode: 'fragment'
  19. };
  20. return authEndpoint + $.param(authParams);
  21. }
  22. // Helper method to validate token and refresh
  23. // if needed
  24. function getAccessToken(callback) {
  25. var now = new Date().getTime();
  26. var isExpired = now > parseInt(sessionStorage.tokenExpires);
  27. // Do we have a token already?
  28. if (sessionStorage.accessToken && !isExpired) {
  29. // Just return what we have
  30. if (callback) {
  31. callback(sessionStorage.accessToken);
  32. }
  33. } else {
  34. // Attempt to do a hidden iframe request
  35. makeSilentTokenRequest(callback);
  36. }
  37. }