Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to set the OAuth redirect_uri in ASP.NET 4.5 webforms application

I can't find anywhere how to set the OAuth2 redirect_uri in an ASP.NET 4.5 webforms application. By default it's 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 from Facebook:

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

And I get this error from my website domain (not from the localhost).

like image 755
Mario Avatar asked Aug 07 '14 13:08

Mario


People also ask

What is OAuth Redirect_uri?

The redirect_uri is an address used by OAuth providers as a location to deliver the access_token by means of a browser redirect. The popular OAuth provider Facebook has run into many vulnerabilities relating to OAuth redirection.

Where is OAuth redirect URI?

From the Firebase documentation: ... make sure your OAuth redirect URI (e.g. my-app-12345.firebaseapp.com/__/auth/handler) is listed as one of your OAuth redirect URIs in your Facebook app's settings page on the Facebook for Developers site in the Product Settings > Facebook Login config.

How does OAuth redirect URL work?

The redirect URL is the endpoint for your application or web page that processes the seller authorization response and manages the seller's OAuth tokens. You need to add this URL to your application using the Developer Dashboard.

What is OAuth authentication in ASP NET MVC?

OAuth provides client applications a "secure delegated access" to server resources on behalf of a resource owner. It specifies a process for resource owners to authorize third-party access to their server resources without sharing their credentials (from the Wikipedia). OAuth stands for Open Authorization.


2 Answers

I was testing the built in external login logic for authentication, and I got this error even though my Google API credentials were correct. For example the redirect URI was set to:

http://localhost:29405/signin-google

The odd thing was that the default CallbackPath for the Google Authentication is "/signin-google" but I had to set this anyway in 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")
        });
like image 92
thenninger Avatar answered Oct 19 '22 20:10

thenninger


After looking at a lot of answers this is what worked for me:

  1. Enable Google + API
  2. The default redirect URI is /signin-google, so add this to the Authorized redirect URI. enter image description here

  3. Add this to the RouteConfig File:

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

Hope it helps anyone that cross by this problem.

like image 29
Sanchitos Avatar answered Oct 19 '22 20:10

Sanchitos