Socket
Socket
Sign inDemoInstall

react-oidc-context

Package Overview
Dependencies
11
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.2 to 1.0.3

138

dist/react-oidc-context.cjs.development.js

@@ -5,8 +5,10 @@ 'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var React = _interopDefault(require('react'));
var React = require('react');
var oidcClient = require('oidc-client');
var AuthContext = /*#__PURE__*/React.createContext(undefined);
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
var AuthContext = /*#__PURE__*/React__default['default'].createContext(undefined);
AuthContext.displayName = "AuthContext";

@@ -83,6 +85,16 @@

function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
function createCommonjsModule(fn, basedir, module) {
return module = {
path: basedir,
exports: {},
require: function (path, base) {
return commonjsRequire();
}
}, fn(module, module.exports), module.exports;
}
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
}
var runtime_1 = createCommonjsModule(function (module) {

@@ -819,3 +831,3 @@ /**

// the regeneratorRuntime variable at the top of this file.
module.exports
module.exports
));

@@ -875,9 +887,22 @@

var hasAuthParams = function hasAuthParams(locationSearch) {
if (locationSearch === void 0) {
locationSearch = window.location.search;
var hasAuthParams = function hasAuthParams(location) {
if (location === void 0) {
location = window.location;
}
var searchParams = new URLSearchParams(locationSearch);
return Boolean((searchParams.get("code") || searchParams.get("error")) && searchParams.get("state"));
// response_mode: query
var searchParams = new URLSearchParams(location.search);
if ((searchParams.get("code") || searchParams.get("error")) && searchParams.get("state")) {
return true;
} // response_mode: fragment
searchParams = new URLSearchParams(location.hash.replace("#", "?"));
if ((searchParams.get("code") || searchParams.get("error")) && searchParams.get("state")) {
return true;
}
return false;
};

@@ -910,3 +935,3 @@

var _React$useState = React.useState(function () {
var _React$useState = React__default['default'].useState(function () {
return new oidcClient.UserManager(userManagerProps);

@@ -916,8 +941,8 @@ }),

var _React$useReducer = React.useReducer(reducer, initialAuthState),
var _React$useReducer = React__default['default'].useReducer(reducer, initialAuthState),
state = _React$useReducer[0],
dispatch = _React$useReducer[1];
React.useEffect(function () {
_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
React__default['default'].useEffect(function () {
void _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
var _user, user;

@@ -973,28 +998,9 @@

React.useEffect(function () {
React__default['default'].useEffect(function () {
// event UserLoaded (e.g. initial load, silent renew success)
var handleUserLoaded = function handleUserLoaded() {
_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
var user;
return runtime_1.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return userManager.getUser();
case 2:
user = _context2.sent;
dispatch({
type: "USER_LOADED",
user: user
});
case 4:
case "end":
return _context2.stop();
}
}
}, _callee2);
}))();
var handleUserLoaded = function handleUserLoaded(user) {
dispatch({
type: "USER_LOADED",
user: user
});
};

@@ -1026,8 +1032,8 @@

}, [userManager]);
var removeUser = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
return runtime_1.wrap(function _callee3$(_context3) {
var removeUser = React__default['default'].useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
return runtime_1.wrap(function _callee2$(_context2) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context2.prev = _context2.next) {
case 0:
_context3.next = 2;
_context2.next = 2;
return userManager.removeUser();

@@ -1040,14 +1046,14 @@

case "end":
return _context3.stop();
return _context2.stop();
}
}
}, _callee3);
}, _callee2);
})), [userManager, onRemoveUser]);
var signoutRedirect = React.useCallback( /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(args) {
return runtime_1.wrap(function _callee4$(_context4) {
var signoutRedirect = React__default['default'].useCallback( /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(args) {
return runtime_1.wrap(function _callee3$(_context3) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context3.prev = _context3.next) {
case 0:
_context4.next = 2;
_context3.next = 2;
return userManager.signoutRedirect(args);

@@ -1060,19 +1066,19 @@

case "end":
return _context4.stop();
return _context3.stop();
}
}
}, _callee4);
}, _callee3);
}));
return function (_x) {
return _ref4.apply(this, arguments);
return _ref3.apply(this, arguments);
};
}(), [userManager, onSignoutRedirect]);
var signoutPopup = React.useCallback( /*#__PURE__*/function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(args) {
return runtime_1.wrap(function _callee5$(_context5) {
var signoutPopup = React__default['default'].useCallback( /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(args) {
return runtime_1.wrap(function _callee4$(_context4) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context4.prev = _context4.next) {
case 0:
_context5.next = 2;
_context4.next = 2;
return userManager.signoutPopup(args);

@@ -1085,13 +1091,13 @@

case "end":
return _context5.stop();
return _context4.stop();
}
}
}, _callee5);
}, _callee4);
}));
return function (_x2) {
return _ref5.apply(this, arguments);
return _ref4.apply(this, arguments);
};
}(), [userManager, onSignoutPopup]);
return React.createElement(AuthContext.Provider, {
return React__default['default'].createElement(AuthContext.Provider, {
value: _extends({}, state, {

@@ -1115,3 +1121,3 @@ settings: userManager.settings,

var useAuth = function useAuth() {
var context = React.useContext(AuthContext);
var context = React__default['default'].useContext(AuthContext);

@@ -1134,3 +1140,3 @@ if (!context) {

var auth = useAuth();
return React.createElement(Component, Object.assign({}, props, auth));
return React__default['default'].createElement(Component, _extends({}, props, auth));
};

@@ -1137,0 +1143,0 @@

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t,e=(t=require("react"))&&"object"==typeof t&&"default"in t?t.default:t,r=require("oidc-client"),n=e.createContext(void 0);function o(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,i){var a=t.apply(e,r);function c(t){o(a,n,i,c,u,"next",t)}function u(t){o(a,n,i,c,u,"throw",t)}c(void 0)}))}}function a(){return(a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}n.displayName="AuthContext";var c,u=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=Object.create((e&&e.prototype instanceof l?e:l).prototype),i=new L(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=x(a,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=s(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===f)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,i),o}function s(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var f={};function l(){}function h(){}function p(){}var d={};d[o]=function(){return this};var v=Object.getPrototypeOf,y=v&&v(v(S([])));y&&y!==e&&r.call(y,o)&&(d=y);var g=p.prototype=l.prototype=Object.create(d);function m(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function w(t,e){var n;this._invoke=function(o,i){function a(){return new e((function(n,a){!function n(o,i,a,c){var u=s(t[o],t,i);if("throw"!==u.type){var f=u.arg,l=f.value;return l&&"object"==typeof l&&r.call(l,"__await")?e.resolve(l.__await).then((function(t){n("next",t,a,c)}),(function(t){n("throw",t,a,c)})):e.resolve(l).then((function(t){f.value=t,a(f)}),(function(t){return n("throw",t,a,c)}))}c(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function x(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,x(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=s(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function S(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return i.next=i}}return{next:R}}function R(){return{value:void 0,done:!0}}return h.prototype=g.constructor=p,p.constructor=h,h.displayName=c(p,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,c(t,a,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},m(w.prototype),w.prototype[i]=function(){return this},t.AsyncIterator=w,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new w(u(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},m(g),c(g,a,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=S,L.prototype={constructor:L,reset:function(t){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(E),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return a.type="throw",a.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var c=r.call(i,"catchLoc"),u=r.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,f):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;E(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:S(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(c={exports:{}}),c.exports),s={isLoading:!0,isAuthenticated:!1},f=function(t,e){switch(e.type){case"INITIALISED":case"USER_LOADED":return a({},t,{user:e.user,isLoading:!1,isAuthenticated:!!e.user&&!e.user.expired,error:void 0});case"USER_UNLOADED":return a({},t,{user:void 0,isAuthenticated:!1});case"ERROR":return a({},t,{isLoading:!1,error:e.error})}},l=function(t){void 0===t&&(t=window.location.search);var e=new URLSearchParams(t);return Boolean((e.get("code")||e.get("error"))&&e.get("state"))},h=function(t){return function(t){return t instanceof Error?t:new Error("Login failed")}}(),p=function(){var t=e.useContext(n);if(!t)throw new Error("AuthProvider context is undefined, please verify you are calling useAuth() as child of a <AuthProvider> component.");return t};exports.AuthContext=n,exports.AuthProvider=function(t){var o=t.children,c=t.onSigninCallback,p=t.skipSigninCallback,d=t.onRemoveUser,v=t.onSignoutRedirect,y=t.onSignoutPopup,g=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}(t,["children","onSigninCallback","skipSigninCallback","onRemoveUser","onSignoutRedirect","onSignoutPopup"]),m=e.useState((function(){return new r.UserManager(g)}))[0],w=e.useReducer(f,s),x=w[0],b=w[1];e.useEffect((function(){i(u.mark((function t(){var e;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,!l()||p){t.next=6;break}return t.next=4,m.signinCallback();case 4:e=t.sent,c&&c(e);case 6:return t.next=8,m.getUser();case 8:b({type:"INITIALISED",user:t.sent}),t.next=15;break;case 12:t.prev=12,t.t0=t.catch(0),b({type:"ERROR",error:h(t.t0)});case 15:case"end":return t.stop()}}),t,null,[[0,12]])})))()}),[m,p,c]),e.useEffect((function(){var t=function(){i(u.mark((function t(){return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m.getUser();case 2:b({type:"USER_LOADED",user:t.sent});case 4:case"end":return t.stop()}}),t)})))()};m.events.addUserLoaded(t);var e=function(){b({type:"USER_UNLOADED"})};m.events.addUserUnloaded(e);var r=function(t){b({type:"ERROR",error:t})};return m.events.addSilentRenewError(r),function(){m.events.removeUserLoaded(t),m.events.removeUserUnloaded(e),m.events.removeSilentRenewError(r)}}),[m]);var E=e.useCallback(i(u.mark((function t(){return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m.removeUser();case 2:d&&d();case 3:case"end":return t.stop()}}),t)}))),[m,d]),L=e.useCallback(function(){var t=i(u.mark((function t(e){return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m.signoutRedirect(e);case 2:v&&v();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[m,v]),S=e.useCallback(function(){var t=i(u.mark((function t(e){return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m.signoutPopup(e);case 2:y&&y();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[m,y]);return e.createElement(n.Provider,{value:a({},x,{settings:m.settings,clearStaleState:m.clearStaleState.bind(m),removeUser:E,signinPopup:m.signinPopup.bind(m),signinSilent:m.signinSilent.bind(m),signinRedirect:m.signinRedirect.bind(m),signoutRedirect:L,signoutPopup:S,querySessionStatus:m.querySessionStatus.bind(m),revokeAccessToken:m.revokeAccessToken.bind(m),startSilentRenew:m.startSilentRenew.bind(m),stopSilentRenew:m.stopSilentRenew.bind(m)})},o)},exports.hasAuthParams=l,exports.loginError=h,exports.useAuth=p,exports.withAuth=function(t){var r=function(r){var n=p();return e.createElement(t,Object.assign({},r,n))};return r.displayName="withAuth("+(t.displayName||t.name)+")",r};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("oidc-client");function r(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=r(t),o=n.default.createContext(void 0);function i(t,e,r,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void r(t)}u.done?e(c):Promise.resolve(c).then(n,o)}function a(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function u(t){i(a,n,o,u,c,"next",t)}function c(t){i(a,n,o,u,c,"throw",t)}u(void 0)}))}}function u(){return(u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}o.displayName="AuthContext";var c,s=(function(t){var e=function(t){var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",u=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof y?e:y).prototype),i=new A(n||[]);return o._invoke=function(t,e,r){var n=l;return function(o,i){if(n===p)throw new Error("Generator is already running");if(n===d){if("throw"===o)throw i;return _()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var u=R(a,r);if(u){if(u===v)continue;return u}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var c=f(t,e,r);if("normal"===c.type){if(n=r.done?d:h,c.arg===v)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=d,r.method="throw",r.arg=c.arg)}}}(t,r,i),o}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var l="suspendedStart",h="suspendedYield",p="executing",d="completed",v={};function y(){}function g(){}function m(){}var w={};w[i]=function(){return this};var x=Object.getPrototypeOf,E=x&&x(x(P([])));E&&E!==r&&n.call(E,i)&&(w=E);var b=m.prototype=y.prototype=Object.create(w);function L(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function r(o,i,a,u){var c=f(t[o],t,i);if("throw"!==c.type){var s=c.arg,l=s.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,a,u)}),(function(t){r("throw",t,a,u)})):e.resolve(l).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,u)}))}u(c.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function R(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,R(t,r),"throw"===r.method))return v;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return v}var o=f(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,v;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,v):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,v)}function k(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function A(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(k,this),this.reset(!0)}function P(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:_}}function _(){return{value:e,done:!0}}return g.prototype=b.constructor=m,m.constructor=g,g.displayName=c(m,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,c(t,u,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},L(S.prototype),S.prototype[a]=function(){return this},t.AsyncIterator=S,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new S(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},L(b),c(b,u,"Generator"),b[i]=function(){return this},b.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=P,A.prototype={constructor:A,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return u.type="throw",u.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){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 i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,v):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),v},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),v}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:P(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),v}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(c={path:void 0,exports:{},require:function(t,e){return function(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}()}}),c.exports),f={isLoading:!0,isAuthenticated:!1},l=function(t,e){switch(e.type){case"INITIALISED":case"USER_LOADED":return u({},t,{user:e.user,isLoading:!1,isAuthenticated:!!e.user&&!e.user.expired,error:void 0});case"USER_UNLOADED":return u({},t,{user:void 0,isAuthenticated:!1});case"ERROR":return u({},t,{isLoading:!1,error:e.error})}},h=function(t){void 0===t&&(t=window.location);var e=new URLSearchParams(t.search);return!(!e.get("code")&&!e.get("error")||!e.get("state"))||!(!(e=new URLSearchParams(t.hash.replace("#","?"))).get("code")&&!e.get("error")||!e.get("state"))},p=function(t){return function(t){return t instanceof Error?t:new Error("Login failed")}}(),d=function(){var t=n.default.useContext(o);if(!t)throw new Error("AuthProvider context is undefined, please verify you are calling useAuth() as child of a <AuthProvider> component.");return t};exports.AuthContext=o,exports.AuthProvider=function(t){var r=t.children,i=t.onSigninCallback,c=t.skipSigninCallback,d=t.onRemoveUser,v=t.onSignoutRedirect,y=t.onSignoutPopup,g=function(t,e){if(null==t)return{};var r,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e.indexOf(r=i[n])>=0||(o[r]=t[r]);return o}(t,["children","onSigninCallback","skipSigninCallback","onRemoveUser","onSignoutRedirect","onSignoutPopup"]),m=n.default.useState((function(){return new e.UserManager(g)}))[0],w=n.default.useReducer(l,f),x=w[0],E=w[1];n.default.useEffect((function(){a(s.mark((function t(){var e;return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(t.prev=0,!h()||c){t.next=6;break}return t.next=4,m.signinCallback();case 4:e=t.sent,i&&i(e);case 6:return t.next=8,m.getUser();case 8:E({type:"INITIALISED",user:t.sent}),t.next=15;break;case 12:t.prev=12,t.t0=t.catch(0),E({type:"ERROR",error:p(t.t0)});case 15:case"end":return t.stop()}}),t,null,[[0,12]])})))()}),[m,c,i]),n.default.useEffect((function(){var t=function(t){E({type:"USER_LOADED",user:t})};m.events.addUserLoaded(t);var e=function(){E({type:"USER_UNLOADED"})};m.events.addUserUnloaded(e);var r=function(t){E({type:"ERROR",error:t})};return m.events.addSilentRenewError(r),function(){m.events.removeUserLoaded(t),m.events.removeUserUnloaded(e),m.events.removeSilentRenewError(r)}}),[m]);var b=n.default.useCallback(a(s.mark((function t(){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m.removeUser();case 2:d&&d();case 3:case"end":return t.stop()}}),t)}))),[m,d]),L=n.default.useCallback(function(){var t=a(s.mark((function t(e){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m.signoutRedirect(e);case 2:v&&v();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[m,v]),S=n.default.useCallback(function(){var t=a(s.mark((function t(e){return s.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,m.signoutPopup(e);case 2:y&&y();case 3:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}(),[m,y]);return n.default.createElement(o.Provider,{value:u({},x,{settings:m.settings,clearStaleState:m.clearStaleState.bind(m),removeUser:b,signinPopup:m.signinPopup.bind(m),signinSilent:m.signinSilent.bind(m),signinRedirect:m.signinRedirect.bind(m),signoutRedirect:L,signoutPopup:S,querySessionStatus:m.querySessionStatus.bind(m),revokeAccessToken:m.revokeAccessToken.bind(m),startSilentRenew:m.startSilentRenew.bind(m),stopSilentRenew:m.stopSilentRenew.bind(m)})},r)},exports.hasAuthParams=h,exports.loginError=p,exports.useAuth=d,exports.withAuth=function(t){var e=function(e){var r=d();return n.default.createElement(t,u({},e,r))};return e.displayName="withAuth("+(t.displayName||t.name)+")",e};
//# sourceMappingURL=react-oidc-context.cjs.production.min.js.map

@@ -76,6 +76,16 @@ import React from 'react';

function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
function createCommonjsModule(fn, basedir, module) {
return module = {
path: basedir,
exports: {},
require: function (path, base) {
return commonjsRequire();
}
}, fn(module, module.exports), module.exports;
}
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
}
var runtime_1 = createCommonjsModule(function (module) {

@@ -812,3 +822,3 @@ /**

// the regeneratorRuntime variable at the top of this file.
module.exports
module.exports
));

@@ -868,9 +878,22 @@

var hasAuthParams = function hasAuthParams(locationSearch) {
if (locationSearch === void 0) {
locationSearch = window.location.search;
var hasAuthParams = function hasAuthParams(location) {
if (location === void 0) {
location = window.location;
}
var searchParams = new URLSearchParams(locationSearch);
return Boolean((searchParams.get("code") || searchParams.get("error")) && searchParams.get("state"));
// response_mode: query
var searchParams = new URLSearchParams(location.search);
if ((searchParams.get("code") || searchParams.get("error")) && searchParams.get("state")) {
return true;
} // response_mode: fragment
searchParams = new URLSearchParams(location.hash.replace("#", "?"));
if ((searchParams.get("code") || searchParams.get("error")) && searchParams.get("state")) {
return true;
}
return false;
};

@@ -913,3 +936,3 @@

React.useEffect(function () {
_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
void _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
var _user, user;

@@ -967,26 +990,7 @@

// event UserLoaded (e.g. initial load, silent renew success)
var handleUserLoaded = function handleUserLoaded() {
_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
var user;
return runtime_1.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return userManager.getUser();
case 2:
user = _context2.sent;
dispatch({
type: "USER_LOADED",
user: user
});
case 4:
case "end":
return _context2.stop();
}
}
}, _callee2);
}))();
var handleUserLoaded = function handleUserLoaded(user) {
dispatch({
type: "USER_LOADED",
user: user
});
};

@@ -1018,8 +1022,8 @@

}, [userManager]);
var removeUser = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
return runtime_1.wrap(function _callee3$(_context3) {
var removeUser = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2() {
return runtime_1.wrap(function _callee2$(_context2) {
while (1) {
switch (_context3.prev = _context3.next) {
switch (_context2.prev = _context2.next) {
case 0:
_context3.next = 2;
_context2.next = 2;
return userManager.removeUser();

@@ -1032,14 +1036,14 @@

case "end":
return _context3.stop();
return _context2.stop();
}
}
}, _callee3);
}, _callee2);
})), [userManager, onRemoveUser]);
var signoutRedirect = React.useCallback( /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(args) {
return runtime_1.wrap(function _callee4$(_context4) {
var _ref3 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(args) {
return runtime_1.wrap(function _callee3$(_context3) {
while (1) {
switch (_context4.prev = _context4.next) {
switch (_context3.prev = _context3.next) {
case 0:
_context4.next = 2;
_context3.next = 2;
return userManager.signoutRedirect(args);

@@ -1052,19 +1056,19 @@

case "end":
return _context4.stop();
return _context3.stop();
}
}
}, _callee4);
}, _callee3);
}));
return function (_x) {
return _ref4.apply(this, arguments);
return _ref3.apply(this, arguments);
};
}(), [userManager, onSignoutRedirect]);
var signoutPopup = React.useCallback( /*#__PURE__*/function () {
var _ref5 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(args) {
return runtime_1.wrap(function _callee5$(_context5) {
var _ref4 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(args) {
return runtime_1.wrap(function _callee4$(_context4) {
while (1) {
switch (_context5.prev = _context5.next) {
switch (_context4.prev = _context4.next) {
case 0:
_context5.next = 2;
_context4.next = 2;
return userManager.signoutPopup(args);

@@ -1077,10 +1081,10 @@

case "end":
return _context5.stop();
return _context4.stop();
}
}
}, _callee5);
}, _callee4);
}));
return function (_x2) {
return _ref5.apply(this, arguments);
return _ref4.apply(this, arguments);
};

@@ -1125,3 +1129,3 @@ }(), [userManager, onSignoutPopup]);

var auth = useAuth();
return React.createElement(Component, Object.assign({}, props, auth));
return React.createElement(Component, _extends({}, props, auth));
};

@@ -1128,0 +1132,0 @@

@@ -1,5 +0,2 @@

export declare const hasAuthParams: (locationSearch?: string) => boolean;
export declare const loginError: (error: Error | {
error: string;
error_description?: string | undefined;
}) => Error;
export declare const hasAuthParams: (location?: Location) => boolean;
export declare const loginError: (error: unknown) => Error;
{
"name": "react-oidc-context",
"version": "1.0.2",
"version": "1.0.3",
"description": "OpenID Connect & OAuth2 authentication using react context api as state management",

@@ -30,6 +30,7 @@ "repository": {

"test": "tsdx test",
"lint": "tsdx lint"
"lint": "eslint ./src/**/*.ts"
},
"peerDependencies": {
"react": ">=16"
"react": ">=16",
"oidc-client": "^1.11.5"
},

@@ -41,11 +42,16 @@ "dependencies": {

"@testing-library/jest-dom": "^5.5.0",
"@testing-library/react": "^11.2.7",
"@testing-library/react": "^12.0.0",
"@testing-library/react-hooks": "^7.0.0",
"@types/react": "^17.0.5",
"@types/react-dom": "^17.0.5",
"@typescript-eslint/eslint-plugin": "^4.29.0",
"@typescript-eslint/parser": "^4.29.0",
"eslint": "^7.32.0",
"eslint-plugin-testing-library": "^4.10.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-test-renderer": "^17.0.2",
"tsdx": "^0.14.1",
"@weiran.zsd/tsdx": "^0.16.2",
"tslib": "^2.2.0",
"ts-jest": "^27.0.5",
"typescript": "^4.2.4"

@@ -55,3 +61,4 @@ },

"clearMocks": true,
"testURL": "https://www.example.com/"
"testURL": "https://www.example.com/",
"testEnvironment": "jsdom"
},

@@ -58,0 +65,0 @@ "engines": {

@@ -26,3 +26,7 @@ # react-oidc-context

The User and UserManager is hold in this context, which is accessible from the React application. Additionally it intercepts
the auth redirects by looking at the query/fragment parameters and acts accordingly. You still need to setup a redirect uri,
which must point to your application, but you do not need to create that route.
## Installation

@@ -29,0 +33,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc