import{k as y}from"./chunk-LCT7LWZZ.js";import{B as u,D as g,w as c,x as l}from"./chunk-MLI5PH7P.js";import{A as d,X as h,ca as f,ha as m,p,u as a}from"./chunk-42LKD4JQ.js";var _=(()=>{class n{constructor(t,e){this.http=t,this.apiService=e,this.getOrganizationPrincipleName=h(r=>{let o=r?.body?.access_token;return o?d({organization:this.MicrosoftGetTenantIdFromGraph(o),me:this.MicrosoftGetPrincipleNameFromGraph(o)}).pipe(a(({organization:i,me:s})=>({tenantId:i?.body?.value?.[0]?.id,userPrincipalName:s?.body?.userPrincipalName}))):p({error_description:r?.body?.error_description})})}MicrosoftConsent(t,e,r,o){return this.apiService.getAccessRefresh(t,e,r,o).pipe(this.getOrganizationPrincipleName)}MicrosoftConsentForPrinciple(t,e,r,o){return this.apiService.getAccessRefresh(t,e,r,o).pipe(h(i=>i?.body?.access_token?o==="Microsoft"?this.MicrosoftGetPrincipleNameFromGraph(i?.body?.access_token).pipe(a(s=>s?.body?.userPrincipalName)):this.apiService.getUserInfoFromGoogle(i?.body?.access_token).pipe(a(s=>s?.body?.emailAddresses[0].value)):p(new u({body:i?.body,status:403,statusText:"Forbidden"}))))}MicrosoftGetAccessRefresh(t,e,r,o,i="authorization_code",s="https://graph.microsoft.com/"){let b=new c({"Content-Type":"application/x-www-form-urlencoded","Cache-Control":"no-cache",Pragma:"no-cache"}),v=new l().set("client_id",e).set("redirect_uri",o).set("client_secret",r).set("code",t).set("grant_type",i).set("resource",s);return this.http.post("https://login.microsoftonline.com/common/oauth2/token",v.toString(),{headers:b,responseType:"json",observe:"response"})}MicrosoftGetTenantIdFromGraph(t){let e="https://graph.microsoft.com/v1.0/organization",r=new c({Authorization:`Bearer ${t}`});return this.http.get(e,{headers:r,responseType:"json",observe:"response"})}MicrosoftGetPrincipleNameFromGraph(t){let e="https://graph.microsoft.com/v1.0/me",r=new c({Authorization:`Bearer ${t}`});return this.http.get(e,{headers:r,responseType:"json",observe:"response"})}static{this.\u0275fac=function(e){return new(e||n)(m(g),m(y))}}static{this.\u0275prov=f({token:n,factory:n.\u0275fac,providedIn:"root"})}}return n})();export{_ as a};
