Home > Enterprise >  Authorization Error 400: invalid_request Google OAuth redirect URI ,nodejs & express passport
Authorization Error 400: invalid_request Google OAuth redirect URI ,nodejs & express passport

Time:06-25

hey i have a server with Google OAuth authentication method, when i develop i used localhost in the google redirect url and all work well, now i am deploy my server via ec2 aws , and i tried to update my google cerditinal , and looking for help.. my ip server is : => https://ip:8000 and i put in the Authorized JavaScript origins a : => https://ip.xip.io:8000 and in the Authorized redirect URIs i put :=> https://ip.xip.io:8000/auth/google/callback the google cerditinal are accept my ips with .xip.io
in addition i put here my auth router in my srever code (passport in express)

authRouter.get('/google', 
passport.authenticate('google', {
    scope: ['email'],
}));

authRouter.get('/google/callback', 
passport.authenticate('google', {
    failureRedirect: '/failure',
    successRedirect: '/',
    session: true,
}));


const AUTH_OPTIONS = {
callbackURL: '/auth/google/callback',
clientID: config.CLIENT_ID,
clientSecret: config.CLIENT_SECRET,
};

error image at google site

CodePudding user response:

The redirect uri must exactly match one you have added in google developer console.

Your application says it is sending from https://44.206.61.98:8000/auth/google/callback THere for you must add this as your redirect uri however you may have issues adding that.

However for your app to comply with the Oauth2 policy. You need to use a valid domain for your redirect uri.

Google developer console states

Users will be redirected to this path after they have authenticated with Google. The path will be appended with the authorization code for access, and must have a protocol. It can’t contain URL fragments, relative paths, or wildcards, and can’t be a public IP address.

You need to use your domain. Its not going to let you use an ip address.

  • Related