From a791e9f475b72c8df777599ba67de54f0798657e Mon Sep 17 00:00:00 2001 From: Malo Skrylevo Date: Thu, 21 Dec 2017 00:15:35 +0300 Subject: [PATCH] Added decode from a non-url-compatible strings returned from OAuth authentication procedure. Added condition to allow skipping code presence validation on success result. --- README.md | 10 ++++++++-- dist/GitHubLogin.js | 2 +- src/GitHubLogin.js | 3 ++- src/PopupWindow.js | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8beb317..894acda 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,12 @@ CSS class for the login button. Text content for the login button. +#### `requireCode` + +`{boolean}` + +Allow skiping 'code' key presence validation on success result, to skip pass 'false' value. + #### `onRequest` `{function}` @@ -63,13 +69,13 @@ Callback for every request. #### `onSuccess` -`{function}` +`{function}` _required_ Callback for successful login. An object will be passed as an argument to the callback, e.g. `{ "code": "..." }`. #### `onFailure` -`{function}` +`{function}` _required_ Callback for errors raised during login. diff --git a/dist/GitHubLogin.js b/dist/GitHubLogin.js index 13bdaac..6a995ee 100644 --- a/dist/GitHubLogin.js +++ b/dist/GitHubLogin.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.GitHubLogin=t(require("react")):e.GitHubLogin=t(e.react)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(e,t,n){"use strict";function r(e){return e.replace(/^\??\//,"").split("&").reduce(function(e,t){var n=t.split("="),r=i(n,2),o=r[0],u=r[1];return e[o]=u,e},{})}function o(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"&",n=Object.keys(e);return n.reduce(function(r,o,i){var u=""+r+o+"="+e[o];return i2&&void 0!==arguments[2]?arguments[2]:{};r(this,e),this.id=t,this.url=n,this.options=o}return o(e,[{key:"open",value:function(){var e=this.url,t=this.id,n=this.options;this.window=window.open(e,t,(0,i.toQuery)(n,","))}},{key:"close",value:function(){this.cancel(),this.window.close()}},{key:"poll",value:function(){var e=this;this.promise=new Promise(function(t,n){e._iid=window.setInterval(function(){try{var r=e.window;if(!r||!1!==r.closed)return e.close(),void n(new Error("The popup was closed"));if(r.location.href===e.url||"blank"===r.location.pathname)return;var o=(0,i.toParams)(r.location.search.replace(/^\?/,""));t(o),e.close()}catch(e){}},500)})}},{key:"cancel",value:function(){this._iid&&(window.clearInterval(this._iid),this._iid=null)}},{key:"then",value:function(){var e;return(e=this.promise).then.apply(e,arguments)}},{key:"catch",value:function(){var e;return(e=this.promise).then.apply(e,arguments)}}],[{key:"open",value:function(){for(var e=arguments.length,t=Array(e),n=0;n1&&void 0!==arguments[1]?arguments[1]:"&",n=Object.keys(e);return n.reduce(function(r,o,i){var u=""+r+o+"="+e[o];return i2&&void 0!==arguments[2]?arguments[2]:{};r(this,e),this.id=t,this.url=n,this.options=o}return o(e,[{key:"open",value:function(){var e=this.url,t=this.id,n=this.options;this.window=window.open(e,t,(0,i.toQuery)(n,","))}},{key:"close",value:function(){this.cancel(),this.window.close()}},{key:"poll",value:function(){var e=this;this.promise=new Promise(function(t,n){e._iid=window.setInterval(function(){try{var r=e.window;if(!r||!1!==r.closed)return e.close(),void n(new Error("The popup was closed"));if(r.location.href===e.url||"blank"===r.location.pathname)return;var o=(0,i.toParams)(decodeURIComponent(r.location.search.replace(/^\?/,"")));t(o),e.close()}catch(e){}},500)})}},{key:"cancel",value:function(){this._iid&&(window.clearInterval(this._iid),this._iid=null)}},{key:"then",value:function(){var e;return(e=this.promise).then.apply(e,arguments)}},{key:"catch",value:function(){var e;return(e=this.promise).then.apply(e,arguments)}}],[{key:"open",value:function(){for(var e=arguments.length,t=Array(e),n=0;n {}, onSuccess: () => {}, onFailure: () => {}, @@ -50,7 +51,7 @@ class GitHubLogin extends Component { } onSuccess = (data) => { - if (!data.code) { + if (this.props.requireCode && !data.code) { return this.onFailure(new Error('\'code\' not found')); } diff --git a/src/PopupWindow.js b/src/PopupWindow.js index 621f72b..53645b3 100644 --- a/src/PopupWindow.js +++ b/src/PopupWindow.js @@ -36,7 +36,7 @@ class PopupWindow { return; } - const params = toParams(popup.location.search.replace(/^\?/, '')); + const params = toParams(decodeURIComponent(popup.location.search.replace(/^\?/, ''))); resolve(params);