-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk-NO5EP2EX.js
1 lines (1 loc) · 3.33 KB
/
chunk-NO5EP2EX.js
1
import{O as h,a,d as p,f as c,l as m,o as g,q as l}from"./chunk-4ABEXS3U.js";var u=class{constructor(){}loadScript(o,f,t,e=null){if(typeof document<"u"&&!document.getElementById(o)){let i=document.createElement("script");i.async=!0,i.src=f,i.onload=t,e||(e=document.head),e.appendChild(i)}}},d=class{},O={oneTapEnabled:!0},A=(()=>{let o=class o extends u{constructor(t,e){super(),this.clientId=t,this.initOptions=e,this.changeUser=new h,this._socialUser=new c(null),this._accessToken=new c(null),this._receivedAccessToken=new h,this.initOptions=a(a({},O),this.initOptions),this._socialUser.pipe(l(1)).subscribe(this.changeUser),this._accessToken.pipe(l(1)).subscribe(this._receivedAccessToken)}initialize(t){return new Promise((e,i)=>{try{this.loadScript(o.PROVIDER_ID,"https://accounts.google.com/gsi/client",()=>{if(google.accounts.id.initialize({client_id:this.clientId,auto_select:t,callback:({credential:n})=>{let s=this.createSocialUser(n);this._socialUser.next(s)},prompt_parent_id:this.initOptions?.prompt_parent_id,itp_support:this.initOptions.oneTapEnabled}),this.initOptions.oneTapEnabled&&this._socialUser.pipe(m(n=>n===null)).subscribe(()=>google.accounts.id.prompt(console.debug)),this.initOptions.scopes){let n=this.initOptions.scopes instanceof Array?this.initOptions.scopes.filter(s=>s).join(" "):this.initOptions.scopes;this._tokenClient=google.accounts.oauth2.initTokenClient({client_id:this.clientId,scope:n,prompt:this.initOptions.prompt,callback:s=>{s.error?this._accessToken.error({code:s.error,description:s.error_description,uri:s.error_uri}):this._accessToken.next(s.access_token)}})}e()})}catch(n){i(n)}})}getLoginStatus(){return new Promise((t,e)=>{this._socialUser.value?t(this._socialUser.value):e(`No user is currently logged in with ${o.PROVIDER_ID}`)})}refreshToken(){return new Promise((t,e)=>{google.accounts.id.revoke(this._socialUser.value.id,i=>{i.error?e(i.error):t(this._socialUser.value)})})}getAccessToken(){return new Promise((t,e)=>{this._tokenClient?(this._tokenClient.requestAccessToken({hint:this._socialUser.value?.email}),this._receivedAccessToken.pipe(g(1)).subscribe(t)):this._socialUser.value?e("No token client was instantiated, you should specify some scopes."):e("You should be logged-in first.")})}revokeAccessToken(){return new Promise((t,e)=>{this._tokenClient?this._accessToken.value?google.accounts.oauth2.revoke(this._accessToken.value,()=>{this._accessToken.next(null),t()}):e("No access token to revoke"):e("No token client was instantiated, you should specify some scopes.")})}signIn(){return Promise.reject('You should not call this method directly for Google, use "<asl-google-signin-button>" wrapper or generate the button yourself with "google.accounts.id.renderButton()" (https://developers.google.com/identity/gsi/web/guides/display-button#javascript)')}signOut(){return p(this,null,function*(){google.accounts.id.disableAutoSelect(),this._socialUser.next(null)})}createSocialUser(t){let e=new d;e.idToken=t;let i=this.decodeJwt(t);return e.id=i.sub,e.name=i.name,e.email=i.email,e.photoUrl=i.picture,e.firstName=i.given_name,e.lastName=i.family_name,e}decodeJwt(t){let i=t.split(".")[1].replace(/-/g,"+").replace(/_/g,"/"),n=decodeURIComponent(window.atob(i).split("").map(function(s){return"%"+("00"+s.charCodeAt(0).toString(16)).slice(-2)}).join(""));return JSON.parse(n)}};o.PROVIDER_ID="GOOGLE";let r=o;return r})();export{A as a};