All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s
2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("immutable"),require("uuid")):"function"==typeof define&&define.amd?define("DecapCmsLibAuth",["immutable","uuid"],t):"object"==typeof exports?exports.DecapCmsLibAuth=t(require("immutable"),require("uuid")):e.DecapCmsLibAuth=t(e.DecapCmsDefaultExports.Immutable,e.DecapCmsDefaultExports.UUId)}(window,((e,t)=>(()=>{var r={857:(e,t,r)=>{var n=r(772).Symbol;e.exports=n},343:e=>{e.exports=function(e,t){for(var r=-1,n=null==e?0:e.length,o=Array(n);++r<n;)o[r]=t(e[r],r,e);return o}},217:e=>{e.exports=function(e){return e.split("")}},359:e=>{e.exports=function(e,t,r,n){for(var o=e.length,i=r+(n?1:-1);n?i--:++i<o;)if(t(e[i],i,e))return i;return-1}},366:(e,t,r)=>{var n=r(857),o=r(107),i=r(157),a=n?n.toStringTag:void 0;e.exports=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":a&&a in Object(e)?o(e):i(e)}},832:(e,t,r)=>{var n=r(359),o=r(195),i=r(24);e.exports=function(e,t,r){return t==t?i(e,t,r):n(e,o,r)}},195:e=>{e.exports=function(e){return e!=e}},872:e=>{e.exports=function(e,t,r){var n=-1,o=e.length;t<0&&(t=-t>o?0:o+t),(r=r>o?o:r)<0&&(r+=o),o=t>r?0:r-t>>>0,t>>>=0;for(var i=Array(o);++n<o;)i[n]=e[n+t];return i}},54:(e,t,r)=>{var n=r(857),o=r(343),i=r(152),a=r(795),s=n?n.prototype:void 0,c=s?s.toString:void 0;e.exports=function e(t){if("string"==typeof t)return t;if(i(t))return o(t,e)+"";if(a(t))return c?c.call(t):"";var r=t+"";return"0"==r&&1/t==-1/0?"-0":r}},704:(e,t,r)=>{var n=r(153),o=/^\s+/;e.exports=function(e){return e?e.slice(0,n(e)+1).replace(o,""):e}},895:(e,t,r)=>{var n=r(872);e.exports=function(e,t,r){var o=e.length;return r=void 0===r?o:r,!t&&r>=o?e:n(e,t,r)}},768:(e,t,r)=>{var n=r(832);e.exports=function(e,t){for(var r=e.length;r--&&n(t,e[r],0)>-1;);return r}},821:(e,t,r)=>{var n=r(832);e.exports=function(e,t){for(var r=-1,o=e.length;++r<o&&n(t,e[r],0)>-1;);return r}},242:(e,t,r)=>{var n="object"==typeof r.g&&r.g&&r.g.Object===Object&&r.g;e.exports=n},107:(e,t,r)=>{var n=r(857),o=Object.prototype,i=o.hasOwnProperty,a=o.toString,s=n?n.toStringTag:void 0;e.exports=function(e){var t=i.call(e,s),r=e[s];try{e[s]=void 0;var n=!0}catch(e){}var o=a.call(e);return n&&(t?e[s]=r:delete e[s]),o}},880:e=>{var t=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");e.exports=function(e){return t.test(e)}},157:e=>{var t=Object.prototype.toString;e.exports=function(e){return t.call(e)}},772:(e,t,r)=>{var n=r(242),o="object"==typeof self&&self&&self.Object===Object&&self,i=n||o||Function("return this")();e.exports=i},24:e=>{e.exports=function(e,t,r){for(var n=r-1,o=e.length;++n<o;)if(e[n]===t)return n;return-1}},435:(e,t,r)=>{var n=r(217),o=r(880),i=r(344);e.exports=function(e){return o(e)?i(e):n(e)}},153:e=>{var t=/\s/;e.exports=function(e){for(var r=e.length;r--&&t.test(e.charAt(r)););return r}},344:e=>{var t="\\ud800-\\udfff",r="["+t+"]",n="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",o="\\ud83c[\\udffb-\\udfff]",i="[^"+t+"]",a="(?:\\ud83c[\\udde6-\\uddff]){2}",s="[\\ud800-\\udbff][\\udc00-\\udfff]",c="(?:"+n+"|"+o+")?",u="[\\ufe0e\\ufe0f]?",p=u+c+"(?:\\u200d(?:"+[i,a,s].join("|")+")"+u+c+")*",h="(?:"+[i+n+"?",n,a,s,r].join("|")+")",l=RegExp(o+"(?="+o+")|"+h+p,"g");e.exports=function(e){return e.match(l)||[]}},152:e=>{var t=Array.isArray;e.exports=t},125:e=>{e.exports=function(e){return null!=e&&"object"==typeof e}},795:(e,t,r)=>{var n=r(366),o=r(125);e.exports=function(e){return"symbol"==typeof e||o(e)&&"[object Symbol]"==n(e)}},188:(e,t,r)=>{var n=r(54);e.exports=function(e){return null==e?"":n(e)}},648:(e,t,r)=>{var n=r(54),o=r(704),i=r(895),a=r(768),s=r(821),c=r(435),u=r(188);e.exports=function(e,t,r){if((e=u(e))&&(r||void 0===t))return o(e);if(!e||!(t=n(t)))return e;var p=c(e),h=c(t),l=s(p,h),f=a(p,h)+1;return i(p,l,f).join("")}},573:(e,t,r)=>{var n=r(54),o=r(895),i=r(768),a=r(435),s=r(188),c=r(153);e.exports=function(e,t,r){if((e=s(e))&&(r||void 0===t))return e.slice(0,c(e)+1);if(!e||!(t=n(t)))return e;var u=a(e),p=i(u,a(t))+1;return o(u,0,p).join("")}},106:t=>{"use strict";t.exports=e},8:e=>{"use strict";e.exports=t}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var i=n[e]={exports:{}};return r[e](i,i.exports,o),i.exports}o.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return o.d(t,{a:t}),t},o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i={};return(()=>{"use strict";o.d(i,{DecapCmsLibAuth:()=>v});var e=o(648),t=o.n(e),r=o(573),n=o.n(r);class a{constructor(e){this.err=e}toString(){return this.err&&this.err.message}}const s={github:{width:960,height:600},gitlab:{width:960,height:600},bitbucket:{width:960,height:500},email:{width:500,height:400}};var c=o(106),u=o(8);function p(){const e=(0,u.v4)();return window.sessionStorage.setItem("decap-cms-auth",JSON.stringify({nonce:e})),e}function h(e){const t=window.sessionStorage.getItem("decap-cms-auth"),r=t&&JSON.parse(t).nonce;return window.localStorage.removeItem("decap-cms-auth"),e===r}function l(){return"https:"!==document.location.protocol&&"localhost"!==document.location.hostname&&"127.0.0.1"!==document.location.hostname}const f=["access_token"];function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function m(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}const g="decap-cms-pkce-verifier-code";const v={NetlifyAuthenticator:class{constructor(e={}){this.site_id=e.site_id||null,this.base_url=n()(e.base_url,"/")||"https://api.netlify.com",this.auth_endpoint=t()(e.auth_endpoint,"/")||"auth"}handshakeCallback(e,t){const r=n=>{if(n.data==="authorizing:"+e.provider&&n.origin===this.base_url)return window.removeEventListener("message",r,!1),window.addEventListener("message",this.authorizeCallback(e,t),!1),this.authWindow.postMessage(n.data,n.origin)};return r}authorizeCallback(e,t){const r=n=>{if(n.origin===this.base_url){if(0===n.data.indexOf("authorization:"+e.provider+":success:")){const o=JSON.parse(n.data.match(new RegExp("^authorization:"+e.provider+":success:(.+)$"))[1]);window.removeEventListener("message",r,!1),this.authWindow.close(),t(null,o)}if(0===n.data.indexOf("authorization:"+e.provider+":error:")){const o=JSON.parse(n.data.match(new RegExp("^authorization:"+e.provider+":error:(.+)$"))[1]);window.removeEventListener("message",r,!1),this.authWindow.close(),t(new a(o))}}};return r}getSiteID(){if(this.site_id)return this.site_id;const e=document.location.host.split(":")[0];return"localhost"===e?"demo.decapcms.org":e}authenticate(e,t){const{provider:r}=e,n=this.getSiteID();if(!r)return t(new a({message:"You must specify a provider when calling netlify.authenticate"}));if(!n)return t(new a({message:"You must set a site_id with netlify.configure({site_id: 'your-site-id'}) to make authentication work from localhost"}));const o=s[r]||s.github,i=screen.width/2-o.width/2,c=screen.height/2-o.height/2;window.addEventListener("message",this.handshakeCallback(e,t),!1);let u=`${this.base_url}/${this.auth_endpoint}?provider=${e.provider}&site_id=${n}`;e.scope&&(u+="&scope="+e.scope),!0===e.login&&(u+="&login=true"),e.beta_invite&&(u+="&beta_invite="+e.beta_invite),e.invite_code&&(u+="&invite_code="+e.invite_code),this.authWindow=window.open(u,"Netlify Authorization",`width=${o.width}, height=${o.height}, top=${c}, left=${i}`),this.authWindow.focus()}refresh(e,t){const{provider:r,refresh_token:n}=e,o=this.getSiteID(),i=t||Promise.reject.bind(Promise);if(!r||!n)return i(new a({message:"You must specify a provider and refresh token when calling netlify.refresh"}));if(!o)return i(new a({message:"You must set a site_id with netlify.configure({site_id: 'your-site-id'}) to make token refresh work from localhost"}));const s=`${this.base_url}/${this.auth_endpoint}/refresh?provider=${r}&site_id=${o}&refresh_token=${n}`,c=fetch(s,{method:"POST",body:""}).then((e=>e.json()));if(!t)return c;c.then((e=>t(null,e))).catch(t)}},ImplicitAuthenticator:class{constructor(e={}){const r=n()(e.base_url,"/"),o=t()(e.auth_endpoint,"/");this.auth_url=`${r}/${o}`,this.appID=e.app_id,this.clearHash=e.clearHash}authenticate(e,t){if(l())return t(new Error("Cannot authenticate over insecure protocol!"));const r=new URL(this.auth_url);r.searchParams.set("client_id",this.appID),r.searchParams.set("redirect_uri",document.location.origin+document.location.pathname),r.searchParams.set("response_type","token"),r.searchParams.set("scope",e.scope),null!=e.prompt&&null!=e.prompt&&r.searchParams.set("prompt",e.prompt),null!=e.resource&&null!=e.resource&&r.searchParams.set("resource",e.resource);const n=JSON.stringify({auth_type:"implicit",nonce:p()});r.searchParams.set("state",n),document.location.assign(r.href)}completeAuth(e){const t=new URLSearchParams(document.location.hash.replace(/^#?\/?/,""));if(!t.has("access_token")&&!t.has("error"))return;this.clearHash();const r=(0,c.Map)(t.entries()),{nonce:n}=JSON.parse(r.get("state"));if(!h(n))return e(new Error("Invalid nonce"));if(r.has("error"))return e(new Error(`${r.get("error")}: ${r.get("error_description")}`));if(r.has("access_token")){const t=r.toJS(),{access_token:n}=t;e(null,function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){var n,o,i;n=e,o=t,i=r[t],(o=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}(o))in n?Object.defineProperty(n,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[o]=i})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({token:n},function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(t,f)))}}},PkceAuthenticator:class{constructor(e={}){const r=n()(e.base_url,"/"),o=t()(e.auth_endpoint,"/"),i=t()(e.auth_token_endpoint,"/");this.auth_url=`${r}/${o}`,this.auth_token_url=`${r}/${i}`,this.auth_token_endpoint_content_type=e.auth_token_endpoint_content_type,this.appID=e.app_id}async authenticate(e,t){if(l())return t(new Error("Cannot authenticate over insecure protocol!"));const r=new URL(this.auth_url);r.searchParams.set("client_id",this.appID),r.searchParams.set("redirect_uri",document.location.origin+document.location.pathname),r.searchParams.set("response_type","code"),r.searchParams.set("scope",e.scope);const n=JSON.stringify({auth_type:"pkce",nonce:p()});r.searchParams.set("state",n),r.searchParams.set("code_challenge_method","S256");const o=function(){const e=Array.from(window.crypto.getRandomValues(new Uint8Array(128))).map((e=>"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-."[e%64])).join("");return window.sessionStorage.setItem(g,e),e}(),i=await async function(e){const t=await async function(e){const t=(new TextEncoder).encode(e),r=await window.crypto.subtle.digest("SHA-256",t);return String.fromCharCode(...new Uint8Array(r))}(e);return btoa(t).split("=")[0].replace(/\+/g,"-").replace(/\//g,"_")}(o);r.searchParams.set("code_challenge",i),document.location.assign(r.href)}async completeAuth(e){const t=new URLSearchParams(document.location.search);if(window.history.replaceState(null,"",document.location.pathname),!t.has("code")&&!t.has("error"))return;let r;try{r=JSON.parse(t.get("state")).nonce}catch(e){r=JSON.parse(t.get("state").replace(/\\"/g,'"')).nonce}if(!h(r))return e(new Error("Invalid nonce"));if(t.has("error"))return e(new Error(`${t.get("error")}: ${t.get("error_description")}`));if(t.has("code")){const r=t.get("code"),n=new URL(this.auth_token_url),o={client_id:this.appID,code:r,grant_type:"authorization_code",redirect_uri:document.location.origin+document.location.pathname,code_verifier:window.sessionStorage.getItem(g)},i=await fetch(n.href,{method:"POST",body:this.auth_token_endpoint_content_type.startsWith("application/x-www-form-urlencoded")?new URLSearchParams(Object.entries(o)).toString():JSON.stringify(o),headers:{"Content-Type":this.auth_token_endpoint_content_type}}),a=await i.json();window.sessionStorage.removeItem(g),e(null,function(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?m(Object(r),!0).forEach((function(t){var n,o,i;n=e,o=t,i=r[t],(o=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==typeof t?t:String(t)}(o))in n?Object.defineProperty(n,o,{value:i,enumerable:!0,configurable:!0,writable:!0}):n[o]=i})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):m(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}({token:a.access_token},a))}}}}})(),i.DecapCmsLibAuth})()));
|
|
//# sourceMappingURL=decap-cms-lib-auth.js.map
|