Can't Validate Google Access Token (wrong number of segments)

一世执手 提交于 2019-12-05 13:21:21

Answering this question because the other one is too short and vague.

Instead of passing the ID returned by profile.getId(), pass the one returned by googleUser.getAuthResponse().id_token as your id_token (the id field of the POST request you use to send the user's id over to your server).

A great tip for any developer: If you think you did everything you were supposed to do, and it is working for them, but it is not working for you, then you did not do everything you were supposed to do.

I used access_token instead of id_token when passing it in POST

I had the same issue and didn't get any fix. I had to change the way I was fetching user info. Instead of using $client->verifyIdToken(); I have used the service class this way :

$authService=new Google_Service_Oauth2($client);
    if($client->getAccessToken()){
        $data=$authService->userinfo->get();
    }

So, to get the current user email, I used $email=data['email'];.

Hope this works!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!