【发布时间】:2018-02-17 04:43:08
【问题描述】:
我有一个通过 Firebase 身份验证的用户,我想做的是在后端(谷歌云平台/Go)上对该用户进行身份验证。我跟着Firebase上的文档进行操作
我在前端获取 idToken,然后使用以下代码将标头上的令牌发送到在我的本地主机上运行的服务器。
idToken = firebase.auth().currentUser.getIdToken()
axios({
method: 'POST',
url: 'https://localhost:8080/users',
headers: {
'Authentication-Token': idToken
},
data: {
name: 'My name',
user_name: 'my_user_name',
email: 'example@example.com'
}
})
我想在后端验证 idToken。我首先使用以下代码创建身份验证客户端。
opt := option.WithCredentialsFile("firebase_credential.json")
app, err := firebase.NewApp(context.Background(), nil, opt)
client, err := app.Auth(context.Background())
使用客户端和前端的 idToken 我尝试了下面的代码。
t, err := client.VerifyIDToken(context.Background(), idToken)
这怎么会引发
的错误{"message":"Get https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com: oauth2: cannot fetch token: Post https://accounts.google.com/o/oauth2/token: not an App Engine context"}
我也尝试curl向服务器发送相同的请求,但出现了相同的错误。
curl -X POST -H "Authentication-Token:hogehogemytoken" -d '{"name":"My name","user_name":"my user name","email":"example@example.com"}' http://localhost:8080/users
我很确定我正在发送正确的令牌。 有什么想法吗?
【问题讨论】:
标签: javascript firebase google-app-engine go firebase-authentication