dermesser / yup-oauth2

An oauth2 client implementation providing the Device, Installed, Service Account, and several more flows.
https://docs.rs/yup-oauth2/
Apache License 2.0
213 stars 114 forks source link

Custom redirect URI #191

Closed hannydevelop closed 1 year ago

hannydevelop commented 1 year ago

Hi @dermesser is there an example on how to add a custom redirect URI? I'm using the example from the custom flow and I realized that the token never gets to the URI, because of the HTTPredirect method.

hannydevelop commented 1 year ago

This is the problem. https://github.com/dermesser/yup-oauth2/blob/1c6f9a7d567af5f98c6fb6b57e33a069115dbbf6/src/installed.rs#L205

We're waiting on the temporary server to exchange token, while the redirect url is a custom url.

k-bx commented 1 year ago

@hannydevelop as a dirty solution for now, you can use a fork I've just made to solve a similar problem https://github.com/k-bx/yup-oauth2

Can be used like this:

зображення зображення
dermesser commented 1 year ago

I apologize for the very great delay - the redirect URI is usually given by the provider as part of the application secret (https://docs.rs/yup-oauth2/latest/yup_oauth2/struct.ApplicationSecret.html). I hope we're talking about the same issue!

k-bx commented 1 year ago

@dermesser my keys have a redirect URL configured in them, yes, but non-patched yup-oauth2 doesn't use it, always giving localhost (127.0.0.1).

k-bx commented 1 year ago

I should also mention that the ApplicationSecret provides a list of possible redirect URLs, there can be more than one possible, and there needs to be a way to specify which one you'd like to use (can use any).

dermesser commented 1 year ago

You're right, it appears - this apparently was changed in one of the last refactors (https://github.com/dermesser/yup-oauth2/blob/master/src/installed.rs#L156), so it appears to always fall back to the OOB redirect URI (https://github.com/dermesser/yup-oauth2/blob/master/src/installed.rs#L57). I will take a look at fixing this in the next few days.

dermesser commented 1 year ago

I read the code again with some context, and it seems that the "dirty hack" you showed above is actually the intended way for the API to be used. It solves the issue of selecting the redirect URL, too. In my last comment, I think I misunderstood the underlying issue.

So just to clarify, is there still an issue that you cannot solve with the custom flow delegate?

k-bx commented 1 year ago

@dermesser regarding the custom URL – no, no issue. I can make a PR with my current changes. Should I do that, or will you make changes yourself?

Separately, there is an issue in general that I have to run a subprocess and capture a string "Please direct your browser to", present user with a web UI giving that URL, then registering a callback (a one-shot signal like futures::channel::oneshot::channel maybe) that forwards an HTTP request to yup-oauth2's localhost server. Ideally yup-oauth2 should have an API where you would give you an ability to give callback when url-visit is needed, and a way to control the subprocess (cancel it). Would you want a separate issue for this?

dermesser commented 1 year ago

@dermesser regarding the custom URL – no, no issue. I can make a PR with my current changes. Should I do that, or will you make changes yourself?

I'd be interested to see, for sure.

Separately, there is an issue in general that I have to run a subprocess and capture a string "Please direct your browser to", present user with a web UI giving that URL, then registering a callback (a one-shot signal like futures::channel::oneshot::channel maybe) that forwards an HTTP request to yup-oauth2's localhost server. Ideally yup-oauth2 should have an API where you would give you an ability to give callback when url-visit is needed, and a way to control the subprocess (cancel it). Would you want a separate issue for this?

I'm sorry but it sounds like you are contorting yourself with this - the API you are asking for already exists, and the specific method is here: https://github.com/dermesser/yup-oauth2/blob/master/src/authenticator_delegate.rs#L106 - this is an async function and should enable you to do whatever it takes to get a code, and return it to yup-oauth2 logic. Implement this trait, and set the flow_delegate field of the InstalledFlow struct to a value of this type.

Or do I still not understand your specific issue? :)

k-bx commented 1 year ago

@dermesser aha! Maybe I didn't read the docs well, sorry, will try it out.

PR incoming..