Socket
Socket
Sign inDemoInstall

react-oauth-flow

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-oauth-flow - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

examples/oauth-dropbox/package.json

24

dist/react-oauth-flow.cjs.js

@@ -644,3 +644,5 @@ 'use strict';

if (res.status < 200 || res.status > 299) {
throw new Error(res.statusText);
var err = new Error(res.statusText);
err.response = res;
throw err;
}

@@ -829,8 +831,9 @@

var _parseQuerystring = _this2.parseQuerystring(),
error = _parseQuerystring.error,
error_description = _parseQuerystring.error_description,
code = _parseQuerystring.code,
state = _parseQuerystring.state;
var queryResult = _this2.parseQuerystring();
var error = queryResult.error,
error_description = queryResult.error_description,
code = queryResult.code;
var state = JSON.parse(queryResult.state);
_this2.setState(function () {

@@ -904,3 +907,3 @@ return { state: state };

return lib.parse(search);
return lib.parse(search, { ignoreQueryPrefix: true });
};

@@ -931,9 +934,8 @@ };

var url = buildURL('' + authorizeUrl, {
var url = buildURL('' + authorizeUrl, _extends({
client_id: clientId,
redirect_uri: redirectUri,
response_type: 'code',
state: state || {},
args: args || {}
});
state: state ? JSON.stringify(state) : undefined
}, args || {}));

@@ -940,0 +942,0 @@ if (component != null) {

@@ -638,3 +638,5 @@ import { Children, Component, createElement } from 'react';

if (res.status < 200 || res.status > 299) {
throw new Error(res.statusText);
var err = new Error(res.statusText);
err.response = res;
throw err;
}

@@ -823,8 +825,9 @@

var _parseQuerystring = _this2.parseQuerystring(),
error = _parseQuerystring.error,
error_description = _parseQuerystring.error_description,
code = _parseQuerystring.code,
state = _parseQuerystring.state;
var queryResult = _this2.parseQuerystring();
var error = queryResult.error,
error_description = queryResult.error_description,
code = queryResult.code;
var state = JSON.parse(queryResult.state);
_this2.setState(function () {

@@ -898,3 +901,3 @@ return { state: state };

return lib.parse(search);
return lib.parse(search, { ignoreQueryPrefix: true });
};

@@ -925,9 +928,8 @@ };

var url = buildURL('' + authorizeUrl, {
var url = buildURL('' + authorizeUrl, _extends({
client_id: clientId,
redirect_uri: redirectUri,
response_type: 'code',
state: state || {},
args: args || {}
});
state: state ? JSON.stringify(state) : undefined
}, args || {}));

@@ -934,0 +936,0 @@ if (component != null) {

@@ -643,3 +643,5 @@ (function (global, factory) {

if (res.status < 200 || res.status > 299) {
throw new Error(res.statusText);
var err = new Error(res.statusText);
err.response = res;
throw err;
}

@@ -828,8 +830,9 @@

var _parseQuerystring = _this2.parseQuerystring(),
error = _parseQuerystring.error,
error_description = _parseQuerystring.error_description,
code = _parseQuerystring.code,
state = _parseQuerystring.state;
var queryResult = _this2.parseQuerystring();
var error = queryResult.error,
error_description = queryResult.error_description,
code = queryResult.code;
var state = JSON.parse(queryResult.state);
_this2.setState(function () {

@@ -903,3 +906,3 @@ return { state: state };

return lib.parse(search);
return lib.parse(search, { ignoreQueryPrefix: true });
};

@@ -930,9 +933,8 @@ };

var url = buildURL('' + authorizeUrl, {
var url = buildURL('' + authorizeUrl, _extends({
client_id: clientId,
redirect_uri: redirectUri,
response_type: 'code',
state: state || {},
args: args || {}
});
state: state ? JSON.stringify(state) : undefined
}, args || {}));

@@ -939,0 +941,0 @@ if (component != null) {

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

!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],r):r(e.ReactOauthFlow={},e.React,e.PropTypes)}(this,function(e,r,t){"use strict";function n(e,r,t){if(null==r)return e;var n=void 0;return(n=null!=t?t(r):h.stringify(r))?e+(e.indexOf("?")<0?"?":"&")+n:e}t=t&&t.hasOwnProperty("default")?t.default:t;var o=function(e,r){return r={exports:{}},e(r,r.exports),r.exports}(function(e,r){var t=Object.prototype.hasOwnProperty,n=function(){for(var e=[],r=0;r<256;++r)e.push("%"+((r<16?"0":"")+r.toString(16)).toUpperCase());return e}();r.arrayToObject=function(e,r){for(var t=r&&r.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(t[n]=e[n]);return t},r.merge=function(e,n,o){if(!n)return e;if("object"!=typeof n){if(Array.isArray(e))e.push(n);else{if("object"!=typeof e)return[e,n];(o.plainObjects||o.allowPrototypes||!t.call(Object.prototype,n))&&(e[n]=!0)}return e}if("object"!=typeof e)return[e].concat(n);var i=e;return Array.isArray(e)&&!Array.isArray(n)&&(i=r.arrayToObject(e,o)),Array.isArray(e)&&Array.isArray(n)?(n.forEach(function(n,i){t.call(e,i)?e[i]&&"object"==typeof e[i]?e[i]=r.merge(e[i],n,o):e.push(n):e[i]=n}),e):Object.keys(n).reduce(function(e,i){var c=n[i];return t.call(e,i)?e[i]=r.merge(e[i],c,o):e[i]=c,e},i)},r.assign=function(e,r){return Object.keys(r).reduce(function(e,t){return e[t]=r[t],e},e)},r.decode=function(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(r){return e}},r.encode=function(e){if(0===e.length)return e;for(var r="string"==typeof e?e:String(e),t="",o=0;o<r.length;++o){var i=r.charCodeAt(o);45===i||46===i||95===i||126===i||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122?t+=r.charAt(o):i<128?t+=n[i]:i<2048?t+=n[192|i>>6]+n[128|63&i]:i<55296||i>=57344?t+=n[224|i>>12]+n[128|i>>6&63]+n[128|63&i]:(o+=1,i=65536+((1023&i)<<10|1023&r.charCodeAt(o)),t+=n[240|i>>18]+n[128|i>>12&63]+n[128|i>>6&63]+n[128|63&i])}return t},r.compact=function(e){for(var r=[{obj:{o:e},prop:"o"}],t=[],n=0;n<r.length;++n)for(var o=r[n],i=o.obj[o.prop],c=Object.keys(i),a=0;a<c.length;++a){var l=c[a],u=i[l];"object"==typeof u&&null!==u&&-1===t.indexOf(u)&&(r.push({obj:i,prop:l}),t.push(u))}return function(e){for(var r;e.length;){var t=e.pop();if(r=t.obj[t.prop],Array.isArray(r)){for(var n=[],o=0;o<r.length;++o)void 0!==r[o]&&n.push(r[o]);t.obj[t.prop]=n}}return r}(r)},r.isRegExp=function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},r.isBuffer=function(e){return null!==e&&void 0!==e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))}}),i=(o.arrayToObject,o.merge,o.assign,o.decode,o.encode,o.compact,o.isRegExp,o.isBuffer,String.prototype.replace),c=/%20/g,a={default:"RFC3986",formatters:{RFC1738:function(e){return i.call(e,c,"+")},RFC3986:function(e){return e}},RFC1738:"RFC1738",RFC3986:"RFC3986"},l={brackets:function(e){return e+"[]"},indices:function(e,r){return e+"["+r+"]"},repeat:function(e){return e}},u=Date.prototype.toISOString,s={delimiter:"&",encode:!0,encoder:o.encode,encodeValuesOnly:!1,serializeDate:function(e){return u.call(e)},skipNulls:!1,strictNullHandling:!1},p=function e(r,t,n,i,c,a,l,u,p,f,d,y){var h=r;if("function"==typeof l)h=l(t,h);else if(h instanceof Date)h=f(h);else if(null===h){if(i)return a&&!y?a(t,s.encoder):t;h=""}if("string"==typeof h||"number"==typeof h||"boolean"==typeof h||o.isBuffer(h)){if(a){return[d(y?t:a(t,s.encoder))+"="+d(a(h,s.encoder))]}return[d(t)+"="+d(String(h))]}var g=[];if(void 0===h)return g;var b;if(Array.isArray(l))b=l;else{var m=Object.keys(h);b=u?m.sort(u):m}for(var v=0;v<b.length;++v){var O=b[v];c&&null===h[O]||(g=Array.isArray(h)?g.concat(e(h[O],n(t,O),n,i,c,a,l,u,p,f,d,y)):g.concat(e(h[O],t+(p?"."+O:"["+O+"]"),n,i,c,a,l,u,p,f,d,y)))}return g},f=Object.prototype.hasOwnProperty,d={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:o.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},y=function(e,r,t){if(e){var n=t.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,o=/(\[[^[\]]*])/g,i=/(\[[^[\]]*])/.exec(n),c=i?n.slice(0,i.index):n,a=[];if(c){if(!t.plainObjects&&f.call(Object.prototype,c)&&!t.allowPrototypes)return;a.push(c)}for(var l=0;null!==(i=o.exec(n))&&l<t.depth;){if(l+=1,!t.plainObjects&&f.call(Object.prototype,i[1].slice(1,-1))&&!t.allowPrototypes)return;a.push(i[1])}return i&&a.push("["+n.slice(i.index)+"]"),function(e,r,t){for(var n=r,o=e.length-1;o>=0;--o){var i,c=e[o];if("[]"===c)i=(i=[]).concat(n);else{i=t.plainObjects?Object.create(null):{};var a="["===c.charAt(0)&&"]"===c.charAt(c.length-1)?c.slice(1,-1):c,l=parseInt(a,10);!isNaN(l)&&c!==a&&String(l)===a&&l>=0&&t.parseArrays&&l<=t.arrayLimit?(i=[])[l]=n:i[a]=n}n=i}return n}(a,r,t)}},h={formats:a,parse:function(e,r){var t=r?o.assign({},r):{};if(null!==t.decoder&&void 0!==t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(t.ignoreQueryPrefix=!0===t.ignoreQueryPrefix,t.delimiter="string"==typeof t.delimiter||o.isRegExp(t.delimiter)?t.delimiter:d.delimiter,t.depth="number"==typeof t.depth?t.depth:d.depth,t.arrayLimit="number"==typeof t.arrayLimit?t.arrayLimit:d.arrayLimit,t.parseArrays=!1!==t.parseArrays,t.decoder="function"==typeof t.decoder?t.decoder:d.decoder,t.allowDots="boolean"==typeof t.allowDots?t.allowDots:d.allowDots,t.plainObjects="boolean"==typeof t.plainObjects?t.plainObjects:d.plainObjects,t.allowPrototypes="boolean"==typeof t.allowPrototypes?t.allowPrototypes:d.allowPrototypes,t.parameterLimit="number"==typeof t.parameterLimit?t.parameterLimit:d.parameterLimit,t.strictNullHandling="boolean"==typeof t.strictNullHandling?t.strictNullHandling:d.strictNullHandling,""===e||null===e||void 0===e)return t.plainObjects?Object.create(null):{};for(var n="string"==typeof e?function(e,r){for(var t={},n=r.ignoreQueryPrefix?e.replace(/^\?/,""):e,o=r.parameterLimit===1/0?void 0:r.parameterLimit,i=n.split(r.delimiter,o),c=0;c<i.length;++c){var a,l,u=i[c],s=u.indexOf("]="),p=-1===s?u.indexOf("="):s+1;-1===p?(a=r.decoder(u,d.decoder),l=r.strictNullHandling?null:""):(a=r.decoder(u.slice(0,p),d.decoder),l=r.decoder(u.slice(p+1),d.decoder)),f.call(t,a)?t[a]=[].concat(t[a]).concat(l):t[a]=l}return t}(e,t):e,i=t.plainObjects?Object.create(null):{},c=Object.keys(n),a=0;a<c.length;++a){var l=c[a],u=y(l,n[l],t);i=o.merge(i,u,t)}return o.compact(i)},stringify:function(e,r){var t=e,n=r?o.assign({},r):{};if(null!==n.encoder&&void 0!==n.encoder&&"function"!=typeof n.encoder)throw new TypeError("Encoder has to be a function.");var i=void 0===n.delimiter?s.delimiter:n.delimiter,c="boolean"==typeof n.strictNullHandling?n.strictNullHandling:s.strictNullHandling,u="boolean"==typeof n.skipNulls?n.skipNulls:s.skipNulls,f="boolean"==typeof n.encode?n.encode:s.encode,d="function"==typeof n.encoder?n.encoder:s.encoder,y="function"==typeof n.sort?n.sort:null,h=void 0!==n.allowDots&&n.allowDots,g="function"==typeof n.serializeDate?n.serializeDate:s.serializeDate,b="boolean"==typeof n.encodeValuesOnly?n.encodeValuesOnly:s.encodeValuesOnly;if(void 0===n.format)n.format=a.default;else if(!Object.prototype.hasOwnProperty.call(a.formatters,n.format))throw new TypeError("Unknown format option provided.");var m,v,O=a.formatters[n.format];"function"==typeof n.filter?t=(v=n.filter)("",t):Array.isArray(n.filter)&&(m=v=n.filter);var j=[];if("object"!=typeof t||null===t)return"";var w;w=n.arrayFormat in l?n.arrayFormat:"indices"in n?n.indices?"indices":"repeat":"indices";var A=l[w];m||(m=Object.keys(t)),y&&m.sort(y);for(var P=0;P<m.length;++P){var R=m[P];u&&null===t[R]||(j=j.concat(p(t[R],R,A,c,u,f?d:null,v,y,h,g,O,b)))}var x=j.join(i),E=!0===n.addQueryPrefix?"?":"";return x.length>0?E+x:""}},g=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},b=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),m=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},v=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)},O=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r},j=function(e){function t(){var e,r,n,o;g(this,t);for(var i=arguments.length,c=Array(i),a=0;a<i;a++)c[a]=arguments[a];return r=n=O(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(c))),w.call(n),o=r,O(n,o)}return v(t,e),b(t,[{key:"componentDidMount",value:function(){this.getAuthorizationCode()}},{key:"render",value:function(){var e=this.props,t=e.component,n=e.render,o=e.children,i=this.state,c=i.processing,a=i.state,l=i.error;return null!=t?r.createElement(t,{processing:c,state:a,error:l}):null!=n?n({processing:c,state:a,error:l}):null!=o?(r.Children.only(o),o({processing:c,state:a,error:l})):null}}]),t}(r.Component);j.propTypes={tokenUrl:t.string.isRequired,clientId:t.string.isRequired,clientSecret:t.string.isRequired,redirectUri:t.string.isRequired,args:t.objectOf(t.oneOfType([t.string,t.number,t.bool,t.object])),location:t.shape({search:t.string.isRequired}),querystring:t.string,onAuthSuccess:t.func,onAuthError:t.func,render:t.func,component:t.element,children:t.func},j.defaultProps={args:{},location:null,querystring:null,onAuthSuccess:null,onAuthError:null,render:null,component:null,children:null};var w=function(){var e=this;this.state={processing:!0,state:null,error:null},this.getAuthorizationCode=function(){try{var r=e.props,t=r.tokenUrl,o=r.clientId,i=r.clientSecret,c=r.redirectUri,a=r.args,l=r.onAuthSuccess,u=e.parseQuerystring(),s=u.error,p=u.error_description,f=u.code,d=u.state;if(e.setState(function(){return{state:d}}),null!=s){throw new Error(p)}(function(e,r){return window.fetch(e,r).then(function(e){if(e.status<200||e.status>299)throw new Error(e.statusText);return e.json()})})(n(""+t,m({code:f,grant_type:"authorization_code",client_id:o,client_secret:i,redirect_uri:c},a)),{method:"POST"}).then(function(r){var t=r.access_token;"function"==typeof l&&l(t,{response:r,state:d}),e.setState(function(){return{processing:!1}})}).catch(function(r){e.handleError(r),e.setState(function(){return{processing:!1}})})}catch(s){e.handleError(s),e.setState(function(){return{processing:!1}})}},this.handleError=function(r){var t=e.props.onAuthError;e.setState(function(){return{error:r}}),"function"==typeof t&&t(r)},this.parseQuerystring=function(){var r=e.props,t=r.location,n=r.querystring,o=void 0;return o=null!=t?t.search:null!=n?n:window.location.search,h.parse(o)}},A=function(e){function t(){return g(this,t),O(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return v(t,e),b(t,[{key:"render",value:function(){var e=this.props,t=e.authorizeUrl,o=e.clientId,i=e.redirectUri,c=e.state,a=e.args,l=e.render,u=e.component,s=e.children,p=n(""+t,{client_id:o,redirect_uri:i,response_type:"code",state:c||{},args:a||{}});return null!=u?r.createElement(u,{url:p}):null!=l?l({url:p}):null!=s?(r.Children.only(s),s({url:p})):null}}]),t}(r.Component);A.propTypes={authorizeUrl:t.string.isRequired,clientId:t.string.isRequired,redirectUri:t.string.isRequired,state:t.objectOf(t.oneOfType([t.string,t.number,t.bool,t.object])),args:t.objectOf(t.oneOfType([t.string,t.number,t.bool,t.object])),render:t.func,component:t.element,children:t.func},A.defaultProps={state:null,args:null,render:null,component:null,children:null},e.createOauthFlow=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.authorizeUrl,n=e.tokenUrl,o=e.clientId,i=e.clientSecret,c=e.redirectUri;return{Sender:function(e){return r.createElement(A,m({authorizeUrl:t,clientId:o,redirectUri:c},e))},Receiver:function(e){return r.createElement(j,m({tokenUrl:n,clientId:o,clientSecret:i,redirectUri:c},e))}}},e.OauthSender=A,e.OauthReceiver=j,Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],r):r(e.ReactOauthFlow={},e.React,e.PropTypes)}(this,function(e,r,t){"use strict";function n(e,r,t){if(null==r)return e;var n=void 0;return(n=null!=t?t(r):h.stringify(r))?e+(e.indexOf("?")<0?"?":"&")+n:e}t=t&&t.hasOwnProperty("default")?t.default:t;var o=function(e,r){return r={exports:{}},e(r,r.exports),r.exports}(function(e,r){var t=Object.prototype.hasOwnProperty,n=function(){for(var e=[],r=0;r<256;++r)e.push("%"+((r<16?"0":"")+r.toString(16)).toUpperCase());return e}();r.arrayToObject=function(e,r){for(var t=r&&r.plainObjects?Object.create(null):{},n=0;n<e.length;++n)void 0!==e[n]&&(t[n]=e[n]);return t},r.merge=function(e,n,o){if(!n)return e;if("object"!=typeof n){if(Array.isArray(e))e.push(n);else{if("object"!=typeof e)return[e,n];(o.plainObjects||o.allowPrototypes||!t.call(Object.prototype,n))&&(e[n]=!0)}return e}if("object"!=typeof e)return[e].concat(n);var i=e;return Array.isArray(e)&&!Array.isArray(n)&&(i=r.arrayToObject(e,o)),Array.isArray(e)&&Array.isArray(n)?(n.forEach(function(n,i){t.call(e,i)?e[i]&&"object"==typeof e[i]?e[i]=r.merge(e[i],n,o):e.push(n):e[i]=n}),e):Object.keys(n).reduce(function(e,i){var c=n[i];return t.call(e,i)?e[i]=r.merge(e[i],c,o):e[i]=c,e},i)},r.assign=function(e,r){return Object.keys(r).reduce(function(e,t){return e[t]=r[t],e},e)},r.decode=function(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch(r){return e}},r.encode=function(e){if(0===e.length)return e;for(var r="string"==typeof e?e:String(e),t="",o=0;o<r.length;++o){var i=r.charCodeAt(o);45===i||46===i||95===i||126===i||i>=48&&i<=57||i>=65&&i<=90||i>=97&&i<=122?t+=r.charAt(o):i<128?t+=n[i]:i<2048?t+=n[192|i>>6]+n[128|63&i]:i<55296||i>=57344?t+=n[224|i>>12]+n[128|i>>6&63]+n[128|63&i]:(o+=1,i=65536+((1023&i)<<10|1023&r.charCodeAt(o)),t+=n[240|i>>18]+n[128|i>>12&63]+n[128|i>>6&63]+n[128|63&i])}return t},r.compact=function(e){for(var r=[{obj:{o:e},prop:"o"}],t=[],n=0;n<r.length;++n)for(var o=r[n],i=o.obj[o.prop],c=Object.keys(i),a=0;a<c.length;++a){var l=c[a],u=i[l];"object"==typeof u&&null!==u&&-1===t.indexOf(u)&&(r.push({obj:i,prop:l}),t.push(u))}return function(e){for(var r;e.length;){var t=e.pop();if(r=t.obj[t.prop],Array.isArray(r)){for(var n=[],o=0;o<r.length;++o)void 0!==r[o]&&n.push(r[o]);t.obj[t.prop]=n}}return r}(r)},r.isRegExp=function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},r.isBuffer=function(e){return null!==e&&void 0!==e&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))}}),i=(o.arrayToObject,o.merge,o.assign,o.decode,o.encode,o.compact,o.isRegExp,o.isBuffer,String.prototype.replace),c=/%20/g,a={default:"RFC3986",formatters:{RFC1738:function(e){return i.call(e,c,"+")},RFC3986:function(e){return e}},RFC1738:"RFC1738",RFC3986:"RFC3986"},l={brackets:function(e){return e+"[]"},indices:function(e,r){return e+"["+r+"]"},repeat:function(e){return e}},u=Date.prototype.toISOString,s={delimiter:"&",encode:!0,encoder:o.encode,encodeValuesOnly:!1,serializeDate:function(e){return u.call(e)},skipNulls:!1,strictNullHandling:!1},p=function e(r,t,n,i,c,a,l,u,p,f,d,y){var h=r;if("function"==typeof l)h=l(t,h);else if(h instanceof Date)h=f(h);else if(null===h){if(i)return a&&!y?a(t,s.encoder):t;h=""}if("string"==typeof h||"number"==typeof h||"boolean"==typeof h||o.isBuffer(h)){if(a){return[d(y?t:a(t,s.encoder))+"="+d(a(h,s.encoder))]}return[d(t)+"="+d(String(h))]}var g=[];if(void 0===h)return g;var b;if(Array.isArray(l))b=l;else{var v=Object.keys(h);b=u?v.sort(u):v}for(var m=0;m<b.length;++m){var O=b[m];c&&null===h[O]||(g=Array.isArray(h)?g.concat(e(h[O],n(t,O),n,i,c,a,l,u,p,f,d,y)):g.concat(e(h[O],t+(p?"."+O:"["+O+"]"),n,i,c,a,l,u,p,f,d,y)))}return g},f=Object.prototype.hasOwnProperty,d={allowDots:!1,allowPrototypes:!1,arrayLimit:20,decoder:o.decode,delimiter:"&",depth:5,parameterLimit:1e3,plainObjects:!1,strictNullHandling:!1},y=function(e,r,t){if(e){var n=t.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,o=/(\[[^[\]]*])/g,i=/(\[[^[\]]*])/.exec(n),c=i?n.slice(0,i.index):n,a=[];if(c){if(!t.plainObjects&&f.call(Object.prototype,c)&&!t.allowPrototypes)return;a.push(c)}for(var l=0;null!==(i=o.exec(n))&&l<t.depth;){if(l+=1,!t.plainObjects&&f.call(Object.prototype,i[1].slice(1,-1))&&!t.allowPrototypes)return;a.push(i[1])}return i&&a.push("["+n.slice(i.index)+"]"),function(e,r,t){for(var n=r,o=e.length-1;o>=0;--o){var i,c=e[o];if("[]"===c)i=(i=[]).concat(n);else{i=t.plainObjects?Object.create(null):{};var a="["===c.charAt(0)&&"]"===c.charAt(c.length-1)?c.slice(1,-1):c,l=parseInt(a,10);!isNaN(l)&&c!==a&&String(l)===a&&l>=0&&t.parseArrays&&l<=t.arrayLimit?(i=[])[l]=n:i[a]=n}n=i}return n}(a,r,t)}},h={formats:a,parse:function(e,r){var t=r?o.assign({},r):{};if(null!==t.decoder&&void 0!==t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(t.ignoreQueryPrefix=!0===t.ignoreQueryPrefix,t.delimiter="string"==typeof t.delimiter||o.isRegExp(t.delimiter)?t.delimiter:d.delimiter,t.depth="number"==typeof t.depth?t.depth:d.depth,t.arrayLimit="number"==typeof t.arrayLimit?t.arrayLimit:d.arrayLimit,t.parseArrays=!1!==t.parseArrays,t.decoder="function"==typeof t.decoder?t.decoder:d.decoder,t.allowDots="boolean"==typeof t.allowDots?t.allowDots:d.allowDots,t.plainObjects="boolean"==typeof t.plainObjects?t.plainObjects:d.plainObjects,t.allowPrototypes="boolean"==typeof t.allowPrototypes?t.allowPrototypes:d.allowPrototypes,t.parameterLimit="number"==typeof t.parameterLimit?t.parameterLimit:d.parameterLimit,t.strictNullHandling="boolean"==typeof t.strictNullHandling?t.strictNullHandling:d.strictNullHandling,""===e||null===e||void 0===e)return t.plainObjects?Object.create(null):{};for(var n="string"==typeof e?function(e,r){for(var t={},n=r.ignoreQueryPrefix?e.replace(/^\?/,""):e,o=r.parameterLimit===1/0?void 0:r.parameterLimit,i=n.split(r.delimiter,o),c=0;c<i.length;++c){var a,l,u=i[c],s=u.indexOf("]="),p=-1===s?u.indexOf("="):s+1;-1===p?(a=r.decoder(u,d.decoder),l=r.strictNullHandling?null:""):(a=r.decoder(u.slice(0,p),d.decoder),l=r.decoder(u.slice(p+1),d.decoder)),f.call(t,a)?t[a]=[].concat(t[a]).concat(l):t[a]=l}return t}(e,t):e,i=t.plainObjects?Object.create(null):{},c=Object.keys(n),a=0;a<c.length;++a){var l=c[a],u=y(l,n[l],t);i=o.merge(i,u,t)}return o.compact(i)},stringify:function(e,r){var t=e,n=r?o.assign({},r):{};if(null!==n.encoder&&void 0!==n.encoder&&"function"!=typeof n.encoder)throw new TypeError("Encoder has to be a function.");var i=void 0===n.delimiter?s.delimiter:n.delimiter,c="boolean"==typeof n.strictNullHandling?n.strictNullHandling:s.strictNullHandling,u="boolean"==typeof n.skipNulls?n.skipNulls:s.skipNulls,f="boolean"==typeof n.encode?n.encode:s.encode,d="function"==typeof n.encoder?n.encoder:s.encoder,y="function"==typeof n.sort?n.sort:null,h=void 0!==n.allowDots&&n.allowDots,g="function"==typeof n.serializeDate?n.serializeDate:s.serializeDate,b="boolean"==typeof n.encodeValuesOnly?n.encodeValuesOnly:s.encodeValuesOnly;if(void 0===n.format)n.format=a.default;else if(!Object.prototype.hasOwnProperty.call(a.formatters,n.format))throw new TypeError("Unknown format option provided.");var v,m,O=a.formatters[n.format];"function"==typeof n.filter?t=(m=n.filter)("",t):Array.isArray(n.filter)&&(v=m=n.filter);var j=[];if("object"!=typeof t||null===t)return"";var w;w=n.arrayFormat in l?n.arrayFormat:"indices"in n?n.indices?"indices":"repeat":"indices";var A=l[w];v||(v=Object.keys(t)),y&&v.sort(y);for(var P=0;P<v.length;++P){var S=v[P];u&&null===t[S]||(j=j.concat(p(t[S],S,A,c,u,f?d:null,m,y,h,g,O,b)))}var x=j.join(i),R=!0===n.addQueryPrefix?"?":"";return x.length>0?R+x:""}},g=function(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")},b=function(){function e(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(r,t,n){return t&&e(r.prototype,t),n&&e(r,n),r}}(),v=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},m=function(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function, not "+typeof r);e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),r&&(Object.setPrototypeOf?Object.setPrototypeOf(e,r):e.__proto__=r)},O=function(e,r){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!r||"object"!=typeof r&&"function"!=typeof r?e:r},j=function(e){function t(){var e,r,n,o;g(this,t);for(var i=arguments.length,c=Array(i),a=0;a<i;a++)c[a]=arguments[a];return r=n=O(this,(e=t.__proto__||Object.getPrototypeOf(t)).call.apply(e,[this].concat(c))),w.call(n),o=r,O(n,o)}return m(t,e),b(t,[{key:"componentDidMount",value:function(){this.getAuthorizationCode()}},{key:"render",value:function(){var e=this.props,t=e.component,n=e.render,o=e.children,i=this.state,c=i.processing,a=i.state,l=i.error;return null!=t?r.createElement(t,{processing:c,state:a,error:l}):null!=n?n({processing:c,state:a,error:l}):null!=o?(r.Children.only(o),o({processing:c,state:a,error:l})):null}}]),t}(r.Component);j.propTypes={tokenUrl:t.string.isRequired,clientId:t.string.isRequired,clientSecret:t.string.isRequired,redirectUri:t.string.isRequired,args:t.objectOf(t.oneOfType([t.string,t.number,t.bool,t.object])),location:t.shape({search:t.string.isRequired}),querystring:t.string,onAuthSuccess:t.func,onAuthError:t.func,render:t.func,component:t.element,children:t.func},j.defaultProps={args:{},location:null,querystring:null,onAuthSuccess:null,onAuthError:null,render:null,component:null,children:null};var w=function(){var e=this;this.state={processing:!0,state:null,error:null},this.getAuthorizationCode=function(){try{var r=e.props,t=r.tokenUrl,o=r.clientId,i=r.clientSecret,c=r.redirectUri,a=r.args,l=r.onAuthSuccess,u=e.parseQuerystring(),s=u.error,p=u.error_description,f=u.code,d=JSON.parse(u.state);if(e.setState(function(){return{state:d}}),null!=s){throw new Error(p)}(function(e,r){return window.fetch(e,r).then(function(e){if(e.status<200||e.status>299){var r=new Error(e.statusText);throw r.response=e,r}return e.json()})})(n(""+t,v({code:f,grant_type:"authorization_code",client_id:o,client_secret:i,redirect_uri:c},a)),{method:"POST"}).then(function(r){var t=r.access_token;"function"==typeof l&&l(t,{response:r,state:d}),e.setState(function(){return{processing:!1}})}).catch(function(r){e.handleError(r),e.setState(function(){return{processing:!1}})})}catch(s){e.handleError(s),e.setState(function(){return{processing:!1}})}},this.handleError=function(r){var t=e.props.onAuthError;e.setState(function(){return{error:r}}),"function"==typeof t&&t(r)},this.parseQuerystring=function(){var r=e.props,t=r.location,n=r.querystring,o=void 0;return o=null!=t?t.search:null!=n?n:window.location.search,h.parse(o,{ignoreQueryPrefix:!0})}},A=function(e){function t(){return g(this,t),O(this,(t.__proto__||Object.getPrototypeOf(t)).apply(this,arguments))}return m(t,e),b(t,[{key:"render",value:function(){var e=this.props,t=e.authorizeUrl,o=e.clientId,i=e.redirectUri,c=e.state,a=e.args,l=e.render,u=e.component,s=e.children,p=n(""+t,v({client_id:o,redirect_uri:i,response_type:"code",state:c?JSON.stringify(c):void 0},a||{}));return null!=u?r.createElement(u,{url:p}):null!=l?l({url:p}):null!=s?(r.Children.only(s),s({url:p})):null}}]),t}(r.Component);A.propTypes={authorizeUrl:t.string.isRequired,clientId:t.string.isRequired,redirectUri:t.string.isRequired,state:t.objectOf(t.oneOfType([t.string,t.number,t.bool,t.object])),args:t.objectOf(t.oneOfType([t.string,t.number,t.bool,t.object])),render:t.func,component:t.element,children:t.func},A.defaultProps={state:null,args:null,render:null,component:null,children:null},e.createOauthFlow=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=e.authorizeUrl,n=e.tokenUrl,o=e.clientId,i=e.clientSecret,c=e.redirectUri;return{Sender:function(e){return r.createElement(A,v({authorizeUrl:t,clientId:o,redirectUri:c},e))},Receiver:function(e){return r.createElement(j,v({tokenUrl:n,clientId:o,clientSecret:i,redirectUri:c},e))}}},e.OauthSender=A,e.OauthReceiver=j,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=react-oauth-flow.umd.min.js.map

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

{"name":"react-oauth-flow","version":"1.0.0","main":"dist/react-oauth-flow.cjs.js","jsnext:main":"dist/react-oauth-flow.esm.js","module":"dist/react-oauth-flow.esm.js","repository":"git@github.com:adambrgmn/react-oauth-flow.git","author":"Adam Bergman <adam@fransvilhelm.com>","license":"MIT","scripts":{"build":"frans-scripts build --bundle","test":"frans-scripts test","lint":"frans-scripts lint","format":"frans-scripts format","validate":"frans-scripts validate","add-contributor":"frans-scripts contributors add","precommit":"frans-scripts precommit","travis-after-success":"frans-scripts travis-after-success"},"devDependencies":{"cz-conventional-changelog":"^2.1.0","enzyme":"^3.2.0","enzyme-adapter-react-16":"^1.1.0","frans-scripts":"^1.0.1","prop-types":"^15.6.0","react":"^16.1.1","react-dom":"^16.1.1"},"dependencies":{"qs":"^6.5.1"},"peerDependencies":{"prop-types":">=15","react":">=15"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}}}
{"name":"react-oauth-flow","version":"1.0.1","main":"dist/react-oauth-flow.cjs.js","jsnext:main":"dist/react-oauth-flow.esm.js","module":"dist/react-oauth-flow.esm.js","repository":"git@github.com:adambrgmn/react-oauth-flow.git","author":"Adam Bergman <adam@fransvilhelm.com>","license":"MIT","scripts":{"build":"frans-scripts build --bundle","test":"frans-scripts test","lint":"frans-scripts lint","format":"frans-scripts format","validate":"frans-scripts validate","add-contributor":"frans-scripts contributors add","precommit":"frans-scripts precommit","travis-after-success":"frans-scripts travis-after-success"},"devDependencies":{"cz-conventional-changelog":"^2.1.0","enzyme":"^3.2.0","enzyme-adapter-react-16":"^1.1.0","frans-scripts":"^1.0.1","prop-types":"^15.6.0","react":"^16.1.1","react-dom":"^16.1.1"},"dependencies":{"qs":"^6.5.1"},"peerDependencies":{"prop-types":">=15","react":">=15"},"config":{"commitizen":{"path":"./node_modules/cz-conventional-changelog"}}}

@@ -266,11 +266,10 @@ # React OAuth Flow

| Arg | Type | Required | Default | Description |
| :-------------------------- | :------- | :------- | :------------------ | :------------------------------------------------------------------------- |
| `options` | `object` | yes | - | Options object |
| `options.authorizeUrl` | `string` | yes | - | The full url to the authorize endpoint, provided by the service |
| `options.tokenUrl` | `string` | yes | - | The full url to the token endpoint, provided by the service |
| `options.clientId` | `string` | yes | - | Your client id from the service provider (remember to keep it secret!) |
| `options.clientSecret` | `string` | yes | - | Your client secret from the service provider (remember to keep it secret!) |
| `options.authorizeEndpoint` | `string` | no | `/oauth2/authorize` | Endpoint to send users to authorize |
| `options.tokenEndpoint` | `string` | no | `/oauth2/token` | Endpoint to send token request to |
| Arg | Type | Required | Default | Description |
| :--------------------- | :------- | :------- | :------ | :------------------------------------------------------------------------- |
| `options` | `object` | yes | - | Options object |
| `options.authorizeUrl` | `string` | yes | - | The full url to the authorize endpoint, provided by the service |
| `options.tokenUrl` | `string` | yes | - | The full url to the token endpoint, provided by the service |
| `options.clientId` | `string` | yes | - | Your client id from the service provider (remember to keep it secret!) |
| `options.clientSecret` | `string` | yes | - | Your client secret from the service provider (remember to keep it secret!) |
| `options.redirectUri` | `string` | yes | - | The URL where the provider should redirect your users back |

@@ -277,0 +276,0 @@ ## License

@@ -63,3 +63,5 @@ // @flow

const { error, error_description, code, state } = this.parseQuerystring();
const queryResult = this.parseQuerystring();
const { error, error_description, code } = queryResult;
const state = JSON.parse(queryResult.state);
this.setState(() => ({ state }));

@@ -122,3 +124,3 @@

return qs.parse(search);
return qs.parse(search, { ignoreQueryPrefix: true });
};

@@ -125,0 +127,0 @@

@@ -33,3 +33,3 @@ import React from 'react';

code: 'abc',
state: { from: '/settings' },
state: JSON.stringify({ from: '/settings' }),
})}`,

@@ -36,0 +36,0 @@ onAuthSuccess,

@@ -56,4 +56,4 @@ // @flow

response_type: 'code',
state: state || {},
args: args || {},
state: state ? JSON.stringify(state) : undefined,
...(args || {}),
});

@@ -60,0 +60,0 @@

export function fetch(url, opts) {
return window.fetch(url, opts).then(res => {
if (res.status < 200 || res.status > 299) {
throw new Error(res.statusText);
const err = new Error(res.statusText);
err.response = res;
throw err;
}

@@ -6,0 +8,0 @@

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc