Where to set OAuth redirect_uri in an ASP.NET 4.5 web form application

I cannot find anywhere how to set OAuth2 redirect_uri in an ASP.NET 4.5 webforms application. By default it is set to localhost and of course I get this error from google:

The redirect URI in the request: http://localhost:3884/signin-google did not match a registered redirect URI 

And this is from Facebook:

 Given URL is not allowed by the Application configuration.: One or more of the given URLs is not allowed by the App settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App domains. 

And I get this error from my site (not from the local host).

+7
c # webforms
source share
5 answers

I tested the built-in external login logic for authentication, and I received this error even though my Google API credentials are correct. For example, the redirect URI was configured to:

http://localhost:29405/signin-google

It's strange that the default CallbackPath for Google Authentication is "/ signin-google", but I still had to set this to App_Start / Startup.Auth, so I added this line and it worked:

CallbackPath = new PathString ("/ signin-google")

So...

 app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() { ClientId = "YOUR CLIENT ID", ClientSecret = "YOUR CLIENT SECRET", CallbackPath = new PathString("/signin-google") }); 
+19
source share

Having looked at the many answers, this is what worked for me:

  • Enable Google + API
  • The default redirect URI is / signin-google, so add it to your Authorized Redirect URI. enter image description here

  • Add this to your RouteConfig file:

    routes.MapRoute (name: "signin-google", url: "signin-google", defaults: new {controller = "Account", action = "ExternalLoginCallback"});

Hope this helps anyone who overcomes this problem.

+13
source share

You need to enable the Google+ API (it is not enabled by default).

Enable Google+ API https://console.developers.google.com/project/projectId/apiui/apiview/plus

Default CallbackPath ( /signin-google ) is fine, but you should add it to REDIRECT URIS in Credentials - OAuth ClientID (you can replace the default value /oauth2callback ).

+6
source share

You must also enable SSL ON.

I did what thenninger and Sanchitos published.

But only after I launched my webApp with SSL did it work.

You can enable SSL in the project properties here:

enter image description here

And make sure the application starts at the correct address:

enter image description here

0
source share

I needed to add more path to the route, as shown below:

  routes.MapRoute(name: "signin-google", url: "localhost:44336/signin-google", defaults: new { controller = "Account", action = "ExternalLoginCallback" }); 
-2
source share

All Articles