react-oauth-flow
Advanced tools
Comparing version 1.1.2 to 1.2.0
@@ -1,2 +0,2 @@ | ||
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=e(require("qs")),t=require("react"),n=e(require("prop-types")),o=function(e,r,t){return Object.defineProperty(e,r,{enumerable:!1,configurable:!1,writable:!1,value:t}),e};function i(e,t){if(null==t)return e;var n=r.stringify(t);return n?e+(e.indexOf("?")<0?"?":"&")+n:e}var s=function(e){function n(r){e.call(this,r),this.state={processing:!0,state:null,error:null},this.getAuthorizationCode=this.getAuthorizationCode.bind(this),this.handleError=this.handleError.bind(this),this.parseQuerystring=this.parseQuerystring.bind(this)}return e&&(n.__proto__=e),(n.prototype=Object.create(e&&e.prototype)).constructor=n,n.prototype.componentDidMount=function(){this.getAuthorizationCode()},n.prototype.getAuthorizationCode=function(){var e=this;try{var r=this.props,t=r.tokenUrl,n=r.tokenFetchArgs,s=r.clientId,c=r.clientSecret,u=r.redirectUri,l=r.args,a=r.onAuthSuccess,p=this.parseQuerystring(),h=p.error,d=p.error_description,f=p.code,g=JSON.parse(p.state||null);if(g&&this.setState(function(){return{state:g}}),null!=h)throw new Error(d);var y=i(""+t,Object.assign({},{code:f,grant_type:"authorization_code",client_id:s,client_secret:c,redirect_uri:u},l)),b=new Headers({"Content-Type":"application/json"});(function(e,r){var t=fetch(e,r);return t.then(function(e){if(!e.ok)throw e;return e.json()}).catch(function(e){return e.json().then(function(r){var n=new Error(e.statusText);throw o(n,"response",e),o(n.response,"data",r),o(n,"request",t),n})})})(y,Object.assign({method:"POST",headers:b},n)).then(function(r){"function"==typeof a&&a(r.access_token,{response:r,state:g}),e.setState(function(){return{processing:!1}})}).catch(function(r){e.handleError(r),e.setState(function(){return{processing:!1}})})}catch(e){this.handleError(e),this.setState(function(){return{processing:!1}})}},n.prototype.handleError=function(e){var r=this.props.onAuthError;this.setState(function(){return{error:e}}),"function"==typeof r&&r(e)},n.prototype.parseQuerystring=function(){var e,t=this.props,n=t.location,o=t.querystring;return e=null!=n?n.search:null!=o?o:window.location.search,r.parse(e,{ignoreQueryPrefix:!0})},n.prototype.render=function(){var e=this.props,r=e.component,n=e.render,o=e.children,i=this.state,s=i.processing,c=i.state,u=i.error;return null!=r?t.createElement(r,{processing:s,state:c,error:u}):null!=n?n({processing:s,state:c,error:u}):null!=o?(t.Children.only(o),o({processing:s,state:c,error:u})):null},n}(t.Component);s.propTypes={tokenUrl:n.string.isRequired,clientId:n.string.isRequired,clientSecret:n.string.isRequired,redirectUri:n.string.isRequired,args:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),location:n.shape({search:n.string.isRequired}),querystring:n.string,onAuthSuccess:n.func,onAuthError:n.func,render:n.func,tokenFetchArgs:n.shape({method:n.string}),component:n.element,children:n.func},s.defaultProps={args:{},location:null,querystring:null,onAuthSuccess:null,onAuthError:null,render:null,tokenFetchArgs:{},component:null,children:null};var c=function(e){function r(){e.apply(this,arguments)}return e&&(r.__proto__=e),(r.prototype=Object.create(e&&e.prototype)).constructor=r,r.prototype.render=function(){var e=this.props,r=e.state,n=e.args,o=e.render,s=e.component,c=e.children,u=i(""+e.authorizeUrl,Object.assign({},{client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",state:r?JSON.stringify(r):void 0},n||{}));return null!=s?t.createElement(s,{url:u}):null!=o?o({url:u}):null!=c?(t.Children.only(c),c({url:u})):null},r}(t.Component);c.propTypes={authorizeUrl:n.string.isRequired,clientId:n.string.isRequired,redirectUri:n.string.isRequired,state:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),args:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),render:n.func,component:n.element,children:n.func},c.defaultProps={state:null,args:null,render:null,component:null,children:null},exports.createOauthFlow=function(e){void 0===e&&(e={});var r=e.authorizeUrl,t=e.tokenUrl,n=e.clientId,o=e.clientSecret,i=e.redirectUri,u=e.appName;return{Sender:function(e){return h(c,Object.assign({},{authorizeUrl:r,clientId:n,redirectUri:i},e))},Receiver:function(e){return h(s,Object.assign({},{tokenUrl:t,clientId:n,clientSecret:o,redirectUri:i,appName:u},e))}}},exports.OauthSender=c,exports.OauthReceiver=s; | ||
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var r=e(require("qs")),t=require("react"),n=e(require("prop-types")),o=function(e,r,t){return Object.defineProperty(e,r,{enumerable:!1,configurable:!1,writable:!1,value:t}),e};function i(e,t){if(null==t)return e;var n=r.stringify(t);return n?e+(e.indexOf("?")<0?"?":"&")+n:e}var s=function(e){function n(r){e.call(this,r),this.state={processing:!0,state:null,error:null},this.getAuthorizationCode=this.getAuthorizationCode.bind(this),this.handleError=this.handleError.bind(this),this.parseQuerystring=this.parseQuerystring.bind(this)}return e&&(n.__proto__=e),(n.prototype=Object.create(e&&e.prototype)).constructor=n,n.prototype.componentDidMount=function(){this.getAuthorizationCode()},n.prototype.getAuthorizationCode=function(){var e=this;try{var r=this.props,t=r.tokenUrl,n=r.tokenFetchArgs,s=r.clientId,c=r.clientSecret,u=r.redirectUri,l=r.args,a=r.tokenFn,p=r.onAuthSuccess,h=this.parseQuerystring(),d=h.error,f=h.error_description,g=h.code,y=JSON.parse(h.state||null);if(y&&this.setState(function(){return{state:y}}),null!=d)throw new Error(f);var b=i(""+t,Object.assign({},{code:g,grant_type:"authorization_code",client_id:s,client_secret:c,redirect_uri:u},l)),m=new Headers({"Content-Type":"application/json"}),O=Object.assign({method:"POST",headers:m},n);("function"==typeof a?a(b,O):function(e,r){var t=fetch(e,r);return t.then(function(e){if(!e.ok)throw e;return e.json()}).catch(function(e){return e.json().then(function(r){var n=new Error(e.statusText);throw o(n,"response",e),o(n.response,"data",r),o(n,"request",t),n})})}(b,O)).then(function(r){"function"==typeof p&&p(r.access_token,{response:r,state:y}),e.setState(function(){return{processing:!1}})}).catch(function(r){e.handleError(r),e.setState(function(){return{processing:!1}})})}catch(e){this.handleError(e),this.setState(function(){return{processing:!1}})}},n.prototype.handleError=function(e){var r=this.props.onAuthError;this.setState(function(){return{error:e}}),"function"==typeof r&&r(e)},n.prototype.parseQuerystring=function(){var e,t=this.props,n=t.location,o=t.querystring;return e=null!=n?n.search:null!=o?o:window.location.search,r.parse(e,{ignoreQueryPrefix:!0})},n.prototype.render=function(){var e=this.props,r=e.component,n=e.render,o=e.children,i=this.state,s=i.processing,c=i.state,u=i.error;return null!=r?t.createElement(r,{processing:s,state:c,error:u}):null!=n?n({processing:s,state:c,error:u}):null!=o?(t.Children.only(o),o({processing:s,state:c,error:u})):null},n}(t.Component);s.propTypes={tokenUrl:n.string.isRequired,clientId:n.string.isRequired,clientSecret:n.string.isRequired,redirectUri:n.string.isRequired,args:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),location:n.shape({search:n.string.isRequired}),querystring:n.string,tokenFn:n.func,onAuthSuccess:n.func,onAuthError:n.func,render:n.func,tokenFetchArgs:n.shape({method:n.string}),component:n.element,children:n.func},s.defaultProps={args:{},location:null,querystring:null,tokenFn:null,onAuthSuccess:null,onAuthError:null,render:null,tokenFetchArgs:{},component:null,children:null};var c=function(e){function r(){e.apply(this,arguments)}return e&&(r.__proto__=e),(r.prototype=Object.create(e&&e.prototype)).constructor=r,r.prototype.render=function(){var e=this.props,r=e.state,n=e.args,o=e.render,s=e.component,c=e.children,u=i(""+e.authorizeUrl,Object.assign({},{client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",state:r?JSON.stringify(r):void 0},n||{}));return null!=s?t.createElement(s,{url:u}):null!=o?o({url:u}):null!=c?(t.Children.only(c),c({url:u})):null},r}(t.Component);c.propTypes={authorizeUrl:n.string.isRequired,clientId:n.string.isRequired,redirectUri:n.string.isRequired,state:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),args:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),render:n.func,component:n.element,children:n.func},c.defaultProps={state:null,args:null,render:null,component:null,children:null},exports.createOauthFlow=function(e){void 0===e&&(e={});var r=e.authorizeUrl,t=e.tokenUrl,n=e.clientId,o=e.clientSecret,i=e.redirectUri,u=e.appName;return{Sender:function(e){return h(c,Object.assign({},{authorizeUrl:r,clientId:n,redirectUri:i},e))},Receiver:function(e){return h(s,Object.assign({},{tokenUrl:t,clientId:n,clientSecret:o,redirectUri:i,appName:u},e))}}},exports.OauthSender=c,exports.OauthReceiver=s; | ||
//# sourceMappingURL=react-oauth-flow.js.map |
@@ -1,2 +0,2 @@ | ||
import r from"qs";import{createElement as e,Children as t,Component as n}from"react";import o from"prop-types";var i=function(r,e,t){return Object.defineProperty(r,e,{enumerable:!1,configurable:!1,writable:!1,value:t}),r};function s(e,t){if(null==t)return e;var n=r.stringify(t);return n?e+(e.indexOf("?")<0?"?":"&")+n:e}var c=function(n){function o(r){n.call(this,r),this.state={processing:!0,state:null,error:null},this.getAuthorizationCode=this.getAuthorizationCode.bind(this),this.handleError=this.handleError.bind(this),this.parseQuerystring=this.parseQuerystring.bind(this)}return n&&(o.__proto__=n),(o.prototype=Object.create(n&&n.prototype)).constructor=o,o.prototype.componentDidMount=function(){this.getAuthorizationCode()},o.prototype.getAuthorizationCode=function(){var r=this;try{var e=this.props,t=e.tokenUrl,n=e.tokenFetchArgs,o=e.clientId,c=e.clientSecret,u=e.redirectUri,l=e.args,a=e.onAuthSuccess,p=this.parseQuerystring(),h=p.error,d=p.error_description,f=p.code,g=JSON.parse(p.state||null);if(g&&this.setState(function(){return{state:g}}),null!=h)throw new Error(d);var y=s(""+t,Object.assign({},{code:f,grant_type:"authorization_code",client_id:o,client_secret:c,redirect_uri:u},l)),b=new Headers({"Content-Type":"application/json"});(function(r,e){var t=fetch(r,e);return t.then(function(r){if(!r.ok)throw r;return r.json()}).catch(function(r){return r.json().then(function(e){var n=new Error(r.statusText);throw i(n,"response",r),i(n.response,"data",e),i(n,"request",t),n})})})(y,Object.assign({method:"POST",headers:b},n)).then(function(e){"function"==typeof a&&a(e.access_token,{response:e,state:g}),r.setState(function(){return{processing:!1}})}).catch(function(e){r.handleError(e),r.setState(function(){return{processing:!1}})})}catch(r){this.handleError(r),this.setState(function(){return{processing:!1}})}},o.prototype.handleError=function(r){var e=this.props.onAuthError;this.setState(function(){return{error:r}}),"function"==typeof e&&e(r)},o.prototype.parseQuerystring=function(){var e,t=this.props,n=t.location,o=t.querystring;return e=null!=n?n.search:null!=o?o:window.location.search,r.parse(e,{ignoreQueryPrefix:!0})},o.prototype.render=function(){var r=this.props,n=r.component,o=r.render,i=r.children,s=this.state,c=s.processing,u=s.state,l=s.error;return null!=n?e(n,{processing:c,state:u,error:l}):null!=o?o({processing:c,state:u,error:l}):null!=i?(t.only(i),i({processing:c,state:u,error:l})):null},o}(n);c.propTypes={tokenUrl:o.string.isRequired,clientId:o.string.isRequired,clientSecret:o.string.isRequired,redirectUri:o.string.isRequired,args:o.objectOf(o.oneOfType([o.string,o.number,o.bool,o.object])),location:o.shape({search:o.string.isRequired}),querystring:o.string,onAuthSuccess:o.func,onAuthError:o.func,render:o.func,tokenFetchArgs:o.shape({method:o.string}),component:o.element,children:o.func},c.defaultProps={args:{},location:null,querystring:null,onAuthSuccess:null,onAuthError:null,render:null,tokenFetchArgs:{},component:null,children:null};var u=function(r){function n(){r.apply(this,arguments)}return r&&(n.__proto__=r),(n.prototype=Object.create(r&&r.prototype)).constructor=n,n.prototype.render=function(){var r=this.props,n=r.state,o=r.args,i=r.render,c=r.component,u=r.children,l=s(""+r.authorizeUrl,Object.assign({},{client_id:r.clientId,redirect_uri:r.redirectUri,response_type:"code",state:n?JSON.stringify(n):void 0},o||{}));return null!=c?e(c,{url:l}):null!=i?i({url:l}):null!=u?(t.only(u),u({url:l})):null},n}(n);function l(r){void 0===r&&(r={});var e=r.authorizeUrl,t=r.tokenUrl,n=r.clientId,o=r.clientSecret,i=r.redirectUri,s=r.appName;return{Sender:function(r){return h(u,Object.assign({},{authorizeUrl:e,clientId:n,redirectUri:i},r))},Receiver:function(r){return h(c,Object.assign({},{tokenUrl:t,clientId:n,clientSecret:o,redirectUri:i,appName:s},r))}}}u.propTypes={authorizeUrl:o.string.isRequired,clientId:o.string.isRequired,redirectUri:o.string.isRequired,state:o.objectOf(o.oneOfType([o.string,o.number,o.bool,o.object])),args:o.objectOf(o.oneOfType([o.string,o.number,o.bool,o.object])),render:o.func,component:o.element,children:o.func},u.defaultProps={state:null,args:null,render:null,component:null,children:null};export{l as createOauthFlow,u as OauthSender,c as OauthReceiver}; | ||
import e from"qs";import{createElement as r,Children as t,Component as n}from"react";import o from"prop-types";var i=function(e,r,t){return Object.defineProperty(e,r,{enumerable:!1,configurable:!1,writable:!1,value:t}),e};function s(r,t){if(null==t)return r;var n=e.stringify(t);return n?r+(r.indexOf("?")<0?"?":"&")+n:r}var c=function(n){function o(e){n.call(this,e),this.state={processing:!0,state:null,error:null},this.getAuthorizationCode=this.getAuthorizationCode.bind(this),this.handleError=this.handleError.bind(this),this.parseQuerystring=this.parseQuerystring.bind(this)}return n&&(o.__proto__=n),(o.prototype=Object.create(n&&n.prototype)).constructor=o,o.prototype.componentDidMount=function(){this.getAuthorizationCode()},o.prototype.getAuthorizationCode=function(){var e=this;try{var r=this.props,t=r.tokenUrl,n=r.tokenFetchArgs,o=r.clientId,c=r.clientSecret,u=r.redirectUri,l=r.args,a=r.tokenFn,p=r.onAuthSuccess,h=this.parseQuerystring(),d=h.error,f=h.error_description,g=h.code,y=JSON.parse(h.state||null);if(y&&this.setState(function(){return{state:y}}),null!=d)throw new Error(f);var b=s(""+t,Object.assign({},{code:g,grant_type:"authorization_code",client_id:o,client_secret:c,redirect_uri:u},l)),m=new Headers({"Content-Type":"application/json"}),v=Object.assign({method:"POST",headers:m},n);("function"==typeof a?a(b,v):function(e,r){var t=fetch(e,r);return t.then(function(e){if(!e.ok)throw e;return e.json()}).catch(function(e){return e.json().then(function(r){var n=new Error(e.statusText);throw i(n,"response",e),i(n.response,"data",r),i(n,"request",t),n})})}(b,v)).then(function(r){"function"==typeof p&&p(r.access_token,{response:r,state:y}),e.setState(function(){return{processing:!1}})}).catch(function(r){e.handleError(r),e.setState(function(){return{processing:!1}})})}catch(e){this.handleError(e),this.setState(function(){return{processing:!1}})}},o.prototype.handleError=function(e){var r=this.props.onAuthError;this.setState(function(){return{error:e}}),"function"==typeof r&&r(e)},o.prototype.parseQuerystring=function(){var r,t=this.props,n=t.location,o=t.querystring;return r=null!=n?n.search:null!=o?o:window.location.search,e.parse(r,{ignoreQueryPrefix:!0})},o.prototype.render=function(){var e=this.props,n=e.component,o=e.render,i=e.children,s=this.state,c=s.processing,u=s.state,l=s.error;return null!=n?r(n,{processing:c,state:u,error:l}):null!=o?o({processing:c,state:u,error:l}):null!=i?(t.only(i),i({processing:c,state:u,error:l})):null},o}(n);c.propTypes={tokenUrl:o.string.isRequired,clientId:o.string.isRequired,clientSecret:o.string.isRequired,redirectUri:o.string.isRequired,args:o.objectOf(o.oneOfType([o.string,o.number,o.bool,o.object])),location:o.shape({search:o.string.isRequired}),querystring:o.string,tokenFn:o.func,onAuthSuccess:o.func,onAuthError:o.func,render:o.func,tokenFetchArgs:o.shape({method:o.string}),component:o.element,children:o.func},c.defaultProps={args:{},location:null,querystring:null,tokenFn:null,onAuthSuccess:null,onAuthError:null,render:null,tokenFetchArgs:{},component:null,children:null};var u=function(e){function n(){e.apply(this,arguments)}return e&&(n.__proto__=e),(n.prototype=Object.create(e&&e.prototype)).constructor=n,n.prototype.render=function(){var e=this.props,n=e.state,o=e.args,i=e.render,c=e.component,u=e.children,l=s(""+e.authorizeUrl,Object.assign({},{client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",state:n?JSON.stringify(n):void 0},o||{}));return null!=c?r(c,{url:l}):null!=i?i({url:l}):null!=u?(t.only(u),u({url:l})):null},n}(n);function l(e){void 0===e&&(e={});var r=e.authorizeUrl,t=e.tokenUrl,n=e.clientId,o=e.clientSecret,i=e.redirectUri,s=e.appName;return{Sender:function(e){return h(u,Object.assign({},{authorizeUrl:r,clientId:n,redirectUri:i},e))},Receiver:function(e){return h(c,Object.assign({},{tokenUrl:t,clientId:n,clientSecret:o,redirectUri:i,appName:s},e))}}}u.propTypes={authorizeUrl:o.string.isRequired,clientId:o.string.isRequired,redirectUri:o.string.isRequired,state:o.objectOf(o.oneOfType([o.string,o.number,o.bool,o.object])),args:o.objectOf(o.oneOfType([o.string,o.number,o.bool,o.object])),render:o.func,component:o.element,children:o.func},u.defaultProps={state:null,args:null,render:null,component:null,children:null};export{l as createOauthFlow,u as OauthSender,c as OauthReceiver}; | ||
//# sourceMappingURL=react-oauth-flow.m.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("qs"),require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","qs","react","prop-types"],r):r(e.reactOauthFlow={},e.qs,e.react,e.PropTypes)}(this,function(e,r,t,n){r=r&&r.hasOwnProperty("default")?r.default:r,n=n&&n.hasOwnProperty("default")?n.default:n;var o=function(e,r,t){return Object.defineProperty(e,r,{enumerable:!1,configurable:!1,writable:!1,value:t}),e};function i(e,t){if(null==t)return e;var n=r.stringify(t);return n?e+(e.indexOf("?")<0?"?":"&")+n:e}var s=function(e){function n(r){e.call(this,r),this.state={processing:!0,state:null,error:null},this.getAuthorizationCode=this.getAuthorizationCode.bind(this),this.handleError=this.handleError.bind(this),this.parseQuerystring=this.parseQuerystring.bind(this)}return e&&(n.__proto__=e),(n.prototype=Object.create(e&&e.prototype)).constructor=n,n.prototype.componentDidMount=function(){this.getAuthorizationCode()},n.prototype.getAuthorizationCode=function(){var e=this;try{var r=this.props,t=r.tokenUrl,n=r.tokenFetchArgs,s=r.clientId,c=r.clientSecret,u=r.redirectUri,l=r.args,a=r.onAuthSuccess,p=this.parseQuerystring(),d=p.error,h=p.error_description,f=p.code,g=JSON.parse(p.state||null);if(g&&this.setState(function(){return{state:g}}),null!=d)throw new Error(h);var y=i(""+t,Object.assign({},{code:f,grant_type:"authorization_code",client_id:s,client_secret:c,redirect_uri:u},l)),b=new Headers({"Content-Type":"application/json"});(function(e,r){var t=fetch(e,r);return t.then(function(e){if(!e.ok)throw e;return e.json()}).catch(function(e){return e.json().then(function(r){var n=new Error(e.statusText);throw o(n,"response",e),o(n.response,"data",r),o(n,"request",t),n})})})(y,Object.assign({method:"POST",headers:b},n)).then(function(r){"function"==typeof a&&a(r.access_token,{response:r,state:g}),e.setState(function(){return{processing:!1}})}).catch(function(r){e.handleError(r),e.setState(function(){return{processing:!1}})})}catch(e){this.handleError(e),this.setState(function(){return{processing:!1}})}},n.prototype.handleError=function(e){var r=this.props.onAuthError;this.setState(function(){return{error:e}}),"function"==typeof r&&r(e)},n.prototype.parseQuerystring=function(){var e,t=this.props,n=t.location,o=t.querystring;return e=null!=n?n.search:null!=o?o:window.location.search,r.parse(e,{ignoreQueryPrefix:!0})},n.prototype.render=function(){var e=this.props,r=e.component,n=e.render,o=e.children,i=this.state,s=i.processing,c=i.state,u=i.error;return null!=r?t.createElement(r,{processing:s,state:c,error:u}):null!=n?n({processing:s,state:c,error:u}):null!=o?(t.Children.only(o),o({processing:s,state:c,error:u})):null},n}(t.Component);s.propTypes={tokenUrl:n.string.isRequired,clientId:n.string.isRequired,clientSecret:n.string.isRequired,redirectUri:n.string.isRequired,args:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),location:n.shape({search:n.string.isRequired}),querystring:n.string,onAuthSuccess:n.func,onAuthError:n.func,render:n.func,tokenFetchArgs:n.shape({method:n.string}),component:n.element,children:n.func},s.defaultProps={args:{},location:null,querystring:null,onAuthSuccess:null,onAuthError:null,render:null,tokenFetchArgs:{},component:null,children:null};var c=function(e){function r(){e.apply(this,arguments)}return e&&(r.__proto__=e),(r.prototype=Object.create(e&&e.prototype)).constructor=r,r.prototype.render=function(){var e=this.props,r=e.state,n=e.args,o=e.render,s=e.component,c=e.children,u=i(""+e.authorizeUrl,Object.assign({},{client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",state:r?JSON.stringify(r):void 0},n||{}));return null!=s?t.createElement(s,{url:u}):null!=o?o({url:u}):null!=c?(t.Children.only(c),c({url:u})):null},r}(t.Component);c.propTypes={authorizeUrl:n.string.isRequired,clientId:n.string.isRequired,redirectUri:n.string.isRequired,state:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),args:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),render:n.func,component:n.element,children:n.func},c.defaultProps={state:null,args:null,render:null,component:null,children:null},e.createOauthFlow=function(e){void 0===e&&(e={});var r=e.authorizeUrl,t=e.tokenUrl,n=e.clientId,o=e.clientSecret,i=e.redirectUri,u=e.appName;return{Sender:function(e){return h(c,Object.assign({},{authorizeUrl:r,clientId:n,redirectUri:i},e))},Receiver:function(e){return h(s,Object.assign({},{tokenUrl:t,clientId:n,clientSecret:o,redirectUri:i,appName:u},e))}}},e.OauthSender=c,e.OauthReceiver=s}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("qs"),require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","qs","react","prop-types"],t):t(e.reactOauthFlow={},e.qs,e.react,e.PropTypes)}(this,function(e,t,r,n){t=t&&t.hasOwnProperty("default")?t.default:t,n=n&&n.hasOwnProperty("default")?n.default:n;var o=function(e,t,r){return Object.defineProperty(e,t,{enumerable:!1,configurable:!1,writable:!1,value:r}),e};function i(e,r){if(null==r)return e;var n=t.stringify(r);return n?e+(e.indexOf("?")<0?"?":"&")+n:e}var s=function(e){function n(t){e.call(this,t),this.state={processing:!0,state:null,error:null},this.getAuthorizationCode=this.getAuthorizationCode.bind(this),this.handleError=this.handleError.bind(this),this.parseQuerystring=this.parseQuerystring.bind(this)}return e&&(n.__proto__=e),(n.prototype=Object.create(e&&e.prototype)).constructor=n,n.prototype.componentDidMount=function(){this.getAuthorizationCode()},n.prototype.getAuthorizationCode=function(){var e=this;try{var t=this.props,r=t.tokenUrl,n=t.tokenFetchArgs,s=t.clientId,c=t.clientSecret,u=t.redirectUri,l=t.args,a=t.tokenFn,p=t.onAuthSuccess,d=this.parseQuerystring(),h=d.error,f=d.error_description,g=d.code,y=JSON.parse(d.state||null);if(y&&this.setState(function(){return{state:y}}),null!=h)throw new Error(f);var b=i(""+r,Object.assign({},{code:g,grant_type:"authorization_code",client_id:s,client_secret:c,redirect_uri:u},l)),O=new Headers({"Content-Type":"application/json"}),m=Object.assign({method:"POST",headers:O},n);("function"==typeof a?a(b,m):function(e,t){var r=fetch(e,t);return r.then(function(e){if(!e.ok)throw e;return e.json()}).catch(function(e){return e.json().then(function(t){var n=new Error(e.statusText);throw o(n,"response",e),o(n.response,"data",t),o(n,"request",r),n})})}(b,m)).then(function(t){"function"==typeof p&&p(t.access_token,{response:t,state:y}),e.setState(function(){return{processing:!1}})}).catch(function(t){e.handleError(t),e.setState(function(){return{processing:!1}})})}catch(e){this.handleError(e),this.setState(function(){return{processing:!1}})}},n.prototype.handleError=function(e){var t=this.props.onAuthError;this.setState(function(){return{error:e}}),"function"==typeof t&&t(e)},n.prototype.parseQuerystring=function(){var e,r=this.props,n=r.location,o=r.querystring;return e=null!=n?n.search:null!=o?o:window.location.search,t.parse(e,{ignoreQueryPrefix:!0})},n.prototype.render=function(){var e=this.props,t=e.component,n=e.render,o=e.children,i=this.state,s=i.processing,c=i.state,u=i.error;return null!=t?r.createElement(t,{processing:s,state:c,error:u}):null!=n?n({processing:s,state:c,error:u}):null!=o?(r.Children.only(o),o({processing:s,state:c,error:u})):null},n}(r.Component);s.propTypes={tokenUrl:n.string.isRequired,clientId:n.string.isRequired,clientSecret:n.string.isRequired,redirectUri:n.string.isRequired,args:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),location:n.shape({search:n.string.isRequired}),querystring:n.string,tokenFn:n.func,onAuthSuccess:n.func,onAuthError:n.func,render:n.func,tokenFetchArgs:n.shape({method:n.string}),component:n.element,children:n.func},s.defaultProps={args:{},location:null,querystring:null,tokenFn:null,onAuthSuccess:null,onAuthError:null,render:null,tokenFetchArgs:{},component:null,children:null};var c=function(e){function t(){e.apply(this,arguments)}return e&&(t.__proto__=e),(t.prototype=Object.create(e&&e.prototype)).constructor=t,t.prototype.render=function(){var e=this.props,t=e.state,n=e.args,o=e.render,s=e.component,c=e.children,u=i(""+e.authorizeUrl,Object.assign({},{client_id:e.clientId,redirect_uri:e.redirectUri,response_type:"code",state:t?JSON.stringify(t):void 0},n||{}));return null!=s?r.createElement(s,{url:u}):null!=o?o({url:u}):null!=c?(r.Children.only(c),c({url:u})):null},t}(r.Component);c.propTypes={authorizeUrl:n.string.isRequired,clientId:n.string.isRequired,redirectUri:n.string.isRequired,state:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),args:n.objectOf(n.oneOfType([n.string,n.number,n.bool,n.object])),render:n.func,component:n.element,children:n.func},c.defaultProps={state:null,args:null,render:null,component:null,children:null},e.createOauthFlow=function(e){void 0===e&&(e={});var t=e.authorizeUrl,r=e.tokenUrl,n=e.clientId,o=e.clientSecret,i=e.redirectUri,u=e.appName;return{Sender:function(e){return h(c,Object.assign({},{authorizeUrl:t,clientId:n,redirectUri:i},e))},Receiver:function(e){return h(s,Object.assign({},{tokenUrl:r,clientId:n,clientSecret:o,redirectUri:i,appName:u},e))}}},e.OauthSender=c,e.OauthReceiver=s}); | ||
//# sourceMappingURL=react-oauth-flow.umd.js.map |
{ | ||
"name": "react-oauth-flow", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"repository": "git@github.com:adambrgmn/react-oauth-flow.git", | ||
@@ -5,0 +5,0 @@ "author": "Adam Bergman <adam@fransvilhelm.com>", |
@@ -182,3 +182,5 @@ # React OAuth Flow | ||
| `tokenFetchArgs` | `object` | no | `{}` | Used to fetch the token endpoint [(read more below)](#tokenfetchargs) | | ||
| `tokenFn` | `func` | no | `null` | Used to bypass default fetch function to fetch the token [(read more below)](#tokenfn) | | ||
#### Events | ||
@@ -278,2 +280,16 @@ | ||
#### `tokenFn` | ||
The prop `tokenFn` can be used to change how the token is fetched and received from | ||
the service. It's a way to bypass the default fetch all together and use your own. | ||
For example, if your `access-token` comes in the headers instead of the response body | ||
you will have to use your own fetch function to get those. Or perhaps you already | ||
have a custom built fetch function that communicates with your backend and you want | ||
to make use of it. | ||
Your function will receive the `url` from the OauthReceiver, it takes the | ||
`tokenUrl` and builds it up with all the other needed parameters so you don't have to. | ||
It will also receive the `tokenFetchArgs` parameter just in case you need it. if you don't, | ||
just ignore it. | ||
### `createOauthFlow` | ||
@@ -280,0 +296,0 @@ |
@@ -35,2 +35,3 @@ // @flow | ||
args, | ||
tokenFn, | ||
onAuthSuccess, | ||
@@ -64,4 +65,6 @@ } = this.props; | ||
fetch2(url, fetchArgs) | ||
.then(response => { | ||
(typeof tokenFn === 'function' ? | ||
tokenFn(url, fetchArgs) : | ||
fetch2(url, fetchArgs) | ||
).then(response => { | ||
const accessToken = response.access_token; | ||
@@ -145,2 +148,3 @@ | ||
querystring: PropTypes.string, | ||
tokenFn: PropTypes.func, | ||
onAuthSuccess: PropTypes.func, | ||
@@ -160,2 +164,3 @@ onAuthError: PropTypes.func, | ||
querystring: null, | ||
tokenFn: null, | ||
onAuthSuccess: null, | ||
@@ -162,0 +167,0 @@ onAuthError: null, |
@@ -93,2 +93,83 @@ import React from 'react'; | ||
}); | ||
test('with custom fetch function, default args', async () => { | ||
const onAuthSuccess = jest.fn(); | ||
const onAuthError = jest.fn(); | ||
const props = { | ||
tokenUrl: 'https://api.service.com/oauth2/token', | ||
tokenFn: fetch2, | ||
clientId: 'abc', | ||
clientSecret: 'abcdef', | ||
redirectUri: 'https://www.test.com/redirect', | ||
querystring: `?${qs.stringify({ | ||
code: 'abc', | ||
state: JSON.stringify({ from: '/success' }), | ||
})}`, | ||
onAuthSuccess, | ||
onAuthError, | ||
}; | ||
const { getByTestId } = render( | ||
<OauthReceiver | ||
{...props} | ||
render={({ processing, state }) => ( | ||
<div> | ||
{processing && <span data-testid="done">done</span>} | ||
<span data-testid="state">{state && state.from}</span> | ||
</div> | ||
)} | ||
/>, | ||
); | ||
await waitForElement(() => getByTestId('done')); | ||
expect(onAuthSuccess).toHaveBeenCalledTimes(1); | ||
expect(onAuthError).not.toHaveBeenCalled(); | ||
expect(getByTestId('state')).toHaveTextContent('/success'); | ||
}); | ||
test('with custom token function and token uri fetch args', async () => { | ||
fetch2.mockClear(); | ||
const props = { | ||
tokenUrl: 'https://api.service.com/oauth2/token', | ||
tokenFn: fetch2, | ||
tokenFetchArgs: { | ||
cache: 'no-cache', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, | ||
}, | ||
clientId: 'abc', | ||
clientSecret: 'abcdef', | ||
redirectUri: 'https://www.test.com/redirect', | ||
querystring: `?${qs.stringify({ | ||
code: 'abc', | ||
state: JSON.stringify({ from: '/settings' }), | ||
})}`, | ||
}; | ||
const { getByTestId } = render( | ||
<OauthReceiver | ||
{...props} | ||
render={({ processing }) => ( | ||
<div>{processing && <span data-testid="done">done</span>}</div> | ||
)} | ||
/>, | ||
); | ||
await waitForElement(() => getByTestId('done')); | ||
expect(fetch2).toHaveBeenCalledWith( | ||
expect.stringContaining(props.tokenUrl), | ||
expect.objectContaining({ | ||
method: expect.stringMatching('POST'), | ||
cache: expect.stringMatching('no-cache'), | ||
headers: expect.objectContaining({ | ||
'Content-Type': expect.stringMatching( | ||
'application/x-www-form-urlencoded', | ||
), | ||
}), | ||
}), | ||
); | ||
}); | ||
}); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
529055
706
337
4