From 749a0672ac057dba92f36f1ba7db1ead2cfcffcb Mon Sep 17 00:00:00 2001 From: Daryl Thayil Date: Sat, 13 Apr 2019 15:39:51 -0700 Subject: [PATCH 1/7] add qs for new code patterns --- .gitignore | 2 + JavaScriptSPA/index.html | 119 ++++++++++++++++++++------------ JavaScriptSPA/msal-0.9.0.min.js | 17 +++++ JavaScriptSPA/style.css | 43 ++++++++++++ 4 files changed, 138 insertions(+), 43 deletions(-) create mode 100644 .gitignore create mode 100644 JavaScriptSPA/msal-0.9.0.min.js create mode 100644 JavaScriptSPA/style.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e6e33c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +package-lock.json \ No newline at end of file diff --git a/JavaScriptSPA/index.html b/JavaScriptSPA/index.html index ea7b1ad..d693267 100644 --- a/JavaScriptSPA/index.html +++ b/JavaScriptSPA/index.html @@ -3,15 +3,20 @@ Quickstart for MSAL JS - + + -

- -

-

-
+    
+
+

Welcome to the Microsoft Authentication Library For Javascript Quickstart

+ +
+
+

+        
+
- - + @@ -18,18 +17,24 @@ diff --git a/JavaScriptSPA/msal-0.9.0.min.js b/JavaScriptSPA/msal-0.9.0.min.js deleted file mode 100644 index 6fe28e7..0000000 --- a/JavaScriptSPA/msal-0.9.0.min.js +++ /dev/null @@ -1,17 +0,0 @@ -/*! msal v0.9.0 2019-04-15 */ -"use strict";!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("Msal",[],t):"object"==typeof exports?exports.Msal=t():e.Msal=t()}(window,function(){return function(r){var n={};function o(e){if(n[e])return n[e].exports;var t=n[e]={i:e,l:!1,exports:{}};return r[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}return o.m=r,o.c=n,o.d=function(e,t,r){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)o.d(r,n,function(e){return t[e]}.bind(null,n));return r},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=15)}([function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var n=r(1),c=r(2),o=function(){function a(){}return a.compareAccounts=function(e,t){return!(!e||!t)&&!(!e.homeAccountIdentifier||!t.homeAccountIdentifier||e.homeAccountIdentifier!==t.homeAccountIdentifier)},a.decimalToHex=function(e){for(var t=e.toString(16);t.length<2;)t="0"+t;return t},a.getLibraryVersion=function(){return"0.2.4"},a.createNewGuid=function(){var e=window.crypto;if(e&&e.getRandomValues){var t=new Uint8Array(16);return e.getRandomValues(t),t[6]|=64,t[6]&=79,t[8]|=128,t[8]&=191,a.decimalToHex(t[0])+a.decimalToHex(t[1])+a.decimalToHex(t[2])+a.decimalToHex(t[3])+"-"+a.decimalToHex(t[4])+a.decimalToHex(t[5])+"-"+a.decimalToHex(t[6])+a.decimalToHex(t[7])+"-"+a.decimalToHex(t[8])+a.decimalToHex(t[9])+"-"+a.decimalToHex(t[10])+a.decimalToHex(t[11])+a.decimalToHex(t[12])+a.decimalToHex(t[13])+a.decimalToHex(t[14])+a.decimalToHex(t[15])}for(var r="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx",n="0123456789abcdef",o=0,i="",s=0;s<36;s++)"-"!==r[s]&&"4"!==r[s]&&(o=16*Math.random()|0),"x"===r[s]?i+=n[o]:"y"===r[s]?(o&=3,i+=n[o|=8]):i+=r[s];return i},a.expiresIn=function(e){return e||(e="3599"),this.now()+parseInt(e,10)},a.now=function(){return Math.round((new Date).getTime()/1e3)},a.isEmpty=function(e){return void 0===e||!e||0===e.length},a.decodeJwt=function(e){if(this.isEmpty(e))return null;var t=/^([^\.\s]*)\.([^\.\s]+)\.([^\.\s]*)$/.exec(e);return!t||t.length<4?null:{header:t[1],JWSPayload:t[2],JWSSig:t[3]}},a.extractIdToken=function(e){var t=this.decodeJwt(e);if(!t)return null;try{var r=t.JWSPayload,n=this.base64DecodeStringUrlSafe(r);return n?JSON.parse(n):null}catch(e){}return null},a.base64EncodeStringUrlSafe=function(e){return window.btoa?window.btoa(e):this.encode(e)},a.base64DecodeStringUrlSafe=function(e){return e=e.replace(/-/g,"+").replace(/_/g,"/"),window.atob?decodeURIComponent(encodeURIComponent(window.atob(e))):decodeURIComponent(encodeURIComponent(this.decode(e)))},a.encode=function(e){var t,r,n,o,i,s,a,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",u="",l=0;for(e=this.utf8Encode(e);l>2,i=(3&t)<<4|(r=e.charCodeAt(l++))>>4,s=(15&r)<<2|(n=e.charCodeAt(l++))>>6,a=63&n,isNaN(r)?s=a=64:isNaN(n)&&(a=64),u=u+c.charAt(o)+c.charAt(i)+c.charAt(s)+c.charAt(a);return u.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")},a.utf8Encode=function(e){e=e.replace(/\r\n/g,"\n");for(var t="",r=0;r>6|192):(t+=String.fromCharCode(n>>12|224),t+=String.fromCharCode(n>>6&63|128)),t+=String.fromCharCode(63&n|128))}return t},a.decode=function(e){var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",r=(e=String(e).replace(/=+$/,"")).length;if(r%4==1)throw new Error("The token to be decoded is not correctly encoded.");for(var n,o,i,s,a,c,u,l,d="",h=0;h>16&255,u=a>>8&255,d+=String.fromCharCode(c,u);break}if(h+1===r-1){c=(a=n<<18|o<<12)>>16&255,d+=String.fromCharCode(c);break}c=(a=n<<18|o<<12|i<<6|s)>>16&255,u=a>>8&255,l=255&a,d+=String.fromCharCode(c,u,l)}return d},a.deserialize=function(e){var t,r=/\+/g,n=/([^&=]+)=([^&]*)/g,o=function(e){return decodeURIComponent(e.replace(r," "))},i={};for(t=n.exec(e);t;)i[o(t[1])]=o(t[2]),t=n.exec(e);return i},a.isIntersectingScopes=function(e,t){e=this.convertToLowerCase(e);for(var r=0;r=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}function i(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),s=[];try{for(;(void 0===t||0s[0]&&t[1]."},authorityUriInsecure:{code:"authority_uri_insecure",desc:"Authority URIs must use https."},authorityUriInvalidPath:{code:"authority_uri_invalid_path",desc:"Given authority URI is invalid."},unsupportedAuthorityValidation:{code:"unsupported_authority_validation",desc:"The authority validation is not supported for this authority type."},b2cAuthorityUriInvalidPath:{code:"b2c_authority_uri_invalid_path",desc:"The given URI for the B2C authority is invalid."}};var o=function(n){function o(e,t){var r=n.call(this,e,t)||this;return r.name="ClientConfigurationError",Object.setPrototypeOf(r,o.prototype),r}return i.__extends(o,n),o.createInvalidCacheLocationConfigError=function(e){return new o(r.ClientConfigurationErrorMessage.invalidCacheLocation.code,r.ClientConfigurationErrorMessage.invalidCacheLocation.desc+" Provided value: "+e+". Possible values are: "+s.Constants.cacheLocationLocal+", "+s.Constants.cacheLocationSession+".")},o.createRedirectCallbacksNotSetError=function(){return new o(r.ClientConfigurationErrorMessage.noRedirectCallbacksSet.code,r.ClientConfigurationErrorMessage.noRedirectCallbacksSet.desc)},o.createInvalidCallbackObjectError=function(e,t){return new o(r.ClientConfigurationErrorMessage.invalidCallbackObject.code,r.ClientConfigurationErrorMessage.invalidCallbackObject.desc+" Given value for "+e+" callback function: "+t)},o.createEmptyScopesArrayError=function(e){return new o(r.ClientConfigurationErrorMessage.emptyScopes.code,r.ClientConfigurationErrorMessage.emptyScopes.desc+" Given value: "+e+".")},o.createScopesNonArrayError=function(e){return new o(r.ClientConfigurationErrorMessage.nonArrayScopes.code,r.ClientConfigurationErrorMessage.nonArrayScopes.desc+" Given value: "+e+".")},o.createClientIdSingleScopeError=function(e){return new o(r.ClientConfigurationErrorMessage.clientScope.code,r.ClientConfigurationErrorMessage.clientScope.desc+" Given value: "+e+".")},o.createScopesRequiredError=function(e){return new o(r.ClientConfigurationErrorMessage.scopesRequired.code,r.ClientConfigurationErrorMessage.scopesRequired.desc+" Given value: "+e)},o.createInvalidPromptError=function(e){return new o(r.ClientConfigurationErrorMessage.invalidPrompt.code,r.ClientConfigurationErrorMessage.invalidPrompt.desc+" Given value: "+e)},o}(n.ClientAuthError);r.ClientConfigurationError=o},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var n,o=r(0),i=r(3),s=r(12);(n=t.AuthorityType||(t.AuthorityType={}))[n.Aad=0]="Aad",n[n.Adfs=1]="Adfs",n[n.B2C=2]="B2C";var a=function(){function e(e,t){this.IsValidationEnabled=t,this.CanonicalAuthority=e,this.validateAsUri()}return Object.defineProperty(e.prototype,"Tenant",{get:function(){return this.CanonicalAuthorityUrlComponents.PathSegments[0]},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"AuthorizationEndpoint",{get:function(){return this.validateResolved(),this.tenantDiscoveryResponse.AuthorizationEndpoint.replace("{tenant}",this.Tenant)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"EndSessionEndpoint",{get:function(){return this.validateResolved(),this.tenantDiscoveryResponse.EndSessionEndpoint.replace("{tenant}",this.Tenant)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"SelfSignedJwtAudience",{get:function(){return this.validateResolved(),this.tenantDiscoveryResponse.Issuer.replace("{tenant}",this.Tenant)},enumerable:!0,configurable:!0}),e.prototype.validateResolved=function(){if(!this.tenantDiscoveryResponse)throw"Please call ResolveEndpointsAsync first"},Object.defineProperty(e.prototype,"CanonicalAuthority",{get:function(){return this.canonicalAuthority},set:function(e){this.canonicalAuthority=o.Utils.CanonicalizeUri(e),this.canonicalAuthorityUrlComponents=null},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"CanonicalAuthorityUrlComponents",{get:function(){return this.canonicalAuthorityUrlComponents||(this.canonicalAuthorityUrlComponents=o.Utils.GetUrlComponents(this.CanonicalAuthority)),this.canonicalAuthorityUrlComponents},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"DefaultOpenIdConfigurationEndpoint",{get:function(){return this.CanonicalAuthority+"v2.0/.well-known/openid-configuration"},enumerable:!0,configurable:!0}),e.prototype.validateAsUri=function(){var e;try{e=this.CanonicalAuthorityUrlComponents}catch(e){throw i.ClientConfigurationErrorMessage.invalidAuthorityType}if(!e.Protocol||"https:"!==e.Protocol.toLowerCase())throw i.ClientConfigurationErrorMessage.authorityUriInsecure;if(!e.PathSegments||e.PathSegments.length<1)throw i.ClientConfigurationErrorMessage.authorityUriInvalidPath},e.prototype.DiscoverEndpoints=function(e){return(new s.XhrClient).sendRequestAsync(e,"GET",!0).then(function(e){return{AuthorizationEndpoint:e.authorization_endpoint,EndSessionEndpoint:e.end_session_endpoint,Issuer:e.issuer}})},e.prototype.resolveEndpointsAsync=function(){var t=this,r="";return this.GetOpenIdConfigurationEndpointAsync().then(function(e){return r=e,t.DiscoverEndpoints(r)}).then(function(e){return t.tenantDiscoveryResponse=e,t})},e}();t.Authority=a},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var i=r(1);t.AuthErrorMessage={unexpectedError:{code:"unexpected_error",desc:"Unexpected error in authentication."}};var n=function(n){function o(e,t){var r=n.call(this,t)||this;return Object.setPrototypeOf(r,o.prototype),r.errorCode=e,r.errorMessage=t,r.name="AuthError",r}return i.__extends(o,n),o.createUnexpectedError=function(e){return new o(t.AuthErrorMessage.unexpectedError.code,t.AuthErrorMessage.unexpectedError.desc+": "+e)},o}(Error);t.AuthError=n},function(e,r,t){Object.defineProperty(r,"__esModule",{value:!0});var i=t(1),n=t(5),s=t(0);r.ClientAuthErrorMessage={multipleMatchingTokens:{code:"multiple_matching_tokens",desc:"The cache contains multiple tokens satisfying the requirements. Call AcquireToken again providing more requirements like authority."},multipleCacheAuthorities:{code:"multiple_authorities",desc:"Multiple authorities found in the cache. Pass authority in the API overload."},endpointResolutionError:{code:"endpoints_resolution_error",desc:"Error: could not resolve endpoints. Please check network and try again."},popUpWindowError:{code:"popup_window_error",desc:"Error opening popup window. This can happen if you are using IE or if popups are blocked in the browser."},tokenRenewalError:{code:"token_renewal_error",desc:"Token renewal operation failed due to timeout."},invalidIdToken:{code:"invalid_id_token",desc:"Invalid ID token."},invalidStateError:{code:"invalid_state_error",desc:"Invalid state."},nonceMismatchError:{code:"nonce_mismatch_error",desc:"Nonce is not matching, Nonce received: "},loginProgressError:{code:"login_progress_error",desc:"Login_In_Progress: Error during login call - login is already in progress."},acquireTokenProgressError:{code:"acquiretoken_progress_error",desc:"AcquireToken_In_Progress: Error during login call - login is already in progress."},userCancelledError:{code:"user_cancelled",desc:"User cancelled the flow."},callbackError:{code:"callback_error",desc:"Error occurred in token received callback function."},userLoginRequiredError:{code:"user_login_error",desc:"User login is required."},userDoesNotExistError:{code:"user_non_existent",desc:"User object does not exist. Please call a login API."}};var o=function(n){function o(e,t){var r=n.call(this,e,t)||this;return r.name="ClientAuthError",Object.setPrototypeOf(r,o.prototype),r}return i.__extends(o,n),o.createEndpointResolutionError=function(e){var t=r.ClientAuthErrorMessage.endpointResolutionError.desc;return e&&!s.Utils.isEmpty(e)&&(t+=" Details: "+e),new o(r.ClientAuthErrorMessage.endpointResolutionError.code,t)},o.createMultipleMatchingTokensInCacheError=function(e){return new o(r.ClientAuthErrorMessage.multipleMatchingTokens.code,"Cache error for scope "+e+": "+r.ClientAuthErrorMessage.multipleMatchingTokens.desc+".")},o.createMultipleAuthoritiesInCacheError=function(e){return new o(r.ClientAuthErrorMessage.multipleCacheAuthorities.code,"Cache error for scope "+e+": "+r.ClientAuthErrorMessage.multipleCacheAuthorities.desc+".")},o.createPopupWindowError=function(e){var t=r.ClientAuthErrorMessage.popUpWindowError.desc;return e&&!s.Utils.isEmpty(e)&&(t+=" Details: "+e),new o(r.ClientAuthErrorMessage.popUpWindowError.code,t)},o.createTokenRenewalTimeoutError=function(){return new o(r.ClientAuthErrorMessage.tokenRenewalError.code,r.ClientAuthErrorMessage.tokenRenewalError.desc)},o.createInvalidIdTokenError=function(e){return new o(r.ClientAuthErrorMessage.invalidIdToken.code,r.ClientAuthErrorMessage.invalidIdToken.desc+" Given token: "+e)},o.createInvalidStateError=function(e,t){return new o(r.ClientAuthErrorMessage.invalidStateError.code,r.ClientAuthErrorMessage.invalidStateError.desc+" "+e+", state expected : "+t+".")},o.createNonceMismatchError=function(e,t){return new o(r.ClientAuthErrorMessage.nonceMismatchError.code,r.ClientAuthErrorMessage.nonceMismatchError.desc+" "+e+", nonce expected : "+t+".")},o.createLoginInProgressError=function(){return new o(r.ClientAuthErrorMessage.loginProgressError.code,r.ClientAuthErrorMessage.loginProgressError.desc)},o.createAcquireTokenInProgressError=function(){return new o(r.ClientAuthErrorMessage.acquireTokenProgressError.code,r.ClientAuthErrorMessage.acquireTokenProgressError.desc)},o.createUserCancelledError=function(){return new o(r.ClientAuthErrorMessage.userCancelledError.code,r.ClientAuthErrorMessage.userCancelledError.desc)},o.createErrorInCallbackFunction=function(e){return new o(r.ClientAuthErrorMessage.callbackError.code,r.ClientAuthErrorMessage.callbackError.desc+" "+e+".")},o.createUserLoginRequiredError=function(){return new o(r.ClientAuthErrorMessage.userLoginRequiredError.code,r.ClientAuthErrorMessage.userLoginRequiredError.desc)},o.createUserDoesNotExistError=function(){return new o(r.ClientAuthErrorMessage.userDoesNotExistError.code,r.ClientAuthErrorMessage.userDoesNotExistError.desc)},o}(n.AuthError);r.ClientAuthError=o},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var c,n,i=r(0);(n=c=t.LogLevel||(t.LogLevel={}))[n.Error=0]="Error",n[n.Warning=1]="Warning",n[n.Info=2]="Info",n[n.Verbose=3]="Verbose";var o=function(){function e(e,t){void 0===t&&(t={}),this.level=c.Info;var r=t.correlationId,n=void 0===r?"":r,o=t.level,i=void 0===o?c.Info:o,s=t.piiLoggingEnabled,a=void 0!==s&&s;this.localCallback=e,this.correlationId=n,this.level=i,this.piiLoggingEnabled=a}return e.prototype.logMessage=function(e,t,r){if(!(e>this.level||!this.piiLoggingEnabled&&r)){var n,o=(new Date).toUTCString();n=i.Utils.isEmpty(this.correlationId)?o+":"+i.Utils.getLibraryVersion()+"-"+c[e]+" "+t:o+":"+this.correlationId+"-"+i.Utils.getLibraryVersion()+"-"+c[e]+" "+t,this.executeCallback(e,n,r)}},e.prototype.executeCallback=function(e,t,r){this.localCallback&&this.localCallback(e,t,r)},e.prototype.error=function(e){this.logMessage(c.Error,e,!1)},e.prototype.errorPii=function(e){this.logMessage(c.Error,e,!0)},e.prototype.warning=function(e){this.logMessage(c.Warning,e,!1)},e.prototype.warningPii=function(e){this.logMessage(c.Warning,e,!0)},e.prototype.info=function(e){this.logMessage(c.Info,e,!1)},e.prototype.infoPii=function(e){this.logMessage(c.Info,e,!0)},e.prototype.verbose=function(e){this.logMessage(c.Verbose,e,!1)},e.prototype.verbosePii=function(e){this.logMessage(c.Verbose,e,!0)},e}();t.Logger=o},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var i=r(1),n=r(5);t.ServerErrorMessage={serverUnavailable:{code:"server_unavailable",desc:"Server is temporarily unavailable."},unknownServerError:{code:"unknown_server_error"}};var o=function(n){function o(e,t){var r=n.call(this,e,t)||this;return r.name="ServerError",Object.setPrototypeOf(r,o.prototype),r}return i.__extends(o,n),o.createServerUnavailableError=function(){return new o(t.ServerErrorMessage.serverUnavailable.code,t.ServerErrorMessage.serverUnavailable.desc)},o.createUnknownServerError=function(e){return new o(t.ServerErrorMessage.unknownServerError.code,e)},o}(n.AuthError);t.ServerError=o},function(e,t,r){Object.defineProperty(t,"__esModule",{value:!0});var y=r(1),m=r(17),C=r(18),h=r(19),v=r(20),w=r(2),I=r(21),b=r(22),S=r(10),k=r(0),g=r(24),n=r(13),a=r(3),E=r(5),A=r(6),T=r(8),O=r(14),l="id_token",o="token",i="id_token token",s=function(e,t,r){var n=r.value;return r.value=function(){for(var e=[],t=0;t