1import{e1 as S}from"./index-PHo2o-Lr.js";class P extends S{constructor(){super(...arguments),this.scriptLoaded=!1}async initialize(e){this.clientId=e.clientId,await this.loadScript()}async signIn(e){var i,t,l,a,d,o,r,s;if(!this.clientId)throw new Error("clientId must be provided. Call initialize() first.");const f=((i=e==null?void 0:e.scopes)!==null&&i!==void 0?i:[]).map(y=>y==="FULL_NAME"?"name":"email").join(" ");window.AppleID.auth.init({clientId:this.clientId,scope:f||void 0,redirectURI:e==null?void 0:e.redirectUrl,state:e==null?void 0:e.state,nonce:e==null?void 0:e.nonce,usePopup:!0});const n=await window.AppleID.auth.signIn(),c=n.authorization,u=c.id_token,w=c.code,p=c.state,m=this.decodeJwtPayload(u),_=m.sub,g=(t=m.email)!==null&&t!==void 0?t:null;let v=null,h=null;n.user&&(v=(a=(l=n.user.name)===null||l===void 0?void 0:l.firstName)!==null&&a!==void 0?a:null,h=(o=(d=n.user.name)===null||d===void 0?void 0:d.lastName)!==null&&o!==void 0?o:null);const I={authorizationCode:w,idToken:u,user:_,email:(s=(r=n.user)===null||r===void 0?void 0:r.email)!==null&&s!==void 0?s:g,givenName:v,familyName:h};return p!==void 0&&(I.state=p),I}decodeJwtPayload(e){const t=e.split(".")[1],l=atob(t.replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(l)}loadScript(){return this.scriptLoaded?Promise.resolve():new Promise((e,i)=>{const t=document.createElement("script");t.src="https://appleid.cdn-apple.com/appleauth/static/jsapi/appleid/1/en_US/appleid.auth.js",t.onload=()=>{this.scriptLoaded=!0,e()},t.onerror=()=>{i(new Error("Failed to load Apple Sign-In SDK."))},document.head.appendChild(t)})}}export{P as AppleSignInWeb};
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.