0

I am working on one of the log in form in ASP.Net MVC 5. And the google login is not working properly. When I run the project as localhost I am able to redirect to the google's log in page. But when I publish the website I get error as Error: redirect_uri_mismatch. I am new to all this please guide me. below is code snippet.

   var ClientID = "*************";
    var url = "https://accounts.google.com/o/oauth2/auth?";
    var parameters = "response_type=code&client_id=".concat(ClientID).concat("&redirect_uri=@(HttpUtility.UrlEncode(SimUtils.UrlForGoogleAuth))" + "&scope=openid%20email&");
    var loginUri = url.concat(parameters);
    window.open(loginUri);

I don't even know where to look as it is working correctly when I ran in localhost. Please help me.

Unbreakable
  • 7,776
  • 24
  • 90
  • 171
  • The most important piece of information here is probably `SimUtils.UrlForGoogleAuth`--what does that evaluate to? – mherzig Dec 21 '16 at 20:12
  • it returns me some URL. Does that URL needs to be registered somewhere? – Unbreakable Dec 21 '16 at 20:20
  • What is the URL? You might also need to go to the Google panel where you set up your app and make sure the domain of your app is listed as an approved domain. – mherzig Dec 21 '16 at 20:33
  • Example: URL Registered: **www.abc.com** in the panel and the Final URL generated is `loginUri = "******************redirect_uri=www.abc.com&scope=openid%20email&` – Unbreakable Dec 21 '16 at 20:58
  • Well, my best guess is that you have the same problem as this question: http://stackoverflow.com/questions/11485271/google-oauth-2-authorization-error-redirect-uri-mismatch#11485644. Seems that it may take some time for adding a redirect URL to be picked up by Google auth. As long as `redirect_url` matches one in the control panel, I'm not sure what else would be causing this problem. – mherzig Dec 21 '16 at 21:01
  • it's been there for atleast 3 months. I have just given an example. please guide me. – Unbreakable Dec 21 '16 at 21:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/131190/discussion-between-unbreakable-and-mherzig). – Unbreakable Dec 21 '16 at 21:02

0 Answers0