背景
由于特殊的原因,国内无法访问Google的api,只能通过代理的方式,然后一开始以为简单的在shell设置全局代理就好了,然并卵,后来发现其实firebase提供了代理的方法,在这里简单记录一下。
设置代理
import admin from 'firebase-admin';
import { HttpsProxyAgent } from 'https-proxy-agent';
admin.initializeApp({
credential: admin.credential.cert('Your config file path'),
httpAgent: new HttpsProxyAgent('http://127.0.0.1:7890'),
});
const auth = admin.auth();
// 调用auth.verifyIdToken校验谷歌登录
auth.verifyIdToken('Id token') ✅
// 注意第二个参数: 在国内,不要将其设置为true,否则会导致方法调用失败。源码中这个参数用于验证用户是否被销毁,目前这个api我没找到设置代理的方法。
auth.verifyIdToken('Id token', true) ❎