@azure/msal-react
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.2
@@ -5,2 +5,55 @@ { | ||
{ | ||
"date": "Tue, 12 Jan 2021 00:51:26 GMT", | ||
"tag": "@azure/msal-react_v1.0.0-alpha.2", | ||
"version": "1.0.0-alpha.2", | ||
"comments": { | ||
"prerelease": [ | ||
{ | ||
"comment": "Add logger (#2727)", | ||
"author": "thomas.norling@microsoft.com", | ||
"commit": "cc0c22274fabb4304ce8b574c488cc5191362848", | ||
"package": "@azure/msal-react" | ||
}, | ||
{ | ||
"comment": "Fix redirect loop when service returns error (#2762)", | ||
"author": "thomas.norling@microsoft.com", | ||
"commit": "730d30b7bb2afa597d7b23dc0393dc78d01f849e", | ||
"package": "@azure/msal-react" | ||
} | ||
], | ||
"none": [ | ||
{ | ||
"comment": "Update storybook to v6", | ||
"author": "janutter@microsoft.com", | ||
"commit": "df94f4216584735768589fb047d74762bfa75911", | ||
"package": "@azure/msal-react" | ||
}, | ||
{ | ||
"comment": "Readme Update (#2814)", | ||
"author": "thomas.norling@microsoft.com", | ||
"commit": "194f21637c900f3e4afb64bbcf47cfc1328cb1bf", | ||
"package": "@azure/msal-react" | ||
}, | ||
{ | ||
"comment": "package-lock changes", | ||
"author": "prkanher@microsoft.com", | ||
"commit": "c092667cd997935625eafbc491ede54417d4b657", | ||
"package": "@azure/msal-react" | ||
}, | ||
{ | ||
"comment": "package.lock change", | ||
"author": "samuel.kamau@microsoft.com", | ||
"commit": "4e50ca592f5a17578072be9e4ac28e05b3e6d594", | ||
"package": "@azure/msal-react" | ||
}, | ||
{ | ||
"comment": "Readme update (#2813)", | ||
"author": "thomas.norling@microsoft.com", | ||
"commit": "c22616826105ea3bad37745e6ffcf27e409fe774", | ||
"package": "@azure/msal-react" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"date": "Mon, 07 Dec 2020 22:19:03 GMT", | ||
@@ -7,0 +60,0 @@ "tag": "@azure/msal-react_v1.0.0-alpha.1", |
# Change Log - @azure/msal-react | ||
This log was last generated on Mon, 07 Dec 2020 22:19:03 GMT and should not be manually modified. | ||
This log was last generated on Tue, 12 Jan 2021 00:51:26 GMT and should not be manually modified. | ||
<!-- Start content --> | ||
## 1.0.0-alpha.2 | ||
Tue, 12 Jan 2021 00:51:26 GMT | ||
### Changes | ||
- Add logger (#2727) (thomas.norling@microsoft.com) | ||
- Fix redirect loop when service returns error (#2762) (thomas.norling@microsoft.com) | ||
## 1.0.0-alpha.1 | ||
@@ -8,0 +17,0 @@ |
@@ -15,2 +15,6 @@ 'use strict'; | ||
*/ | ||
var Constants = { | ||
SKU: "@azure/msal-react", | ||
VERSION: "1.0.0-alpha.1" | ||
}; | ||
var InteractionStatus; | ||
@@ -40,3 +44,4 @@ | ||
inProgress: InteractionStatus.None, | ||
accounts: [] | ||
accounts: [], | ||
logger: /*#__PURE__*/new msalBrowser.Logger({}) | ||
}; | ||
@@ -88,4 +93,7 @@ var MsalContext = /*#__PURE__*/React.createContext(defaultMsalContext); | ||
children = _ref.children; | ||
// Create a logger instance for msal-react with the same options as PublicClientApplication | ||
var logger = React.useMemo(function () { | ||
return instance.getLogger().clone(Constants.SKU, Constants.VERSION); | ||
}, [instance]); // State hook to store accounts | ||
// State hook to store accounts | ||
var _useState = React.useState([]), | ||
@@ -114,3 +122,6 @@ accounts = _useState[0], | ||
if (!accountArraysAreEqual(currentAccounts, accounts)) { | ||
logger.info("MsalProvider - updating account state"); | ||
setAccounts(currentAccounts); | ||
} else { | ||
logger.info("MsalProvider - no account changes"); | ||
} | ||
@@ -121,9 +132,11 @@ | ||
}); | ||
logger.verbose("MsalProvider - Registered event callback with id: " + callbackId); | ||
return function () { | ||
// Remove callback when component unmounts or accounts change | ||
if (callbackId) { | ||
logger.verbose("MsalProvider - Removing event callback " + callbackId); | ||
instance.removeEventCallback(callbackId); | ||
} | ||
}; | ||
}, [instance, accounts]); | ||
}, [instance, accounts, logger]); | ||
React.useEffect(function () { | ||
@@ -133,2 +146,3 @@ var callbackId = instance.addEventCallback(function (message) { | ||
case msalBrowser.EventType.LOGIN_START: | ||
logger.info("MsalProvider - Login called, setting inProgress to 'login'"); | ||
setInProgress(InteractionStatus.Login); | ||
@@ -138,2 +152,3 @@ break; | ||
case msalBrowser.EventType.SSO_SILENT_START: | ||
logger.info("MsalProvider - SsoSilent called, setting inProgress to 'ssoSilent'"); | ||
setInProgress(InteractionStatus.SsoSilent); | ||
@@ -144,2 +159,3 @@ break; | ||
if (message.interactionType === msalBrowser.InteractionType.Redirect || message.interactionType === msalBrowser.InteractionType.Popup) { | ||
logger.info("MsalProvider - Interactive acquireToken called, setting inProgress to 'acquireToken'"); | ||
setInProgress(InteractionStatus.AcquireToken); | ||
@@ -151,2 +167,3 @@ } | ||
case msalBrowser.EventType.HANDLE_REDIRECT_START: | ||
logger.info("MsalProvider - HandleRedirectPromise called, setting inProgress to 'handleRedirect'"); | ||
setInProgress(InteractionStatus.HandleRedirect); | ||
@@ -156,2 +173,3 @@ break; | ||
case msalBrowser.EventType.LOGOUT_START: | ||
logger.info("MsalProvider - Logout called, setting inProgress to 'logout'"); | ||
setInProgress(InteractionStatus.Logout); | ||
@@ -166,2 +184,3 @@ break; | ||
case msalBrowser.EventType.LOGOUT_FAILURE: | ||
logger.info("MsalProvider - Interactive request finished, setting inProgress to 'none'"); | ||
setInProgress(InteractionStatus.None); | ||
@@ -173,2 +192,3 @@ break; | ||
if (message.interactionType === msalBrowser.InteractionType.Redirect || message.interactionType === msalBrowser.InteractionType.Popup) { | ||
logger.info("MsalProvider - Interactive acquireToken request finished, setting inProgress to 'none'"); | ||
setInProgress(InteractionStatus.None); | ||
@@ -180,2 +200,3 @@ } | ||
}); | ||
logger.verbose("MsalProvider - Registered event callback with id: " + callbackId); | ||
instance.handleRedirectPromise()["catch"](function () { | ||
@@ -187,10 +208,12 @@ // Errors should be handled by listening to the LOGIN_FAILURE event | ||
if (callbackId) { | ||
logger.verbose("MsalProvider - Removing event callback " + callbackId); | ||
instance.removeEventCallback(callbackId); | ||
} | ||
}; | ||
}, [instance]); | ||
}, [instance, logger]); | ||
var contextValue = { | ||
instance: instance, | ||
inProgress: inProgress, | ||
accounts: accounts | ||
accounts: accounts, | ||
logger: logger | ||
}; | ||
@@ -1139,3 +1162,4 @@ return React__default.createElement(MsalContext.Provider, { | ||
instance = _useMsal.instance, | ||
inProgress = _useMsal.inProgress; | ||
inProgress = _useMsal.inProgress, | ||
logger = _useMsal.logger; | ||
@@ -1164,18 +1188,22 @@ var isAuthenticated = useIsAuthenticated(accountIdentifiers); | ||
_context.t0 = loginType; | ||
_context.next = _context.t0 === msalBrowser.InteractionType.Popup ? 5 : _context.t0 === msalBrowser.InteractionType.Redirect ? 6 : _context.t0 === msalBrowser.InteractionType.Silent ? 7 : 8; | ||
_context.next = _context.t0 === msalBrowser.InteractionType.Popup ? 5 : _context.t0 === msalBrowser.InteractionType.Redirect ? 7 : _context.t0 === msalBrowser.InteractionType.Silent ? 9 : 11; | ||
break; | ||
case 5: | ||
logger.verbose("useMsalAuthentication - Calling loginPopup"); | ||
return _context.abrupt("return", instance.loginPopup(loginRequest)); | ||
case 6: | ||
case 7: | ||
// This promise is not expected to resolve due to full frame redirect | ||
logger.verbose("useMsalAuthentication - Calling loginRedirect"); | ||
return _context.abrupt("return", instance.loginRedirect(loginRequest).then(null)); | ||
case 7: | ||
case 9: | ||
logger.verbose("useMsalAuthentication - Calling ssoSilent"); | ||
return _context.abrupt("return", instance.ssoSilent(loginRequest)); | ||
case 8: | ||
case 11: | ||
throw "Invalid interaction type provided."; | ||
case 9: | ||
case 12: | ||
case "end": | ||
@@ -1191,3 +1219,3 @@ return _context.stop(); | ||
}; | ||
}(), [instance, interactionType, authenticationRequest]); | ||
}(), [instance, interactionType, authenticationRequest, logger]); | ||
React.useEffect(function () { | ||
@@ -1213,11 +1241,14 @@ var callbackId = instance.addEventCallback(function (message) { | ||
}); | ||
logger.verbose("useMsalAuthentication - Registered event callback with id: " + callbackId); | ||
return function () { | ||
if (callbackId) { | ||
logger.verbose("useMsalAuthentication - Removing event callback " + callbackId); | ||
instance.removeEventCallback(callbackId); | ||
} | ||
}; | ||
}, [instance]); | ||
}, [instance, logger]); | ||
React.useEffect(function () { | ||
if (!hasBeenCalled && !isAuthenticated && inProgress === InteractionStatus.None) { | ||
// Ensure login is only called one time from within this hook, any subsequent login attempts should use the callback returned | ||
if (!hasBeenCalled && !error && !isAuthenticated && inProgress === InteractionStatus.None) { | ||
logger.info("useMsalAuthentication - No user is authenticated, attempting to login"); // Ensure login is only called one time from within this hook, any subsequent login attempts should use the callback returned | ||
setHasBeenCalled(true); | ||
@@ -1229,3 +1260,3 @@ login()["catch"](function () { | ||
} | ||
}, [isAuthenticated, inProgress, hasBeenCalled, login]); | ||
}, [isAuthenticated, inProgress, error, hasBeenCalled, login, logger]); | ||
return { | ||
@@ -1232,0 +1263,0 @@ login: login, |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,n=require("react"),r=(e=n)&&"object"==typeof e&&"default"in e?e.default:e,o=require("@azure/msal-browser");!function(e){e.Startup="startup",e.Login="login",e.Logout="logout",e.AcquireToken="acquireToken",e.SsoSilent="ssoSilent",e.HandleRedirect="handleRedirect",e.None="none"}(t||(t={}));var a=n.createContext({instance:o.stubbedPublicClientApplication,inProgress:t.None,accounts:[]}),c=a.Consumer;function i(e,t){return"function"==typeof e?e(t):e}var u=function(){return n.useContext(a)};function s(e){var t=u(),r=t.instance,o=t.inProgress,a=n.useState(null),c=a[0],i=a[1];return n.useEffect((function(){i(function(e,t){var n=e.getAllAccounts();return n.length>0&&(t.homeAccountId||t.localAccountId||t.username)&&n.filter((function(e){return!(t.username&&t.username.toLowerCase()!==e.username.toLowerCase()||t.homeAccountId&&t.homeAccountId.toLowerCase()!==e.homeAccountId.toLowerCase()||t.localAccountId&&t.localAccountId.toLowerCase()!==e.localAccountId.toLowerCase())}))[0]||null}(r,e))}),[o,e,r]),c}function l(e){var t=u().accounts,r=s(e||{}),o=n.useState(!1),a=o[0],c=o[1];return n.useEffect((function(){c(function(e,t,n){return n&&(n.username||n.homeAccountId||n.localAccountId)?!!t:e.length>0}(t,r,e))}),[t,r,e]),a}function f(e,t,n,r,o,a,c){try{var i=e[a](c),u=i.value}catch(e){return void n(e)}i.done?t(u):Promise.resolve(u).then(r,o)}var h,p=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",c=r.toStringTag||"@@toStringTag";function i(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{i({},"")}catch(e){i=function(e,t,n){return e[t]=n}}function u(e,t,n,r){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),a=new L(r||[]);return o._invoke=function(e,t,n){var r="suspendedStart";return function(o,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw a;return{value:void 0,done:!0}}for(n.method=o,n.arg=a;;){var c=n.delegate;if(c){var i=T(c,n);if(i){if(i===l)continue;return i}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var u=s(e,t,n);if("normal"===u.type){if(r=n.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r="completed",n.method="throw",n.arg=u.arg)}}}(e,n,a),o}function s(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var l={};function f(){}function h(){}function p(){}var v={};v[o]=function(){return this};var d=Object.getPrototypeOf,y=d&&d(d(A([])));y&&y!==t&&n.call(y,o)&&(v=y);var E=p.prototype=f.prototype=Object.create(v);function m(e){["next","throw","return"].forEach((function(t){i(e,t,(function(e){return this._invoke(t,e)}))}))}function g(e,t){var r;this._invoke=function(o,a){function c(){return new t((function(r,c){!function r(o,a,c,i){var u=s(e[o],e,a);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,c,i)}),(function(e){r("throw",e,c,i)})):t.resolve(f).then((function(e){l.value=e,c(l)}),(function(e){return r("throw",e,c,i)}))}i(u.arg)}(o,a,r,c)}))}return r=r?r.then(c,c):c()}}function T(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,T(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=s(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,l;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function S(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,this),this.reset(!0)}function A(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:w}}function w(){return{value:void 0,done:!0}}return h.prototype=E.constructor=p,p.constructor=h,h.displayName=i(p,c,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,i(e,c,"GeneratorFunction")),e.prototype=Object.create(E),e},e.awrap=function(e){return{__await:e}},m(g.prototype),g.prototype[a]=function(){return this},e.AsyncIterator=g,e.async=function(t,n,r,o,a){void 0===a&&(a=Promise);var c=new g(u(t,n,r,o),a);return e.isGeneratorFunction(n)?c:c.next().then((function(e){return e.done?e.value:c.next()}))},m(E),i(E,c,"Generator"),E[o]=function(){return this},E.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=A,L.prototype={constructor:L,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(I),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return c.type="throw",c.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],c=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var i=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(i&&u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(i){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var c=a?a.completion:{};return c.type=e,c.arg=t,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(c)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),I(n),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;I(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:A(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(h={exports:{}}),h.exports);function v(e,r,a){var c=u(),i=c.instance,s=c.inProgress,h=l(a),v=n.useState([null,null]),d=v[0],y=d[0],E=d[1],m=v[1],g=n.useState(!1),T=g[0],S=g[1],I=n.useCallback(function(){var t,n=(t=p.mark((function t(n,a){var c;return p.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:c=a||r,t.t0=n||e,t.next=t.t0===o.InteractionType.Popup?5:t.t0===o.InteractionType.Redirect?6:t.t0===o.InteractionType.Silent?7:8;break;case 5:return t.abrupt("return",i.loginPopup(c));case 6:return t.abrupt("return",i.loginRedirect(c).then(null));case 7:return t.abrupt("return",i.ssoSilent(c));case 8:throw"Invalid interaction type provided.";case 9:case"end":return t.stop()}}),t)})),function(){var e=this,n=arguments;return new Promise((function(r,o){var a=t.apply(e,n);function c(e){f(a,r,o,c,i,"next",e)}function i(e){f(a,r,o,c,i,"throw",e)}c(void 0)}))});return function(e,t){return n.apply(this,arguments)}}(),[i,e,r]);return n.useEffect((function(){var e=i.addEventCallback((function(e){switch(e.eventType){case o.EventType.LOGIN_SUCCESS:case o.EventType.SSO_SILENT_SUCCESS:e.payload&&m([e.payload,null]);break;case o.EventType.LOGIN_FAILURE:case o.EventType.SSO_SILENT_FAILURE:e.error&&m([null,e.error])}}));return function(){e&&i.removeEventCallback(e)}}),[i]),n.useEffect((function(){T||h||s!==t.None||(S(!0),I().catch((function(){})))}),[h,s,T,I]),{login:I,result:y,error:E}}exports.AuthenticatedTemplate=function(e){var t=e.username,o=e.homeAccountId,a=e.localAccountId,c=e.children,s=u();return l(n.useMemo((function(){return{username:t,homeAccountId:o,localAccountId:a}}),[t,o,a]))?r.createElement(r.Fragment,null,i(c,s)):null},exports.MsalAuthenticationTemplate=function(e){var o=e.interactionType,a=e.username,c=e.homeAccountId,s=e.localAccountId,f=e.authenticationRequest,h=e.loadingComponent,p=e.errorComponent,d=e.children,y=n.useMemo((function(){return{username:a,homeAccountId:c,localAccountId:s}}),[a,c,s]),E=u(),m=v(o,f,y),g=l(y);if(m.error&&E.inProgress===t.None){if(p)return r.createElement(p,Object.assign({},m));throw m.error}return g?r.createElement(r.Fragment,null,i(d,m)):h&&E.inProgress!==t.None?r.createElement(h,Object.assign({},E)):null},exports.MsalConsumer=c,exports.MsalContext=a,exports.MsalProvider=function(e){var c=e.instance,i=e.children,u=n.useState([]),s=u[0],l=u[1],f=n.useState(t.Startup),h=f[0],p=f[1];return n.useEffect((function(){var e=c.addEventCallback((function(e){switch(e.eventType){case o.EventType.LOGIN_SUCCESS:case o.EventType.SSO_SILENT_SUCCESS:case o.EventType.HANDLE_REDIRECT_END:case o.EventType.LOGIN_FAILURE:case o.EventType.SSO_SILENT_FAILURE:case o.EventType.LOGOUT_FAILURE:case o.EventType.ACQUIRE_TOKEN_SUCCESS:case o.EventType.ACQUIRE_TOKEN_FAILURE:var t=c.getAllAccounts();(function(e,t){if(e.length!==t.length)return!1;var n=[].concat(t);return e.every((function(e){var t=n.shift();return!(!e||!t)&&e.homeAccountId===t.homeAccountId&&e.localAccountId===t.localAccountId&&e.username===t.username}))})(t,s)||l(t)}}));return function(){e&&c.removeEventCallback(e)}}),[c,s]),n.useEffect((function(){var e=c.addEventCallback((function(e){switch(e.eventType){case o.EventType.LOGIN_START:p(t.Login);break;case o.EventType.SSO_SILENT_START:p(t.SsoSilent);break;case o.EventType.ACQUIRE_TOKEN_START:e.interactionType!==o.InteractionType.Redirect&&e.interactionType!==o.InteractionType.Popup||p(t.AcquireToken);break;case o.EventType.HANDLE_REDIRECT_START:p(t.HandleRedirect);break;case o.EventType.LOGOUT_START:p(t.Logout);break;case o.EventType.LOGIN_SUCCESS:case o.EventType.SSO_SILENT_SUCCESS:case o.EventType.HANDLE_REDIRECT_END:case o.EventType.LOGIN_FAILURE:case o.EventType.SSO_SILENT_FAILURE:case o.EventType.LOGOUT_FAILURE:p(t.None);break;case o.EventType.ACQUIRE_TOKEN_SUCCESS:case o.EventType.ACQUIRE_TOKEN_FAILURE:e.interactionType!==o.InteractionType.Redirect&&e.interactionType!==o.InteractionType.Popup||p(t.None)}}));return c.handleRedirectPromise().catch((function(){})),function(){e&&c.removeEventCallback(e)}}),[c]),r.createElement(a.Provider,{value:{instance:c,inProgress:h,accounts:s}},i)},exports.UnauthenticatedTemplate=function(e){var t=e.username,o=e.homeAccountId,a=e.localAccountId,c=e.children,s=u();return l(n.useMemo((function(){return{username:t,homeAccountId:o,localAccountId:a}}),[t,o,a]))?null:r.createElement(r.Fragment,null,i(c,s))},exports.useAccount=s,exports.useIsAuthenticated=l,exports.useMsal=u,exports.useMsalAuthentication=v,exports.withMsal=function(e){var t=function(t){var n=u();return r.createElement(e,Object.assign({},t,{msalContext:n}))};return t.displayName="withMsal("+(e.displayName||e.name||"Component")+")",t}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t,n=require("react"),r=(e=n)&&"object"==typeof e&&"default"in e?e.default:e,o=require("@azure/msal-browser");!function(e){e.Startup="startup",e.Login="login",e.Logout="logout",e.AcquireToken="acquireToken",e.SsoSilent="ssoSilent",e.HandleRedirect="handleRedirect",e.None="none"}(t||(t={}));var a=n.createContext({instance:o.stubbedPublicClientApplication,inProgress:t.None,accounts:[],logger:new o.Logger({})}),i=a.Consumer;function c(e,t){return"function"==typeof e?e(t):e}var u=function(){return n.useContext(a)};function s(e){var t=u(),r=t.instance,o=t.inProgress,a=n.useState(null),i=a[0],c=a[1];return n.useEffect((function(){c(function(e,t){var n=e.getAllAccounts();return n.length>0&&(t.homeAccountId||t.localAccountId||t.username)&&n.filter((function(e){return!(t.username&&t.username.toLowerCase()!==e.username.toLowerCase()||t.homeAccountId&&t.homeAccountId.toLowerCase()!==e.homeAccountId.toLowerCase()||t.localAccountId&&t.localAccountId.toLowerCase()!==e.localAccountId.toLowerCase())}))[0]||null}(r,e))}),[o,e,r]),i}function l(e){var t=u().accounts,r=s(e||{}),o=n.useState(!1),a=o[0],i=o[1];return n.useEffect((function(){i(function(e,t,n){return n&&(n.username||n.homeAccountId||n.localAccountId)?!!t:e.length>0}(t,r,e))}),[t,r,e]),a}function f(e,t,n,r,o,a,i){try{var c=e[a](i),u=c.value}catch(e){return void n(e)}c.done?t(u):Promise.resolve(u).then(r,o)}var h,v=(function(e){var t=function(e){var t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",i=r.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,r){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),a=new L(r||[]);return o._invoke=function(e,t,n){var r="suspendedStart";return function(o,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw a;return{value:void 0,done:!0}}for(n.method=o,n.arg=a;;){var i=n.delegate;if(i){var c=T(i,n);if(c){if(c===l)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var u=s(e,t,n);if("normal"===u.type){if(r=n.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r="completed",n.method="throw",n.arg=u.arg)}}}(e,n,a),o}function s(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var l={};function f(){}function h(){}function v(){}var p={};p[o]=function(){return this};var d=Object.getPrototypeOf,y=d&&d(d(A([])));y&&y!==t&&n.call(y,o)&&(p=y);var g=v.prototype=f.prototype=Object.create(p);function m(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function E(e,t){var r;this._invoke=function(o,a){function i(){return new t((function(r,i){!function r(o,a,i,c){var u=s(e[o],e,a);if("throw"!==u.type){var l=u.arg,f=l.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,i,c)}),(function(e){r("throw",e,i,c)})):t.resolve(f).then((function(e){l.value=e,i(l)}),(function(e){return r("throw",e,i,c)}))}c(u.arg)}(o,a,r,i)}))}return r=r?r.then(i,i):i()}}function T(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,T(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=s(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,l;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function S(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function I(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function L(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(S,this),this.reset(!0)}function A(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:w}}function w(){return{value:void 0,done:!0}}return h.prototype=g.constructor=v,v.constructor=h,h.displayName=c(v,i,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,v):(e.__proto__=v,c(e,i,"GeneratorFunction")),e.prototype=Object.create(g),e},e.awrap=function(e){return{__await:e}},m(E.prototype),E.prototype[a]=function(){return this},e.AsyncIterator=E,e.async=function(t,n,r,o,a){void 0===a&&(a=Promise);var i=new E(u(t,n,r,o),a);return e.isGeneratorFunction(n)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},m(g),c(g,i,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=A,L.prototype={constructor:L,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(I),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return i.type="throw",i.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),I(n),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;I(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:A(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},e}(e.exports);try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}}(h={exports:{}}),h.exports);function p(e,r,a){var i=u(),c=i.instance,s=i.inProgress,h=i.logger,p=l(a),d=n.useState([null,null]),y=d[0],g=y[0],m=y[1],E=d[1],T=n.useState(!1),S=T[0],I=T[1],L=n.useCallback(function(){var t,n=(t=v.mark((function t(n,a){var i;return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:i=a||r,t.t0=n||e,t.next=t.t0===o.InteractionType.Popup?5:t.t0===o.InteractionType.Redirect?7:t.t0===o.InteractionType.Silent?9:11;break;case 5:return h.verbose("useMsalAuthentication - Calling loginPopup"),t.abrupt("return",c.loginPopup(i));case 7:return h.verbose("useMsalAuthentication - Calling loginRedirect"),t.abrupt("return",c.loginRedirect(i).then(null));case 9:return h.verbose("useMsalAuthentication - Calling ssoSilent"),t.abrupt("return",c.ssoSilent(i));case 11:throw"Invalid interaction type provided.";case 12:case"end":return t.stop()}}),t)})),function(){var e=this,n=arguments;return new Promise((function(r,o){var a=t.apply(e,n);function i(e){f(a,r,o,i,c,"next",e)}function c(e){f(a,r,o,i,c,"throw",e)}i(void 0)}))});return function(e,t){return n.apply(this,arguments)}}(),[c,e,r,h]);return n.useEffect((function(){var e=c.addEventCallback((function(e){switch(e.eventType){case o.EventType.LOGIN_SUCCESS:case o.EventType.SSO_SILENT_SUCCESS:e.payload&&E([e.payload,null]);break;case o.EventType.LOGIN_FAILURE:case o.EventType.SSO_SILENT_FAILURE:e.error&&E([null,e.error])}}));return h.verbose("useMsalAuthentication - Registered event callback with id: "+e),function(){e&&(h.verbose("useMsalAuthentication - Removing event callback "+e),c.removeEventCallback(e))}}),[c,h]),n.useEffect((function(){S||m||p||s!==t.None||(h.info("useMsalAuthentication - No user is authenticated, attempting to login"),I(!0),L().catch((function(){})))}),[p,s,m,S,L,h]),{login:L,result:g,error:m}}exports.AuthenticatedTemplate=function(e){var t=e.username,o=e.homeAccountId,a=e.localAccountId,i=e.children,s=u();return l(n.useMemo((function(){return{username:t,homeAccountId:o,localAccountId:a}}),[t,o,a]))?r.createElement(r.Fragment,null,c(i,s)):null},exports.MsalAuthenticationTemplate=function(e){var o=e.interactionType,a=e.username,i=e.homeAccountId,s=e.localAccountId,f=e.authenticationRequest,h=e.loadingComponent,v=e.errorComponent,d=e.children,y=n.useMemo((function(){return{username:a,homeAccountId:i,localAccountId:s}}),[a,i,s]),g=u(),m=p(o,f,y),E=l(y);if(m.error&&g.inProgress===t.None){if(v)return r.createElement(v,Object.assign({},m));throw m.error}return E?r.createElement(r.Fragment,null,c(d,m)):h&&g.inProgress!==t.None?r.createElement(h,Object.assign({},g)):null},exports.MsalConsumer=i,exports.MsalContext=a,exports.MsalProvider=function(e){var i=e.instance,c=e.children,u=n.useMemo((function(){return i.getLogger().clone("@azure/msal-react","1.0.0-alpha.1")}),[i]),s=n.useState([]),l=s[0],f=s[1],h=n.useState(t.Startup),v=h[0],p=h[1];return n.useEffect((function(){var e=i.addEventCallback((function(e){switch(e.eventType){case o.EventType.LOGIN_SUCCESS:case o.EventType.SSO_SILENT_SUCCESS:case o.EventType.HANDLE_REDIRECT_END:case o.EventType.LOGIN_FAILURE:case o.EventType.SSO_SILENT_FAILURE:case o.EventType.LOGOUT_FAILURE:case o.EventType.ACQUIRE_TOKEN_SUCCESS:case o.EventType.ACQUIRE_TOKEN_FAILURE:var t=i.getAllAccounts();!function(e,t){if(e.length!==t.length)return!1;var n=[].concat(t);return e.every((function(e){var t=n.shift();return!(!e||!t)&&e.homeAccountId===t.homeAccountId&&e.localAccountId===t.localAccountId&&e.username===t.username}))}(t,l)?(u.info("MsalProvider - updating account state"),f(t)):u.info("MsalProvider - no account changes")}}));return u.verbose("MsalProvider - Registered event callback with id: "+e),function(){e&&(u.verbose("MsalProvider - Removing event callback "+e),i.removeEventCallback(e))}}),[i,l,u]),n.useEffect((function(){var e=i.addEventCallback((function(e){switch(e.eventType){case o.EventType.LOGIN_START:u.info("MsalProvider - Login called, setting inProgress to 'login'"),p(t.Login);break;case o.EventType.SSO_SILENT_START:u.info("MsalProvider - SsoSilent called, setting inProgress to 'ssoSilent'"),p(t.SsoSilent);break;case o.EventType.ACQUIRE_TOKEN_START:e.interactionType!==o.InteractionType.Redirect&&e.interactionType!==o.InteractionType.Popup||(u.info("MsalProvider - Interactive acquireToken called, setting inProgress to 'acquireToken'"),p(t.AcquireToken));break;case o.EventType.HANDLE_REDIRECT_START:u.info("MsalProvider - HandleRedirectPromise called, setting inProgress to 'handleRedirect'"),p(t.HandleRedirect);break;case o.EventType.LOGOUT_START:u.info("MsalProvider - Logout called, setting inProgress to 'logout'"),p(t.Logout);break;case o.EventType.LOGIN_SUCCESS:case o.EventType.SSO_SILENT_SUCCESS:case o.EventType.HANDLE_REDIRECT_END:case o.EventType.LOGIN_FAILURE:case o.EventType.SSO_SILENT_FAILURE:case o.EventType.LOGOUT_FAILURE:u.info("MsalProvider - Interactive request finished, setting inProgress to 'none'"),p(t.None);break;case o.EventType.ACQUIRE_TOKEN_SUCCESS:case o.EventType.ACQUIRE_TOKEN_FAILURE:e.interactionType!==o.InteractionType.Redirect&&e.interactionType!==o.InteractionType.Popup||(u.info("MsalProvider - Interactive acquireToken request finished, setting inProgress to 'none'"),p(t.None))}}));return u.verbose("MsalProvider - Registered event callback with id: "+e),i.handleRedirectPromise().catch((function(){})),function(){e&&(u.verbose("MsalProvider - Removing event callback "+e),i.removeEventCallback(e))}}),[i,u]),r.createElement(a.Provider,{value:{instance:i,inProgress:v,accounts:l,logger:u}},c)},exports.UnauthenticatedTemplate=function(e){var t=e.username,o=e.homeAccountId,a=e.localAccountId,i=e.children,s=u();return l(n.useMemo((function(){return{username:t,homeAccountId:o,localAccountId:a}}),[t,o,a]))?null:r.createElement(r.Fragment,null,c(i,s))},exports.useAccount=s,exports.useIsAuthenticated=l,exports.useMsal=u,exports.useMsalAuthentication=p,exports.withMsal=function(e){var t=function(t){var n=u();return r.createElement(e,Object.assign({},t,{msalContext:n}))};return t.displayName="withMsal("+(e.displayName||e.name||"Component")+")",t}; | ||
//# sourceMappingURL=msal-react.cjs.production.min.js.map |
@@ -1,3 +0,3 @@ | ||
import React__default, { createContext, useState, useEffect, useContext, useMemo, useCallback } from 'react'; | ||
import { stubbedPublicClientApplication, EventType, InteractionType } from '@azure/msal-browser'; | ||
import React__default, { createContext, useMemo, useState, useEffect, useContext, useCallback } from 'react'; | ||
import { stubbedPublicClientApplication, Logger, EventType, InteractionType } from '@azure/msal-browser'; | ||
@@ -8,2 +8,6 @@ /* | ||
*/ | ||
var Constants = { | ||
SKU: "@azure/msal-react", | ||
VERSION: "1.0.0-alpha.1" | ||
}; | ||
var InteractionStatus; | ||
@@ -33,3 +37,4 @@ | ||
inProgress: InteractionStatus.None, | ||
accounts: [] | ||
accounts: [], | ||
logger: /*#__PURE__*/new Logger({}) | ||
}; | ||
@@ -81,4 +86,7 @@ var MsalContext = /*#__PURE__*/createContext(defaultMsalContext); | ||
children = _ref.children; | ||
// Create a logger instance for msal-react with the same options as PublicClientApplication | ||
var logger = useMemo(function () { | ||
return instance.getLogger().clone(Constants.SKU, Constants.VERSION); | ||
}, [instance]); // State hook to store accounts | ||
// State hook to store accounts | ||
var _useState = useState([]), | ||
@@ -107,3 +115,6 @@ accounts = _useState[0], | ||
if (!accountArraysAreEqual(currentAccounts, accounts)) { | ||
logger.info("MsalProvider - updating account state"); | ||
setAccounts(currentAccounts); | ||
} else { | ||
logger.info("MsalProvider - no account changes"); | ||
} | ||
@@ -114,9 +125,11 @@ | ||
}); | ||
logger.verbose("MsalProvider - Registered event callback with id: " + callbackId); | ||
return function () { | ||
// Remove callback when component unmounts or accounts change | ||
if (callbackId) { | ||
logger.verbose("MsalProvider - Removing event callback " + callbackId); | ||
instance.removeEventCallback(callbackId); | ||
} | ||
}; | ||
}, [instance, accounts]); | ||
}, [instance, accounts, logger]); | ||
useEffect(function () { | ||
@@ -126,2 +139,3 @@ var callbackId = instance.addEventCallback(function (message) { | ||
case EventType.LOGIN_START: | ||
logger.info("MsalProvider - Login called, setting inProgress to 'login'"); | ||
setInProgress(InteractionStatus.Login); | ||
@@ -131,2 +145,3 @@ break; | ||
case EventType.SSO_SILENT_START: | ||
logger.info("MsalProvider - SsoSilent called, setting inProgress to 'ssoSilent'"); | ||
setInProgress(InteractionStatus.SsoSilent); | ||
@@ -137,2 +152,3 @@ break; | ||
if (message.interactionType === InteractionType.Redirect || message.interactionType === InteractionType.Popup) { | ||
logger.info("MsalProvider - Interactive acquireToken called, setting inProgress to 'acquireToken'"); | ||
setInProgress(InteractionStatus.AcquireToken); | ||
@@ -144,2 +160,3 @@ } | ||
case EventType.HANDLE_REDIRECT_START: | ||
logger.info("MsalProvider - HandleRedirectPromise called, setting inProgress to 'handleRedirect'"); | ||
setInProgress(InteractionStatus.HandleRedirect); | ||
@@ -149,2 +166,3 @@ break; | ||
case EventType.LOGOUT_START: | ||
logger.info("MsalProvider - Logout called, setting inProgress to 'logout'"); | ||
setInProgress(InteractionStatus.Logout); | ||
@@ -159,2 +177,3 @@ break; | ||
case EventType.LOGOUT_FAILURE: | ||
logger.info("MsalProvider - Interactive request finished, setting inProgress to 'none'"); | ||
setInProgress(InteractionStatus.None); | ||
@@ -166,2 +185,3 @@ break; | ||
if (message.interactionType === InteractionType.Redirect || message.interactionType === InteractionType.Popup) { | ||
logger.info("MsalProvider - Interactive acquireToken request finished, setting inProgress to 'none'"); | ||
setInProgress(InteractionStatus.None); | ||
@@ -173,2 +193,3 @@ } | ||
}); | ||
logger.verbose("MsalProvider - Registered event callback with id: " + callbackId); | ||
instance.handleRedirectPromise()["catch"](function () { | ||
@@ -180,10 +201,12 @@ // Errors should be handled by listening to the LOGIN_FAILURE event | ||
if (callbackId) { | ||
logger.verbose("MsalProvider - Removing event callback " + callbackId); | ||
instance.removeEventCallback(callbackId); | ||
} | ||
}; | ||
}, [instance]); | ||
}, [instance, logger]); | ||
var contextValue = { | ||
instance: instance, | ||
inProgress: inProgress, | ||
accounts: accounts | ||
accounts: accounts, | ||
logger: logger | ||
}; | ||
@@ -1132,3 +1155,4 @@ return React__default.createElement(MsalContext.Provider, { | ||
instance = _useMsal.instance, | ||
inProgress = _useMsal.inProgress; | ||
inProgress = _useMsal.inProgress, | ||
logger = _useMsal.logger; | ||
@@ -1157,18 +1181,22 @@ var isAuthenticated = useIsAuthenticated(accountIdentifiers); | ||
_context.t0 = loginType; | ||
_context.next = _context.t0 === InteractionType.Popup ? 5 : _context.t0 === InteractionType.Redirect ? 6 : _context.t0 === InteractionType.Silent ? 7 : 8; | ||
_context.next = _context.t0 === InteractionType.Popup ? 5 : _context.t0 === InteractionType.Redirect ? 7 : _context.t0 === InteractionType.Silent ? 9 : 11; | ||
break; | ||
case 5: | ||
logger.verbose("useMsalAuthentication - Calling loginPopup"); | ||
return _context.abrupt("return", instance.loginPopup(loginRequest)); | ||
case 6: | ||
case 7: | ||
// This promise is not expected to resolve due to full frame redirect | ||
logger.verbose("useMsalAuthentication - Calling loginRedirect"); | ||
return _context.abrupt("return", instance.loginRedirect(loginRequest).then(null)); | ||
case 7: | ||
case 9: | ||
logger.verbose("useMsalAuthentication - Calling ssoSilent"); | ||
return _context.abrupt("return", instance.ssoSilent(loginRequest)); | ||
case 8: | ||
case 11: | ||
throw "Invalid interaction type provided."; | ||
case 9: | ||
case 12: | ||
case "end": | ||
@@ -1184,3 +1212,3 @@ return _context.stop(); | ||
}; | ||
}(), [instance, interactionType, authenticationRequest]); | ||
}(), [instance, interactionType, authenticationRequest, logger]); | ||
useEffect(function () { | ||
@@ -1206,11 +1234,14 @@ var callbackId = instance.addEventCallback(function (message) { | ||
}); | ||
logger.verbose("useMsalAuthentication - Registered event callback with id: " + callbackId); | ||
return function () { | ||
if (callbackId) { | ||
logger.verbose("useMsalAuthentication - Removing event callback " + callbackId); | ||
instance.removeEventCallback(callbackId); | ||
} | ||
}; | ||
}, [instance]); | ||
}, [instance, logger]); | ||
useEffect(function () { | ||
if (!hasBeenCalled && !isAuthenticated && inProgress === InteractionStatus.None) { | ||
// Ensure login is only called one time from within this hook, any subsequent login attempts should use the callback returned | ||
if (!hasBeenCalled && !error && !isAuthenticated && inProgress === InteractionStatus.None) { | ||
logger.info("useMsalAuthentication - No user is authenticated, attempting to login"); // Ensure login is only called one time from within this hook, any subsequent login attempts should use the callback returned | ||
setHasBeenCalled(true); | ||
@@ -1222,3 +1253,3 @@ login()["catch"](function () { | ||
} | ||
}, [isAuthenticated, inProgress, hasBeenCalled, login]); | ||
}, [isAuthenticated, inProgress, error, hasBeenCalled, login, logger]); | ||
return { | ||
@@ -1225,0 +1256,0 @@ login: login, |
import * as React from "react"; | ||
import { IPublicClientApplication } from "@azure/msal-browser"; | ||
import { IPublicClientApplication, Logger } from "@azure/msal-browser"; | ||
import { InteractionStatus } from "./utils/Constants"; | ||
@@ -9,4 +9,5 @@ import { AccountIdentifiers } from "./types/AccountIdentifiers"; | ||
accounts: AccountIdentifiers[]; | ||
logger: Logger; | ||
} | ||
export declare const MsalContext: React.Context<IMsalContext>; | ||
export declare const MsalConsumer: React.Consumer<IMsalContext>; |
@@ -0,1 +1,5 @@ | ||
export declare const Constants: { | ||
SKU: string; | ||
VERSION: string; | ||
}; | ||
export declare enum InteractionStatus { | ||
@@ -2,0 +6,0 @@ Startup = "startup", |
{ | ||
"name": "@azure/msal-react", | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0-alpha.2", | ||
"author": { | ||
@@ -40,3 +40,3 @@ "name": "Microsoft", | ||
"peerDependencies": { | ||
"@azure/msal-browser": "^2.8.0", | ||
"@azure/msal-browser": "^2.9.0", | ||
"react": "^16.13.0 || ^17" | ||
@@ -46,11 +46,10 @@ }, | ||
"devDependencies": { | ||
"@azure/msal-browser": "^2.8.0", | ||
"@babel/core": "^7.10.5", | ||
"@storybook/addon-actions": "^5.3.19", | ||
"@storybook/addon-docs": "^5.3.19", | ||
"@storybook/addon-info": "^5.3.19", | ||
"@storybook/addon-links": "^5.3.19", | ||
"@storybook/addons": "^5.3.19", | ||
"@storybook/addon-storysource": "^5.3.19", | ||
"@storybook/react": "^5.3.19", | ||
"@azure/msal-browser": "^2.9.0", | ||
"@babel/core": "^7.12.10", | ||
"@storybook/addon-actions": "^6.1.10", | ||
"@storybook/addon-docs": "^6.1.10", | ||
"@storybook/addon-links": "^6.1.10", | ||
"@storybook/addon-storysource": "^6.1.10", | ||
"@storybook/addons": "^6.1.10", | ||
"@storybook/react": "^6.1.10", | ||
"@testing-library/jest-dom": "^5.11.5", | ||
@@ -73,3 +72,4 @@ "@testing-library/react": "^11.1.0", | ||
"typescript": "^3.9.7" | ||
} | ||
}, | ||
"dependencies": {} | ||
} |
@@ -20,3 +20,3 @@ # Microsoft Authentication Library for React (msal-react) | ||
- [MSAL React Specific Concepts](#msal-react-specific-concepts) | ||
1. [Samples](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-react-samples) | ||
1. [Samples](#samples) | ||
1. [Security Reporting](#security-reporting) | ||
@@ -111,2 +111,11 @@ 1. [License](#license) | ||
## Samples | ||
Our [samples directory](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-react-samples) contains several example apps you can spin up to see how this library can be used in different contexts. | ||
- [Create React App (JS) Sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-react-samples/react-router-sample) | ||
- [Create React App (TS) Sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-react-samples/typescript-sample) | ||
- [Next.js Sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-react-samples/nextjs-sample) | ||
- [Gatsby Sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-react-samples/gatsby-sample) | ||
## Security Reporting | ||
@@ -113,0 +122,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
354550
25
2572
130