site
Version:
Site Engine is the world's first all-in-one engine to build a modern web site, game, or blog. No HTML or CSS knowledge required.
1 lines • 4.31 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("./shared.manifest"),r=require("url"),n=(e=r)&&e.__esModule?e:{default:e},o=function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}(require("./shared.log"));var i,s,a,l,c,d,u,h,f,y=function(e){return null!=e},p=function(e,t,r,n){return e(t)[r](t,...n)},m=function(e){var t=e.call(this);return new Promise(function(e,r){!function n(o,i){try{var s=t[o](i),a=s.value}catch(e){return void r(e)}s.done?e(a):Promise.resolve(a).then(function(e){n("next",e)},function(e){n("throw",e)})}("next")})};exports.default=(i=Symbol(),s=Symbol(),a=Symbol(),l=Symbol(),c=Symbol(),d=Symbol(),u=Symbol(),h=Symbol(),(f=class{constructor(e){(e=>(()=>{var r,n,o,f,y,m,b,_,w,g,v,O,k,q,T,S,x,R,P,A,F,C;r=e.name,n=e.grantType,o=e.username,f=e.password,y=e.credentialPosition,m=e.tokenUri,b=void 0===(q=e.method)?"POST":q,_=void 0===(T=e.clientIdFieldName)?"client_id":T,w=void 0===(S=e.clientSecretFieldName)?"client_secret":S,(0,t.assert)("string"==typeof r&&1<=(x=r.length)&&x<=100),(0,t.assert)("code"===n),(0,t.assert)("string"==typeof o&&1<=(R=o.length)&&R<=500),(0,t.assert)("string"==typeof f&&1<=(P=f.length)&&P<=500),(0,t.assert)(["header","body","query"].indexOf(y)>=0),(0,t.assert)("string"==typeof m&&1<=(A=m.length)&&A<=2e3&&m.startsWith("https:")),(0,t.assert)(["POST","GET"].indexOf(b)>=0),(0,t.assert)(!("POST"===b&&"query"===y||"GET"===b&&"body"===y)),(0,t.assert)("string"==typeof _&&1<=(F=_.length)&&F<=50),(0,t.assert)("string"==typeof w&&1<=(C=w.length)&&C<=50),(0,t.assert)(_!==w),this[i]=o,this[s]=f,g=encodeURIComponent(o),v=encodeURIComponent(f),O=encodeURIComponent(_),k=encodeURIComponent(w),this[a]="Basic "+p(t.dotDot_573300145710716007,p(t.dotDot_573300145710716007,g+":"+v,"toBytes",[]),"toBase64",[]),this[l]=O+"="+g+"&"+k+"="+v,this[c]=r,this[d]=b,this[u]=m,this[h]=y})())(e)}getName(){return(()=>{return(()=>this[c])()})()}requestAccessToken(e,r){return((e,r)=>(void 0===r&&(r={}),m.call(this,function*(){var c,f,b,_,w,g,v,O;return c=void 0===(O=r.tokenRequestHeaderFields)?{}:O,(0,t.assert)(y(e)),f="POST"===this[d]?yield m.call(this,function*(){return b=encodeURIComponent(e),"header"===this[h]?yield m.call(this,function*(){return o.info("OAuth: Request access token from "+this[u]),yield t.web.post(this[u],"grant_type=authorization_code&code="+b,{headerFields:p(t.dotDot_573300145710716007,Object,"absorb",[c,{Authorization:this[a],"Content-Type":"application/x-www-form-urlencoded"}])})}):yield m.call(this,function*(){return"body"===this[h]?yield m.call(this,function*(){return o.info("OAuth: Request access token from "+this[u]),yield t.web.post(this[u],"grant_type=authorization_code&code="+b+"&"+this[l],{headerFields:p(t.dotDot_573300145710716007,Object,"absorb",[c,{"Content-Type":"application/x-www-form-urlencoded"}])})}):yield m.call(this,function*(){return(0,t.fail)()})})}):yield m.call(this,function*(){return"GET"===this[d]?yield m.call(this,function*(){return(_=n.default.parse(this[u],!0)).search=void 0,_.query.grant_type="authorization_code",_.query.code=e,"header"===this[h]?yield m.call(this,function*(){return w=n.default.format(_),o.info("OAuth: Request access token from "+w),yield t.web.get(w,{headerFields:p(t.dotDot_573300145710716007,Object,"absorb",[c,{Authorization:this[a]}])})}):yield m.call(this,function*(){return"query"===credentialPosition?yield m.call(this,function*(){return _.query.client_id=this[i],_.query.client_secret=this[s],w=n.default.format(_),o.info("OAuth: Request access token from "+w),yield t.web.get(w,{headerFields:c})}):yield m.call(this,function*(){return(0,t.fail)()})})}):void 0}),(0,t.assert)(-1!==f.headerFields["content-type"].search(new RegExp("\\bapplication/json\\b"))),g=JSON.parse(f.body),(v={}).raw=g,v.accessToken=v.raw.access_token,(0,t.assert)(y(v.accessToken)),v.tokenType=v.raw.token_type,y(v.raw.expires_in)&&(yield m.call(this,function*(){v.lifetime=1e3*v.raw.expires_in})),y(v.raw.refresh_token)&&(yield m.call(this,function*(){v.refreshToken=v.raw.refresh_token})),y(v.raw.scope)&&(yield m.call(this,function*(){v.scope=v.raw.scope})),v})))(e,r)}refreshAccessToken(){}}).BrowserAttachment=class{constructor(e){(e=>(()=>{this.value=e})())(e)}},f);