I have a user authenticated with Firebase and what I want to do is to authenticate this user on the backend(Google cloud platform / Go) as well. I followed along with the document on Firebase
I get the idToken on the front end and send the token on the header to the server running on my localhost with the following code.
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: '[email protected]'
}
})
On the backend I want to verify the idToken. I first create the auth client with the following code.
opt := option.WithCredentialsFile("firebase_credential.json")
app, err := firebase.NewApp(context.Background(), nil, opt)
client, err := app.Auth(context.Background())
With the client and the idToken from the frontend I tried the code below.
t, err := client.VerifyIDToken(context.Background(), idToken)
How ever this throws an error of
{"message":"Get https://www.googleapis.com/robot/v1/metadata/x509/[email protected]: oauth2: cannot fetch token: Post https://accounts.google.com/o/oauth2/token: not an App Engine context"}
I also tried to curl the same request to the sever but the same error came out.
curl -X POST -H "Authentication-Token:hogehogemytoken" -d '{"name":"My name","user_name":"my user name","email":"[email protected]"}' http://localhost:8080/users
I am quite sure that I'm sending the right token. Any ideas?