import{logger as e}from"../logger/index.mjs";import{ErrorHandler as t}from"../utils/errors/ErrorHandler.mjs";import{formatSession as n}from"../utils/auth/getAuth.mjs";import{m as r,p as i,s as a,u as o}from"../oAuth2.service-4snhZ7Ht.mjs";import s,{Request as c,Response as l}from"oauth2-server";const u=new s({model:r(),accessTokenLifetime:3600,allowBearerTokensInQueryString:!0}),d=async(e,t)=>{e.oauth=u},f=async(r,s)=>{if(r.locals||={},r.locals?.authType===void 0)try{if(!r.headers.authorization)return;let t=new c({headers:r.headers,method:r.method,query:r.query,body:r.body}),u=new l(s.raw),d=n(await a(await o((await r.oauth.authenticate(t,u,i)).accessToken))),f=r.locals;if(f){f.authType=`session`;for(let[e,t]of Object.entries(d))f[e]=t}e.info(`OAuth2 bearer token authenticated`,d.user.email)}catch(e){t.handleAppErrorResponse(s,e);return}};export{d as attachOAuthInstance,f as oAuth2Middleware};
//# sourceMappingURL=oAuth2.middleware.mjs.map