123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138(**************************************************************************)(* *)(* Copyright 2018-2023 OCamlPro *)(* *)(* All rights reserved. This file is distributed under the terms of the *)(* GNU Lesser General Public License version 2.1, with the special *)(* exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)moduleTypes=structtypeinfo={app_id:string;token_type:string;app_name:string;token_exp:int64;token_valid:bool;token_iss:int64option;token_meta:Json_repr.anyoption;token_scopes:stringlist;user_id:string;}typeprofile={fb_name:string;fb_email:string;fb_lastname:stringoption;fb_firstname:stringoption;fb_picture:stringoption;}endmoduleEncoding=structopenTypesopenJson_encodingletpicture_encoding=obj1@@req"data"@@EzEncoding.ignore_enc@@obj1(req"url"string)letencoding=obj1@@req"data"@@EzEncoding.ignore_enc@@conv(fun{app_id;token_type;app_name;token_exp;token_valid;token_iss;token_meta;token_scopes;user_id}->(app_id,token_type,app_name,token_exp,token_valid,token_iss,token_meta,token_scopes,user_id))(fun(app_id,token_type,app_name,token_exp,token_valid,token_iss,token_meta,token_scopes,user_id)->{app_id;token_type;app_name;token_exp;token_valid;token_iss;token_meta;token_scopes;user_id})@@obj9(req"app_id"string)(req"type"string)(req"application"string)(req"expires_at"int53)(req"is_valid"bool)(opt"issued_at"int53)(opt"metadata"any_value)(req"scopes"(liststring))(req"user_id"string)letprofile=EzEncoding.ignore_enc@@conv(fun{fb_email;fb_name;fb_lastname;fb_firstname;fb_picture}->(fb_email,fb_name,fb_lastname,fb_firstname,fb_picture))(fun(fb_email,fb_name,fb_lastname,fb_firstname,fb_picture)->{fb_email;fb_name;fb_lastname;fb_firstname;fb_picture})@@obj5(req"email"string)(req"name"string)(opt"last_name"string)(opt"first_name"string)(opt"picture"picture_encoding)endmoduleServices=structopenEzAPIletarg_user_id=Arg.string~example:"68746545""user_id"letinput_token_param=Param.string~descr:"input token""input_token"letaccess_token_param=Param.string~descr:"access token""access_token"letfields_param=Param.string~descr:"output fields""fields"letfacebook_auth=BASE"https://graph.facebook.com/v8.0/"letdebug_token:(Types.info,exn,Security.none)EzAPI.service0=EzAPI.service~register:false~name:"debug_token"~params:[input_token_param;access_token_param]~output:Encoding.encodingPath.(root//"debug_token")letnodes?nameoutput:(string,'a,exn,Security.none)EzAPI.service1=EzAPI.service~register:false?name~params:[access_token_param;fields_param]~outputEzAPI.Path.(root/:arg_user_id)letedges?nameoutput:(string,'a,exn,Security.none)EzAPI.service1=EzAPI.service~register:false?name~params:[access_token_param;fields_param]~outputEzAPI.Path.(root/:arg_user_id)endopenTypesopenServicesopenEzReq_lwtopenLwt.Infixlethandle_errore=Error(handle_error(funexn->Some(Printexc.to_stringexn))e)letcheck_token~app_secret~app_idinput_token=letparams=[access_token_param,EzAPI.S(app_id^"|"^app_secret);input_token_param,EzAPI.Sinput_token]inget0~paramsfacebook_authdebug_token>|=function|Errore->handle_errore|Oktoken->iftoken.app_id=app_id&&token.token_validthenOktoken.user_idelseError(400,Some"Invalid facebook token")letfields="email,name,last_name,first_name,picture"letget_info~user_iduser_access_token:(profile,int*stringoption)resultLwt.t=letparams=[access_token_param,EzAPI.Suser_access_token;fields_param,EzAPI.Sfields]inget1~paramsfacebook_auth(nodes~name:"facebook_profile"Encoding.profile)user_id>|=function|Errore->handle_errore|Okpr->Okpr