Google-api-dotnet-client: FR: Custom Google auth redirect message

Created on 7 Mar 2019  路  18Comments  路  Source: googleapis/google-api-dotnet-client

Hi Google API team!

I am working on a C# application called Gmail Notifier that works with Gmail API, and I would like to know if it is possible to customize the redirect URI after signing in with Google on the OAuth screen?

For now, the current behavior of the Google API .NET client is to redirect users to something like:
http://127.0.0.1:56252/authorize/?code=

Thanks for your feedback! :wink:

p2 feature request

Most helpful comment

All 18 comments

@xavierfoucrier This is not currently customizable.

It looks like you're writing an application that is locally installed, so the hostname has to be 127.0.0.1, so it redirects back to your application. The path authorize/ is hard-coded here: https://github.com/googleapis/google-api-dotnet-client/blob/3978ee951c65e2d84cca7544fc74c6514f11ef27/Src/Support/Google.Apis.Auth/OAuth2/LocalServerCodeReceiver.cs#L44

If this hard-coded path is causing a problem that you can't work-around, please let us know here and we'll consider making it configurable.

Hey @chrisdunelm!

Thanks for your feedback first :+1:

My application is a C# software that works locally on Windows machines, but... there is no local server to properly serve http://127.0.0.1, so should I add support for it?

For me, since the user has logged in into Gmail, its better to redirect it to a webpage that display "hey, you have logged in successfully, you can use the app now", instead of "Unable to reach 127.0.0.1"... it's very confusing. :confused:

@xavierfoucrier It is required to redirect to localhost, as this is how your application retrieves the authorization code from Google.
The auth library starts up a simple http server to retrieve this code, and serves a very simple page stating that auth is complete and the browser can be closed.
If you are not seeing this, then either there is something blocking serving locally on your machine, or there is something preventing the server from working.

Does the auth success for your application? If so, then the local server is working sufficiently to read the auth code.

Are you able to post a screenshot of the browser after auth is complete?

Here is a screenshot of localhost after auth is complete:

Capture

Note that if I manually refresh the webpage, the server is not responding anymore.

Right, that's expected - the server shuts down when the verification code has been requested. It looks like it's all working correctly. That's very different from the "Unable to reach 127.0.0.1" message you reported in an earlier comment.

This is working as intended. Closing.

If it works like intended it's ok, I can understand, but... is there a way to properly modify this webpage to display something else that the default message? That is confusing for end users.

That's what matter for me in this issue: display another message OR use a custom redirect URI to display another web page with a specific message.

Thanks :wink:

Ah, OK, that's a different matter.

Yes, we could potentially allow this message to be customized. I'll re-open this issue, and update the title to reflect this.

Yup,

Sorry to not be enough clear.

Different message is a good start, but... if we could customize the whole page with CSS or app branding it could be a serious gain for app credibility regarding the end users.

May be the API should use some kind of web "template" file and display/use it when the auth is complete.

Thanks for your time.
Best regards :wink: :beers:

I happened to dig into this myself and was able to come up with a solution that you're welcome to use @xavierfoucrier or could be used as the solution for this issue.

https://github.com/SaviorXTanren/google-api-dotnet-client/commit/a49e652dc8b6ef2d1aa5ae23f74f54c2a34f70fd

If you guys like the solution, I'm happy to submit it as a formal PR. In the interim, just copy down the entire class and rename it to something like CustomRedirectLocalServerCodeReceiver. You then would just use it like so:

UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync( ... , new CustomRedirectLocalServerCodeReceiver("Hello World!"));

Hi @SaviorXTanren!

Sounds good, love it! I will test it as soon as possible in my application.
I appreciate your feedback :wink:

@SaviorXTanren Please do submit this change as a PR. Thanks :)

I expect this to be implemented and released within a couple of weeks.

@chrisdunelm thanks chris :wink:

@SaviorXTanren If you'd like to create a PR for this, then please do. Otherwise I'll create a PR myself next week.

Perfect, I will test this solution in my application soon. Thanks guys! :wink:

Hi guys @chrisdunelm @SaviorXTanren,
It is now working as expected in my application.
Big thanks for this feature! :v:

Was this page helpful?
0 / 5 - 0 ratings