UNPKG

asteroid-oauth-mixin

Version:
1 lines 7.51 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AsteroidOauthMixin=t():e.AsteroidOauthMixin=t()}(this,function(){return function(e){function t(n){if(o[n])return o[n].exports;var r=o[n]={exports:{},id:n,loaded:!1};return e[n].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var o={};return t.m=e,t.c=o,t.p="",t(0)}([function(e,t,o){"use strict";function n(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t["default"]=e,t}function r(e){return e&&e.__esModule?e:{"default":e}}function i(e){var t=e.endpoint,o=e.platform;this.subscribe("meteor.loginServiceConfiguration"),this.oauth={platform:o,url:l["default"](t)}}function s(e){h[e.name]=e}function u(e,t){var o=this,n=h[e].getOptions({url:this.oauth.url,configCollection:this.getServiceConfig(e),scope:t});return f["default"](this.oauth.platform,this.oauth.url.host,n.credentialToken,n.loginUrl,function(e){return o.login({oauth:e})})}Object.defineProperty(t,"__esModule",{value:!0}),t.init=i,t.registerOauthProvider=s,t.loginWith=u;var a=o(1),l=r(a),c=o(5),f=r(c),p=o(7),d=n(p),h={google:d}},function(e,t,o){"use strict";function n(e,t,o){if(!(this instanceof n))return new n(e,t,o);var l,c,f,p,d=u.test(e),h=typeof t,v=this,g=0;for("object"!==h&&"string"!==h&&(o=t,t=null),o&&"function"!=typeof o&&(o=s.parse),t=i(t);g<a.length;g++)c=a[g],l=c[0],p=c[1],l!==l?v[p]=e:"string"==typeof l?~(f=e.indexOf(l))&&("number"==typeof c[2]?(v[p]=e.slice(0,f),e=e.slice(f+c[2])):(v[p]=e.slice(f),e=e.slice(0,f))):(f=l.exec(e))&&(v[p]=f[1],e=e.slice(0,e.length-f[0].length)),v[p]=v[p]||(c[3]||"port"===p&&d?t[p]||"":""),c[4]&&(v[p]=v[p].toLowerCase());o&&(v.query=o(v.query)),r(v.port,v.protocol)||(v.host=v.hostname,v.port=""),v.username=v.password="",v.auth&&(c=v.auth.split(":"),v.username=c[0]||"",v.password=c[1]||""),v.href=v.toString()}var r=o(2),i=o(3),s=o(4),u=/^\/(?!\/)/,a=[["#","hash"],["?","query"],["//","protocol",2,1,1],["/","pathname"],["@","auth",1],[NaN,"host",void 0,1,1],[/\:(\d+)$/,"port"],[NaN,"hostname",void 0,1,1]];n.prototype.set=function(e,t,o){var n=this;return"query"===e?("string"==typeof t&&t.length&&(t=(o||s.parse)(t)),n[e]=t):"port"===e?(n[e]=t,r(t,n.protocol)?t&&(n.host=n.hostname+":"+t):(n.host=n.hostname,n[e]="")):"hostname"===e?(n[e]=t,n.port&&(t+=":"+n.port),n.host=t):"host"===e?(n[e]=t,/\:\d+/.test(t)&&(t=t.split(":"),n.hostname=t[0],n.port=t[1])):n[e]=t,n.href=n.toString(),n},n.prototype.toString=function(e){e&&"function"==typeof e||(e=s.stringify);var t,o=this,n=o.protocol+"//";return o.username&&(n+=o.username,o.password&&(n+=":"+o.password),n+="@"),n+=o.hostname,o.port&&(n+=":"+o.port),n+=o.pathname,t="object"==typeof o.query?e(o.query):o.query,t&&(n+="?"!==t.charAt(0)?"?"+t:t),o.hash&&(n+=o.hash),n},n.qs=s,n.location=i,e.exports=n},function(e,t){"use strict";e.exports=function(e,t){if(t=t.split(":")[0],e=+e,!e)return!1;switch(t){case"http":case"ws":return 80!==e;case"https":case"wss":return 443!==e;case"ftp":return 22!==e;case"gopher":return 70!==e;case"file":return!1}return 0!==e}},function(e,t,o){(function(t){"use strict";var n,r={hash:1,query:1};e.exports=function(e){e=e||t.location||{},n=n||o(1);var i,s={},u=typeof e;if("blob:"===e.protocol)s=new n(unescape(e.pathname),{});else if("string"===u){s=new n(e,{});for(i in r)delete s[i]}else if("object"===u)for(i in e)i in r||(s[i]=e[i]);return s}}).call(t,function(){return this}())},function(e,t){"use strict";function o(e){for(var t,o=/([^=?&]+)=([^&]*)/g,n={};t=o.exec(e);n[decodeURIComponent(t[1])]=decodeURIComponent(t[2]));return n}function n(e,t){t=t||"";var o=[];"string"!=typeof t&&(t="?");for(var n in e)r.call(e,n)&&o.push(encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return o.length?t+o.join("&"):""}var r=Object.prototype.hasOwnProperty;t.stringify=n,t.parse=o},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(e,t,o,n,r){var i=u[e],s=new i({host:t,credentialToken:o,loginUrl:n});return s.init().then(r)}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=r;var i=o(6),s=n(i),u={browser:s["default"]};e.exports=t["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,o,n){return o&&e(t.prototype,o),n&&e(t,n),t}}(),s=o(1),u=n(s),a=function(){function e(t){var o=this,n=t.credentialToken,i=t.host,s=t.loginUrl;r(this,e),this.credentialToken=n,this.host=i,this.loginUrl=s,this._credentialSecretPromise=new Promise(function(e,t){o._resolvePromise=e,o._rejectPromise=t})}return i(e,[{key:"_startPolling",value:function(){var e=this,t=JSON.stringify({credentialToken:this.credentialToken});this.intervalId=window.setInterval(function(){e.popup.postMessage(t,e.host)},100),window.addEventListener("message",this._onMessage.bind(this))}},{key:"_stopPolling",value:function(){window.clearInterval(this.intervalId)}},{key:"_onMessage",value:function(e){var t=e.data,o=e.origin;try{var n=JSON.parse(t);if(u["default"](o).host!==this.host)return;n.credentialToken===this.credentialToken&&this._resolvePromise({credentialToken:n.credentialToken,credentialSecret:n.credentialSecret}),n.error&&this._rejectPromise(n.error)}catch(r){}}},{key:"_openPopup",value:function(){this.popup=window.open(this.loginUrl,"_blank","location=no,toolbar=no"),this.popup.focus&&this.popup.focus()}},{key:"_closePopup",value:function(){this.popup.close()}},{key:"init",value:function(){var e=this;return this._openPopup(),this._startPolling(),this._credentialSecretPromise.then(function(t){return e._stopPolling(),e._closePopup(),t})}}]),e}();t["default"]=a,e.exports=t["default"]},function(e,t,o){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function r(e){var t=e.url,o=e.configCollection,n=e.scope,r=a["default"](),i=t.protocol,u=t.host,l={response_type:"code",client_id:p["default"](o),redirect_uri:h["default"](i)+("//"+u+"/_oauth/google"),state:c["default"](r),scope:n||"openid email"},f=s["default"]("https://accounts.google.com/o/oauth2/auth").set("query",l).toString();return{credentialToken:r,loginUrl:f}}Object.defineProperty(t,"__esModule",{value:!0}),t.getOptions=r;var i=o(1),s=n(i),u=o(8),a=n(u),l=o(9),c=n(l),f=o(10),p=n(f),d=o(11),h=n(d),v="google";t.name=v},function(e,t){"use strict";function o(){for(var e="",t=0;8>t;t++)e+=Math.floor(65536*(1+Math.random())).toString(16).substring(1);return e}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=o,e.exports=t["default"]},function(e,t){"use strict";function o(e){var t={loginStyle:"popup",credentialToken:e,isCordova:!1};return window.btoa(JSON.stringify(t))}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=o,e.exports=t["default"]},function(e,t){"use strict";function o(e){return e.clientId||e.consumerKey||e.appId}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=o,e.exports=t["default"]},function(e,t){"use strict";function o(e){return"ws:"===e||"http:"===e?"http:":"wss:"===e||"https:"===e?"https:":void 0}Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=o,e.exports=t["default"]}])});