@azure/msal-react
Advanced tools
Comparing version 1.4.5 to 1.4.6
@@ -88,3 +88,3 @@ 'use strict'; | ||
const name = "@azure/msal-react"; | ||
const version = "1.4.5"; | ||
const version = "1.4.6"; | ||
@@ -91,0 +91,0 @@ /* |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,r=require("@azure/msal-browser");const o=t.createContext({instance:r.stubbedPublicClientApplication,inProgress:r.InteractionStatus.None,accounts:[],logger:new r.Logger({})}),c=o.Consumer;function a(e,t){return"function"==typeof e?e(t):e}function s(e,t){if(e.length!==t.length)return!1;const n=[...t];return e.every(e=>{const t=n.shift();return!(!e||!t)&&e.homeAccountId===t.homeAccountId&&e.localAccountId===t.localAccountId&&e.username===t.username})}function i(e,t){return e.length>0&&(t.homeAccountId||t.localAccountId||t.username)&&e.filter(e=>!(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}var u;!function(e){e.UNBLOCK_INPROGRESS="UNBLOCK_INPROGRESS",e.EVENT="EVENT"}(u||(u={}));const l=(e,t)=>{const{type:n,payload:o}=t;let c=e.inProgress;switch(n){case u.UNBLOCK_INPROGRESS:e.inProgress===r.InteractionStatus.Startup&&(c=r.InteractionStatus.None,o.logger.info("MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'"));break;case u.EVENT:const t=o.message,a=r.EventMessageUtils.getInteractionStatusFromEvent(t,e.inProgress);a&&(o.logger.info(`MsalProvider - ${t.eventType} results in setting inProgress from ${e.inProgress} to ${a}`),c=a);break;default:throw new Error("Unknown action type: "+n)}const a=o.instance.getAllAccounts();return c===e.inProgress||s(a,e.accounts)?c!==e.inProgress?{...e,inProgress:c}:s(a,e.accounts)?e:{...e,accounts:a}:{...e,inProgress:c,accounts:a}},d=()=>t.useContext(o);function g(e,t){return t&&(t.username||t.homeAccountId||t.localAccountId)?!!i(e,t):e.length>0}function h(e){const{accounts:n}=d(),[r,o]=t.useState(()=>g(n,e));return t.useEffect(()=>{o(g(n,e))},[n,e]),r}function p(e,t){return t&&(t.homeAccountId||t.localAccountId||t.username)?i(e.getAllAccounts(),t):e.getActiveAccount()}function m(e){const{instance:n,inProgress:o,logger:c}=d(),[a,s]=t.useState(()=>p(n,e));return t.useEffect(()=>{s(t=>{const o=p(n,e);return r.AccountEntity.accountInfoIsEqual(t,o,!0)?t:(c.info("useAccount - Updating account"),o)})},[o,e,n,c]),a}class I extends r.AuthError{constructor(e,t){super(e,t),Object.setPrototypeOf(this,I.prototype),this.name="ReactAuthError"}static createInvalidInteractionTypeError(){return new I("invalid_interaction_type","The provided interaction type is invalid.")}static createUnableToFallbackToInteractionError(){return new I("unable_to_fallback_to_interaction","Interaction is required but another interaction is already in progress. Please try again when the current interaction is complete.")}}function A(e,n,o){const{instance:c,inProgress:a,logger:s}=d(),i=h(o),u=m(o),[[l,g],p]=t.useState([null,null]),A=t.useRef(a!==r.InteractionStatus.None);t.useEffect(()=>{A.current=a!==r.InteractionStatus.None},[a]);const f=t.useRef(!0);t.useEffect(()=>{(g||l)&&(f.current=!1)},[g,l]);const E=t.useCallback(async(t,o)=>{const a=o||n;switch(t||e){case r.InteractionType.Popup:return s.verbose("useMsalAuthentication - Calling loginPopup"),c.loginPopup(a);case r.InteractionType.Redirect:return s.verbose("useMsalAuthentication - Calling loginRedirect"),c.loginRedirect(a).then(null);case r.InteractionType.Silent:return s.verbose("useMsalAuthentication - Calling ssoSilent"),c.ssoSilent(a);default:throw I.createInvalidInteractionTypeError()}},[c,e,n,s]),v=t.useCallback(async(t,o)=>{const a=t||e;let i;return o?(s.trace("useMsalAuthentication - acquireToken - Using request provided in the callback"),i={...o}):n?(s.trace("useMsalAuthentication - acquireToken - Using request provided in the hook"),i={...n,scopes:n.scopes||r.OIDC_DEFAULT_SCOPES}):(s.trace("useMsalAuthentication - acquireToken - No request object provided, using default request."),i={scopes:r.OIDC_DEFAULT_SCOPES}),!i.account&&u&&(s.trace("useMsalAuthentication - acquireToken - Attaching account to request"),i.account=u),(async()=>(s.verbose("useMsalAuthentication - Calling acquireTokenSilent"),c.acquireTokenSilent(i).catch(async e=>{if(e instanceof r.InteractionRequiredAuthError){if(A.current)throw s.error("useMsalAuthentication - Interaction required but is already in progress. Please try again, if needed, after interaction completes."),I.createUnableToFallbackToInteractionError();return s.error("useMsalAuthentication - Interaction required, falling back to interaction"),E(a,i)}throw e})))().then(e=>(p([e,null]),e)).catch(e=>{throw p([null,e]),e})},[c,e,n,s,u,E]);return t.useEffect(()=>{const e=c.addEventCallback(e=>{switch(e.eventType){case r.EventType.LOGIN_SUCCESS:case r.EventType.SSO_SILENT_SUCCESS:e.payload&&p([e.payload,null]);break;case r.EventType.LOGIN_FAILURE:case r.EventType.SSO_SILENT_FAILURE:e.error&&p([null,e.error])}});return s.verbose("useMsalAuthentication - Registered event callback with id: "+e),()=>{e&&(s.verbose("useMsalAuthentication - Removing event callback "+e),c.removeEventCallback(e))}},[c,s]),t.useEffect(()=>{f.current&&a===r.InteractionStatus.None&&(f.current=!1,i?u&&(s.info("useMsalAuthentication - User is authenticated, attempting to acquire token"),v().catch(()=>{})):(s.info("useMsalAuthentication - No user is authenticated, attempting to login"),E().catch(()=>{})))},[i,u,a,E,v,s]),{login:E,acquireToken:v,result:l,error:g}}exports.AuthenticatedTemplate=function(e){let{username:o,homeAccountId:c,localAccountId:s,children:i}=e;const u=d();return h(t.useMemo(()=>({username:o,homeAccountId:c,localAccountId:s}),[o,c,s]))&&u.inProgress!==r.InteractionStatus.Startup?n.createElement(n.Fragment,null,a(i,u)):null},exports.MsalAuthenticationTemplate=function(e){let{interactionType:o,username:c,homeAccountId:s,localAccountId:i,authenticationRequest:u,loadingComponent:l,errorComponent:g,children:p}=e;const m=t.useMemo(()=>({username:c,homeAccountId:s,localAccountId:i}),[c,s,i]),I=d(),f=A(o,u,m),E=h(m);if(f.error&&I.inProgress===r.InteractionStatus.None){if(g)return n.createElement(g,Object.assign({},f));throw f.error}return E?n.createElement(n.Fragment,null,a(p,f)):l&&I.inProgress!==r.InteractionStatus.None?n.createElement(l,Object.assign({},I)):null},exports.MsalConsumer=c,exports.MsalContext=o,exports.MsalProvider=function(e){let{instance:c,children:a}=e;t.useEffect(()=>{c.initializeWrapperLibrary(r.WrapperSKU.React,"1.4.5")},[c]);const s=t.useMemo(()=>c.getLogger().clone("@azure/msal-react","1.4.5"),[c]),[i,d]=t.useReducer(l,void 0,()=>({inProgress:r.InteractionStatus.Startup,accounts:c.getAllAccounts()}));return t.useEffect(()=>{const e=c.addEventCallback(e=>{d({payload:{instance:c,logger:s,message:e},type:u.EVENT})});return s.verbose("MsalProvider - Registered event callback with id: "+e),c.initialize().then(()=>{c.handleRedirectPromise().catch(()=>{}).finally(()=>{d({payload:{instance:c,logger:s},type:u.UNBLOCK_INPROGRESS})})}),()=>{e&&(s.verbose("MsalProvider - Removing event callback "+e),c.removeEventCallback(e))}},[c,s]),n.createElement(o.Provider,{value:{instance:c,inProgress:i.inProgress,accounts:i.accounts,logger:s}},a)},exports.UnauthenticatedTemplate=function(e){let{username:o,homeAccountId:c,localAccountId:s,children:i}=e;const u=d();return h(t.useMemo(()=>({username:o,homeAccountId:c,localAccountId:s}),[o,c,s]))||u.inProgress===r.InteractionStatus.Startup||u.inProgress===r.InteractionStatus.HandleRedirect?null:n.createElement(n.Fragment,null,a(i,u))},exports.useAccount=m,exports.useIsAuthenticated=h,exports.useMsal=d,exports.useMsalAuthentication=A,exports.version="1.4.5",exports.withMsal=e=>{const t=t=>{const r=d();return n.createElement(e,Object.assign({},t,{msalContext:r}))};return t.displayName=`withMsal(${e.displayName||e.name||"Component"})`,t}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),n=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,r=require("@azure/msal-browser");const o=t.createContext({instance:r.stubbedPublicClientApplication,inProgress:r.InteractionStatus.None,accounts:[],logger:new r.Logger({})}),c=o.Consumer;function a(e,t){return"function"==typeof e?e(t):e}function s(e,t){if(e.length!==t.length)return!1;const n=[...t];return e.every(e=>{const t=n.shift();return!(!e||!t)&&e.homeAccountId===t.homeAccountId&&e.localAccountId===t.localAccountId&&e.username===t.username})}function i(e,t){return e.length>0&&(t.homeAccountId||t.localAccountId||t.username)&&e.filter(e=>!(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}var u;!function(e){e.UNBLOCK_INPROGRESS="UNBLOCK_INPROGRESS",e.EVENT="EVENT"}(u||(u={}));const l=(e,t)=>{const{type:n,payload:o}=t;let c=e.inProgress;switch(n){case u.UNBLOCK_INPROGRESS:e.inProgress===r.InteractionStatus.Startup&&(c=r.InteractionStatus.None,o.logger.info("MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'"));break;case u.EVENT:const t=o.message,a=r.EventMessageUtils.getInteractionStatusFromEvent(t,e.inProgress);a&&(o.logger.info(`MsalProvider - ${t.eventType} results in setting inProgress from ${e.inProgress} to ${a}`),c=a);break;default:throw new Error("Unknown action type: "+n)}const a=o.instance.getAllAccounts();return c===e.inProgress||s(a,e.accounts)?c!==e.inProgress?{...e,inProgress:c}:s(a,e.accounts)?e:{...e,accounts:a}:{...e,inProgress:c,accounts:a}},d=()=>t.useContext(o);function g(e,t){return t&&(t.username||t.homeAccountId||t.localAccountId)?!!i(e,t):e.length>0}function h(e){const{accounts:n}=d(),[r,o]=t.useState(()=>g(n,e));return t.useEffect(()=>{o(g(n,e))},[n,e]),r}function p(e,t){return t&&(t.homeAccountId||t.localAccountId||t.username)?i(e.getAllAccounts(),t):e.getActiveAccount()}function m(e){const{instance:n,inProgress:o,logger:c}=d(),[a,s]=t.useState(()=>p(n,e));return t.useEffect(()=>{s(t=>{const o=p(n,e);return r.AccountEntity.accountInfoIsEqual(t,o,!0)?t:(c.info("useAccount - Updating account"),o)})},[o,e,n,c]),a}class I extends r.AuthError{constructor(e,t){super(e,t),Object.setPrototypeOf(this,I.prototype),this.name="ReactAuthError"}static createInvalidInteractionTypeError(){return new I("invalid_interaction_type","The provided interaction type is invalid.")}static createUnableToFallbackToInteractionError(){return new I("unable_to_fallback_to_interaction","Interaction is required but another interaction is already in progress. Please try again when the current interaction is complete.")}}function A(e,n,o){const{instance:c,inProgress:a,logger:s}=d(),i=h(o),u=m(o),[[l,g],p]=t.useState([null,null]),A=t.useRef(a!==r.InteractionStatus.None);t.useEffect(()=>{A.current=a!==r.InteractionStatus.None},[a]);const f=t.useRef(!0);t.useEffect(()=>{(g||l)&&(f.current=!1)},[g,l]);const E=t.useCallback(async(t,o)=>{const a=o||n;switch(t||e){case r.InteractionType.Popup:return s.verbose("useMsalAuthentication - Calling loginPopup"),c.loginPopup(a);case r.InteractionType.Redirect:return s.verbose("useMsalAuthentication - Calling loginRedirect"),c.loginRedirect(a).then(null);case r.InteractionType.Silent:return s.verbose("useMsalAuthentication - Calling ssoSilent"),c.ssoSilent(a);default:throw I.createInvalidInteractionTypeError()}},[c,e,n,s]),v=t.useCallback(async(t,o)=>{const a=t||e;let i;return o?(s.trace("useMsalAuthentication - acquireToken - Using request provided in the callback"),i={...o}):n?(s.trace("useMsalAuthentication - acquireToken - Using request provided in the hook"),i={...n,scopes:n.scopes||r.OIDC_DEFAULT_SCOPES}):(s.trace("useMsalAuthentication - acquireToken - No request object provided, using default request."),i={scopes:r.OIDC_DEFAULT_SCOPES}),!i.account&&u&&(s.trace("useMsalAuthentication - acquireToken - Attaching account to request"),i.account=u),(async()=>(s.verbose("useMsalAuthentication - Calling acquireTokenSilent"),c.acquireTokenSilent(i).catch(async e=>{if(e instanceof r.InteractionRequiredAuthError){if(A.current)throw s.error("useMsalAuthentication - Interaction required but is already in progress. Please try again, if needed, after interaction completes."),I.createUnableToFallbackToInteractionError();return s.error("useMsalAuthentication - Interaction required, falling back to interaction"),E(a,i)}throw e})))().then(e=>(p([e,null]),e)).catch(e=>{throw p([null,e]),e})},[c,e,n,s,u,E]);return t.useEffect(()=>{const e=c.addEventCallback(e=>{switch(e.eventType){case r.EventType.LOGIN_SUCCESS:case r.EventType.SSO_SILENT_SUCCESS:e.payload&&p([e.payload,null]);break;case r.EventType.LOGIN_FAILURE:case r.EventType.SSO_SILENT_FAILURE:e.error&&p([null,e.error])}});return s.verbose("useMsalAuthentication - Registered event callback with id: "+e),()=>{e&&(s.verbose("useMsalAuthentication - Removing event callback "+e),c.removeEventCallback(e))}},[c,s]),t.useEffect(()=>{f.current&&a===r.InteractionStatus.None&&(f.current=!1,i?u&&(s.info("useMsalAuthentication - User is authenticated, attempting to acquire token"),v().catch(()=>{})):(s.info("useMsalAuthentication - No user is authenticated, attempting to login"),E().catch(()=>{})))},[i,u,a,E,v,s]),{login:E,acquireToken:v,result:l,error:g}}exports.AuthenticatedTemplate=function(e){let{username:o,homeAccountId:c,localAccountId:s,children:i}=e;const u=d();return h(t.useMemo(()=>({username:o,homeAccountId:c,localAccountId:s}),[o,c,s]))&&u.inProgress!==r.InteractionStatus.Startup?n.createElement(n.Fragment,null,a(i,u)):null},exports.MsalAuthenticationTemplate=function(e){let{interactionType:o,username:c,homeAccountId:s,localAccountId:i,authenticationRequest:u,loadingComponent:l,errorComponent:g,children:p}=e;const m=t.useMemo(()=>({username:c,homeAccountId:s,localAccountId:i}),[c,s,i]),I=d(),f=A(o,u,m),E=h(m);if(f.error&&I.inProgress===r.InteractionStatus.None){if(g)return n.createElement(g,Object.assign({},f));throw f.error}return E?n.createElement(n.Fragment,null,a(p,f)):l&&I.inProgress!==r.InteractionStatus.None?n.createElement(l,Object.assign({},I)):null},exports.MsalConsumer=c,exports.MsalContext=o,exports.MsalProvider=function(e){let{instance:c,children:a}=e;t.useEffect(()=>{c.initializeWrapperLibrary(r.WrapperSKU.React,"1.4.6")},[c]);const s=t.useMemo(()=>c.getLogger().clone("@azure/msal-react","1.4.6"),[c]),[i,d]=t.useReducer(l,void 0,()=>({inProgress:r.InteractionStatus.Startup,accounts:c.getAllAccounts()}));return t.useEffect(()=>{const e=c.addEventCallback(e=>{d({payload:{instance:c,logger:s,message:e},type:u.EVENT})});return s.verbose("MsalProvider - Registered event callback with id: "+e),c.initialize().then(()=>{c.handleRedirectPromise().catch(()=>{}).finally(()=>{d({payload:{instance:c,logger:s},type:u.UNBLOCK_INPROGRESS})})}),()=>{e&&(s.verbose("MsalProvider - Removing event callback "+e),c.removeEventCallback(e))}},[c,s]),n.createElement(o.Provider,{value:{instance:c,inProgress:i.inProgress,accounts:i.accounts,logger:s}},a)},exports.UnauthenticatedTemplate=function(e){let{username:o,homeAccountId:c,localAccountId:s,children:i}=e;const u=d();return h(t.useMemo(()=>({username:o,homeAccountId:c,localAccountId:s}),[o,c,s]))||u.inProgress===r.InteractionStatus.Startup||u.inProgress===r.InteractionStatus.HandleRedirect?null:n.createElement(n.Fragment,null,a(i,u))},exports.useAccount=m,exports.useIsAuthenticated=h,exports.useMsal=d,exports.useMsalAuthentication=A,exports.version="1.4.6",exports.withMsal=e=>{const t=t=>{const r=d();return n.createElement(e,Object.assign({},t,{msalContext:r}))};return t.displayName=`withMsal(${e.displayName||e.name||"Component"})`,t}; | ||
//# sourceMappingURL=msal-react.cjs.production.min.js.map |
@@ -81,3 +81,3 @@ import React__default, { createContext, useEffect, useMemo, useReducer, useContext, useState, useRef, useCallback } from 'react'; | ||
const name = "@azure/msal-react"; | ||
const version = "1.4.5"; | ||
const version = "1.4.6"; | ||
@@ -84,0 +84,0 @@ /* |
export declare const name = "@azure/msal-react"; | ||
export declare const version = "1.4.5"; | ||
export declare const version = "1.4.6"; |
{ | ||
"name": "@azure/msal-react", | ||
"version": "1.4.5", | ||
"version": "1.4.6", | ||
"author": { | ||
@@ -44,3 +44,3 @@ "name": "Microsoft", | ||
"peerDependencies": { | ||
"@azure/msal-browser": "^2.28.1", | ||
"@azure/msal-browser": "^2.28.2", | ||
"react": "^16.8.0 || ^17 || ^18" | ||
@@ -50,3 +50,3 @@ }, | ||
"devDependencies": { | ||
"@azure/msal-browser": "^2.28.1", | ||
"@azure/msal-browser": "^2.28.2", | ||
"@testing-library/jest-dom": "^5.11.5", | ||
@@ -53,0 +53,0 @@ "@testing-library/react": "^11.2.3", |
@@ -125,2 +125,3 @@ # Microsoft Authentication Library for React (msal-react) | ||
- [Gatsby Sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-react-samples/gatsby-sample) | ||
- [B2C Sample](https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-react-samples/b2c-sample) | ||
@@ -130,3 +131,3 @@ More advanced samples backed with a tutorial can be found in the [Azure Samples](https://github.com/Azure-Samples) space on GitHub: | ||
- [React SPA calling Express.js web API](https://github.com/Azure-Samples/ms-identity-javascript-react-tutorial/tree/main/3-Authorization-II/1-call-api) | ||
- [React SPA calling Express.js web API using Proof of Possesion tokens](https://github.com/Azure-Samples/ms-identity-javascript-react-tutorial/tree/main/6-AdvancedScenarios/2-call-api-pop) | ||
- [React SPA calling Express.js web API using App Roles and RBAC](https://github.com/Azure-Samples/ms-identity-javascript-react-tutorial/tree/main/5-AccessControl/1-call-api-roles) | ||
- [React SPA calling Microsoft Graph via Express.js web API using on-behalf-of flow](https://github.com/Azure-Samples/ms-identity-javascript-react-tutorial/tree/main/6-AdvancedScenarios/1-call-api-obo) | ||
@@ -133,0 +134,0 @@ - [Deployment tutorial for Azure Static Web Apps](https://github.com/Azure-Samples/ms-identity-javascript-react-tutorial/tree/main/4-Deployment/2-deploy-static) |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
204952
145