Home > Software design >  ASP.NET MVC website application to upload files with Google Drive API URI mismatch
ASP.NET MVC website application to upload files with Google Drive API URI mismatch

Time:02-03

I'm trying to upload files using the Google Drive API and am getting a URI mismatch error from Google when clicking the upload button on my page. The URI that Google shows isn't even a part of the website, nor is a URI that I supplied to Google, so I have no idea where it's coming from.

enter image description here

Here is the APIHelper class I created based off of enter image description here

enter image description here

Edit: Startup.Auth.cs - this is used for pass through ADFS authentication and has nothing to do with the Google Drive API

 private void ConfigureAuth(IAppBuilder app)
    {
        app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
        app.UseCookieAuthentication(
            new CookieAuthenticationOptions
            {
                // TempData and Owin don't get along, use this workaround to force a custom cookie manager
                // https://stackoverflow.com/questions/28559237/intermittent-redirection-loops-during-adfs-authentication
                CookieManager = new SystemWebCookieManager()
            });
        app.UseWsFederationAuthentication(
            new WsFederationAuthenticationOptions
            {
                Wtrealm = ConfigurationManager.AppSettings["ida:Wtrealm"],
                MetadataAddress = ConfigurationManager.AppSettings["ida:ADFSMetadata"]
            });
    }

The realm matches the URI in the Google console and the metadata is the same xml link I use in all my web apps that use ADFS pass through auth, which has worked flawlessly. Nothing in my web.config file mention the IP address that Google says is my redirect URI either.

CodePudding user response:

The URI that Google shows isn't even a part of the website, nor is a URI that I supplied to Google, so I have no idea where it's coming from.

The redirect uri is built buy the client library you are using. Your app is set to run http not https its running localhost and not hosted so its 127.0.0.1 the port is also either being randomly generated by your app or something that you have set up statically. the /authorize is attached again by the client library.

The redirect uri is the location your code is prepared to accept the response from the authorization server. This URI needs to be configured in Google cloud console. The easiest solution is to copy it exactly and add it as a redirect uri in Google cloud console. Just make sure that your app is set to use a static port if the port changes its not going to work.

This video will show you how to add it. Google OAuth2: How the fix redirect_uri_mismatch error. Part 2 server sided web applications.

  •  Tags:  
  • Related