Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect_uri_mismatch The redirect URI in the request, http://localhost:4500/auth/auth/google/callback, does not match #73

Open
yilmazbingo opened this issue Nov 23, 2020 · 5 comments

Comments

@yilmazbingo
Copy link

yilmazbingo commented Nov 23, 2020

Google is seeing callback url as "http://localhost:4500/auth/auth/google/callback" //double "auth"

this is the callback url I set on app settings.
http://localhost:4500/auth/google/callback
this is passport configuration:

passport.use(
  new GoogleStrategy.Strategy(
    {
      clientID: process.env.GOOGLE_CLIENT_ID!, // "!" is typescript character
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
      callbackURL: "auth/google/callback",
    },
    // this is called when user is redirected back to our app
    async (accessToken, refreshToken, profile, done) => {
      const existingUser = await User.findOne({ googleId: profile.id });
      if (existingUser) {
        done(undefined, existingUser);
      }
      const user = await new User({ googleId: profile.id }).save();
      done(undefined, user);
    }
  )
);

here are the routtes:

export const authRoutes = (app: Application) => {
  //with passing "google" passport knows that it will use GoogleStrategy
  app.get(
    "/auth/google",
    passport.authenticate("google", { scope: ["profile", "email"] }),
    (req, res) => {
      res.redirect("/");
    }
  );

  // passport sees the code here and it knows that it has to use the code to get user
  app.get("/auth/google/callback", passport.authenticate("google"));
  app.get("/auth/current_user", (req: Request, res: Response) => {
    res.send(req.user);
  });
  app.get("/auth/logout", (req: Request, res: Response) => {
    req.logout();
    res.json({ user: req.user });
  });
};

### Environment

* Operating System: Kali Linux 2020
* Node version:  -v10.21.0 

 "passport": "^0.4.1",
    "passport-google-oauth20": "^2.0.0",

![google-oauth](https://user-images.githubusercontent.com/47233790/99930825-83e5a200-2d20-11eb-9021-443d82eb40d5.png)

@lily-law
Copy link

lily-law commented Dec 6, 2020

Hey, have you added http://localhost:4500/auth/google/callback in the Authorised redirect URIs in your console.developers.google.com?

@blood-rogue
Copy link

blood-rogue commented Dec 7, 2020

You need to provide a public IP. I don't think google can access localhost.
Try providing IP like 127.0.0.1:8080 and adding it to authorized URIs in google dev console.
Also try
callbackURL : '/auth/google/callback'

@Ritik0602
Copy link

Your url contains two levels of auth.
You have accidently added : http://localhost:4500/auth/auth/google/callback
Instead it should be http://localhost:4500/auth/google/callback

@Venryx
Copy link

Venryx commented Aug 11, 2021

Also try
callbackURL : '/auth/google/callback'

+1. I'm guessing that is the issue. (leaving off the starting / can, depending on the context/parser, result in it viewing it as a "relative to current url" path, in which case it would take the /auth/google path and find the relative auth... as replacing the right-most path-segment)

@ellenhutchings
Copy link

I'm getting this with '/login/google/callback' from a https site. The redirect_uri is only http?

I can't add the http version as an authorized redirect as it's in production and Google says:

Invalid Redirect: This app has a publishing status of "In production". URI must use https:// as the scheme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants