UNPKG

@julienbenac/ally-orange

Version:
8 lines (7 loc) 2.02 kB
import{getDirname as a}from"@poppinss/utils";var c=a(import.meta.url);async function p(n){let o=await n.createCodemods();await o.defineEnvVariables({ORANGE_CLIENT_ID:"",ORANGE_CLIENT_SECRET:"",ORANGE_CALLBACK_URL:""}),await o.defineEnvValidations({variables:{ORANGE_CLIENT_ID:"Env.schema.string()",ORANGE_CLIENT_SECRET:"Env.schema.string()",ORANGE_CALLBACK_URL:"Env.schema.string()"},leadingComment:"Variables for configuring @julienbenac/ally-orange"})}import{Oauth2Driver as u}from"@adonisjs/ally";var s=class extends u{constructor(e,r){super(e,r);this.config=r;this.loadState()}authorizeUrl="https://api.orange.com/openidconnect/fr/v1/authorize";accessTokenUrl="https://api.orange.com/openidconnect/fr/v1/token";userInfoUrl="https://api.orange.com/openidconnect/fr/v1/userinfo";stateCookieName="orange_oauth_state";stateParamName="state";codeParamName="code";errorParamName="error";scopeParamName="scope";scopesSeparator=" ";configureRedirectRequest(e){e.scopes(this.config.scopes||["openid"]),e.param("response_type","code")}async redirect(e){let r=await this.redirectUrl(t=>{typeof e=="function"&&e(t)});this.ctx.response.redirect(r)}getAuthenticatedRequest(e,r){let t=this.httpClient(e);return t.header("Authorization",`Bearer ${r}`),t.header("Accept","application/json"),t.parseAs("json"),t}async getUserInfo(e,r){let t=this.getAuthenticatedRequest(this.userInfoUrl,e);typeof r=="function"&&r(t);let i=await t.get();return{id:i.sub,nickName:"",name:"",email:null,emailVerificationState:"unsupported",avatarUrl:null,original:i}}accessDenied(){let e=this.getError();return e?e==="access_denied":!1}async user(e){let{id_token:r,...t}=await this.accessToken(e);return{...await this.getUserInfo(t.token,e),token:{...t,idToken:r}}}async userFromToken(e,r){return{...await this.getUserInfo(e,r),token:{token:e,type:"bearer"}}}};function h(n){return o=>new s(o,n)}export{p as configure,h as orange,c as stubsRoot}; /** * @julienbenac/ally-orange * * @author Julien Benac <contact@julienbenac.fr> * @license MIT */