Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom redirect URI #191

Closed
hannydevelop opened this issue Dec 19, 2022 · 10 comments
Closed

Custom redirect URI #191

hannydevelop opened this issue Dec 19, 2022 · 10 comments

Comments

@hannydevelop
Copy link

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
Copy link
Author

hannydevelop commented Dec 19, 2022

This is the problem.

let auth_code = server.wait_for_auth_code().await;

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

@k-bx
Copy link

k-bx commented Jan 7, 2023

@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
Copy link
Owner

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
Copy link

k-bx commented Feb 8, 2023

@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
Copy link

k-bx commented Feb 8, 2023

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
Copy link
Owner

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
Copy link
Owner

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
Copy link

k-bx commented Feb 11, 2023

@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
Copy link
Owner

@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
Copy link

k-bx commented Feb 11, 2023

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

PR incoming..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants