strapi-examples icon indicating copy to clipboard operation
strapi-examples copied to clipboard

Google auth not working

Open techwebdev opened this issue 2 years ago • 5 comments

** Node.js : 14.1.7.1 ** ** strapi : 4.0.0 **

When after choosing an account from google in google signup it redirects to the frontend URL. from the frontend when I call the api/connect/google/redirect?access_token=XXX then it shows me the 401 error unauthorized error. I attached the URL which I call from the frontend. I attached a screenshot. After selecting a Gmail account, it's not created the user in dB. that's the reason it returns a 401

image

techwebdev avatar Dec 19 '21 18:12 techwebdev

Some updates which might help in troubleshooting this issue. This app is broken with Strapi V4 backend.

The issue occurs when front end call back Strapi with auth code on the url locahost:1337/api/auth/google/callback?access_token={token}. Strapi V4 is not able to parse the jwt token and fails with {"name":"JsonWebTokenError","message":"invalid algorithm"}

Not sure why JsonWebToken fails as Strapi generated the token using JsonWebToken itself.

Regards M

manjunathkg avatar Dec 25 '21 09:12 manjunathkg

Also facing the same issue.

fabiocasumo avatar Jan 11 '22 15:01 fabiocasumo

in header, if you put

{
    headers: {
        Authorization: `token ${token}`
}

token is any random string for temporary you use this for a google auth so temp it working

techwebdev avatar Jan 11 '22 16:01 techwebdev

Authorization

in header, if you put

{
    headers: {
        Authorization: `token ${token}`
}

token is any random string for temporary you use this for a google auth so temp it working

Thanks mate. Adding any random string there worked as you said.

fabiocasumo avatar Jan 11 '22 19:01 fabiocasumo

this is temp. so once strapi fix you will need to remove this headers

techwebdev avatar Jan 11 '22 19:01 techwebdev

http://localhost:1337/api/auth/google/callback

add 'api' in the url

muhsin097 avatar Apr 18 '24 09:04 muhsin097