PageSourceSearch

https://www.cccb.org/o/oauth2-provider-web/__liferay__/client.js

js cccb.org collected 2026-10-01 08:15:18 UTC 4,220 bytes, 2 lines download raw bytes

1import{pkceChallenge as R}from"../../frontend-js-web/__liferay__/index.js";var c=class{authorizeURL;clientId;debug;homePageURL;redirectURIs;tokenURL;constructor(e){this.authorizeURL=e.authorizeURL,this.clientId=e.clientId,this.debug=e.debug||!1,this.homePageURL=e.homePageURL,this.redirectURIs=e.redirectURIs,this.tokenURL=e.tokenURL}async fetch(e,r={}){return this._fetch(e,r).then(t=>{if(t.ok){let o=t.headers.get("content-type");return o&&o.indexOf("application/json")!==-1?t.json():Promise.resolve(t)}return Promise.reject(t)})}_createIframe(e,r){let n=this,t=window.location.origin,o=n.redirectURIs.find(h=>h.startsWith(t));if(!o)return Promise.reject(`No redirectURI in ${n.redirectURIs} matching origin ${t}`);let s=document.createElement("iframe");return s.src=`${n.authorizeURL}?client_id=${n.clientId}&code_challenge=${e.code_challenge}&code_challenge_method=S256&redirect_uri=${encodeURIComponent(o)}&response_type=code&prompt=none&state=${r}`,s.style.display="none",document.body.appendChild(s),new Promise((h,g)=>{let f=i=>{if(n.debug&&console.debug("OAuth2Client._createIframe.event",i),i.data.error){i.target&&i.target.parentElement&&i.target.parentElement.removeChild(i.target),g(i.data.error);return}else if(!i.data.code)return;if(i.data.state!==r){i.target&&i.target.parentElement&&i.target.parentElement.removeChild(i.target),g("state does not match");return}let l=n._requestToken(e.code_verifier,i.data.code,o);h(l),l.then(d=>Liferay.Util.SessionStorage.setItem(r,JSON.stringify({...d,expires_after_ms:new Date().getTime()+d.expires_in*1e3}),Liferay.Util.SessionStorage.TYPES.NECESSARY)).then(()=>{i.target&&i.target.parentElement&&i.target.parentElement.removeChild(i.target)})};s.contentWindow&&s.contentWindow.addEventListener("message",f)})}async _fetch(e,r={}){let n=this,t=e instanceof Request?e.url:e.toString();if(t.includes("//")&&!t.startsWith(n.homePageURL))throw new Error(`This client only supports calls to ${n.homePageURL}`);t.startsWith(n.homePageURL)||(t.startsWith("/")&&(t=t.substring(1)),t=`${n.homePageURL}/${t}`);let o=await n._getOrRequestToken();return e=e instanceof Request?{...e,url:t}:t,await fetch(e,{...r,headers:{...r?.headers,Authorization:`Bearer ${o.access_token}`}})}async _getOrRequestToken(){let e=this,r=`${e.clientId}-${Liferay.authToken}-token`,n=Liferay.Util.SessionStorage.getItem(r,Liferay.Util.SessionStorage.TYPES.NECESSARY);if(e.debug&&n&&console.debug("OAuth2Client._getOrRequestToken.cachedTokenData",n),n!=null){let t=JSON.parse(n);if(new Date().getTime()<t.expires_after_ms)return t}return await e._requestTokenSilently(r)}async _requestTokenSilently(e){let r=this,n=await R(128);return r._createIframe(n,e)}async _requestToken(e,r,n){let t=this,o=await fetch(t.tokenURL,{body:new URLSearchParams({client_id:t.clientId,code:r,code_verifier:e,grant_type:"authorization_code",redirect_uri:n}),cache:"no-cache",headers:{"Content-Type":"application/x-www-form-urlencoded"},method:"POST",mode:"cors"});return o.ok?o.json():await Promise.reject(o)}};function y(a){return new c({authorizeURL:a.authorizeURL||u(),clientId:a.clientId,debug:a.debug,homePageURL:a.homePageURL,redirectURIs:a.redirectURIs||[p()],tokenURL:a.tokenURL||m()})}async function I(a,e){let r=await U(a);if(!r)throw new Error(`No Application User Agent profile found for ${a}`);return new c({authorizeURL:u(),clientId:r.clientId,debug:e,homePageURL:r.homePageURL,redirectURIs:r.redirectURIs,tokenURL:m()})}function u(){return Liferay.ThemeDisplay.getPathContext()+"/o/oauth2/authorize"}function p(){return Liferay.ThemeDisplay.getPathContext()+"/o/oauth2/redirect"}function _(){return Liferay.ThemeDisplay.getPathContext()+"/o/oauth2/introspect"}function m(){return Liferay.ThemeDisplay.getPathContext()+"/o/oauth2/token"}async function U(a){let r=await(await fetch(`${Liferay.ThemeDisplay.getPathContext()}/o/oauth2/application?externalReferenceCode=${a}`)).json();return{clientId:r.client_id,homePageURL:r.homePageURL,redirectURIs:r.redirectURIs}}export{y as FromParameters,I as FromUserAgentApplication,c as OAuth2Client,u as getAuthorizeURL,p as getBuiltInRedirectURL,_ as getIntrospectURL,m as getTokenURL,U as getUserAgentApplication};
2//# sourceMappingURL=client.(P72AU4QH).js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.