Teacan
Teacan

Reputation: 69

Using an external redirect URI with Google's OAuth2 for desktop apps

I have a desktop WPF app that has to link to a user's Google account in order to integrate with Google Drive later. I'm Using their Google.Apis.Auth.OAuth2 utility to handle authorization. I've registered my app in Google console and added OAuth2 client ID for a Desktop app as per documentation.

My problem is, I don't see where in the console I can add/whitelist a custom redirect URI for my app to use - this option seems to be only available to Web applications, and my desktop app has no other option than to redirect to localhost, which is not acceptable. I've tried overriding GoogleAuthorizationCodeFlow and passing my URI directly into

public override AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri)
        => new GoogleAuthorizationCodeRequestUrl(new Uri(AuthorizationServerUrl))
        {
            ClientId = ClientSecrets.ClientId,
            Scope = string.Join(" ", Scopes),
            RedirectUri = _customRedirectUri,
            State = _state
        };

But Google spits out a redirect_uri_mismatch of course, because why wouldn't it - I couldn't add it anywhere else. I've implemented the same functionality for DropBox integration, where you can specify and whitelist a redirect page - I assumed Google would have something similar, but the Authorized Redirect URI field isn't even there for desktop apps.

Information on this seems to be very scarce. Is this at all possible and what am I missing ?

Upvotes: 1

Views: 1803

Answers (1)

Teacan
Teacan

Reputation: 69

As a last ditch effort, I've created credentials of a different type (Web app), where I could provide my redirect URI and it worked this way. The documentation is a bit confusing in this regard though. It suggests using a Desktop profile for such apps, but you have no choice for redirect pages in that case.

Upvotes: 2

Related Questions