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

Make redirect_uri the primary interface #294

Merged
merged 6 commits into from
Sep 4, 2023
Merged

Conversation

hadley
Copy link
Member

@hadley hadley commented Aug 31, 2023

Fixes #149

Copy link
Collaborator

@atheriel atheriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me.

NEWS.md Outdated Show resolved Hide resolved
R/oauth-flow-auth-code.R Outdated Show resolved Hide resolved
R/oauth-flow-auth-code.R Outdated Show resolved Hide resolved
@hadley hadley requested a review from jennybc September 2, 2023 19:41
#Conflicts:
#	NEWS.md
#	R/oauth-flow-auth-code.R
#	tests/testthat/test-oauth-flow-auth-code.R
@hadley hadley merged commit 1b32d8c into main Sep 4, 2023
11 of 12 checks passed
@hadley hadley deleted the redirect-url-primary branch September 4, 2023 20:29
Copy link
Member

@jennybc jennybc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is already merged and I have not actually run this code. But I made a few comments in case it's helpful.

Comment on lines 130 to +132
#' @param host_ip IP address for the temporary webserver used to capture the
#' authorization code.
#' @param type Either `desktop` or `web`. Use desktop when running on the
#' desktop in an environment where you can redirect the user to `localhost`.
#' Use `web` when running in a hosted web environment.
#' @param port Port to bind the temporary webserver to. Used only when
#' `redirect_uri` is `"http(s)://localhost"`. By default, this uses a random
#' port. You may need to set it to a fixed port if the API requires that the
#' `redirect_uri` specified in the client exactly matches the `redirect_uri`
#' generated by this function.
#' @param port Port to bind the temporary webserver to.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the explicit docs for host_ip and port go away, since they are lumped in with the host_name as deprecated in favor of redirect_uri?

#'
#' Alternatively, you can provide a URL to a website that uses javascript to
#' give the user a code to copy and paste back into the R session (see
#' <https://www.tidyverse.org/google-callback/>, for an example). This is
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW gargle includes the source for a similar page (but minus the tidyverse branding), in case you want to do the same or point at that one:

https://github.com/r-lib/gargle/blob/main/inst/pseudo-oob/google-callback/index.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't traced through the httr2 code enough yet to know if this is already here: But the gargle example doesn't just emit the naked auth code. It checks for a state and then packages/encodes the state and code.

https://github.com/r-lib/gargle/blob/ef00eb0581a8eda05185a3a6348f80cff522dd76/inst/pseudo-oob/google-callback/index.html#L46-L49

Which then gets decoded and checked:

https://github.com/r-lib/gargle/blob/ef00eb0581a8eda05185a3a6348f80cff522dd76/R/oauth-init.R#L134-L138

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I added support for that in the original PR. It should work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. I was just focusing on the specific diffs in front of my 👀

lifecycle::deprecate_warn("0.3.0", "oauth_flow_auth_code(host_ip)")
}

localhost <- parsed$hostname == "localhost"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like you might one day have to ponder what happens if someone provides urn:ietf:wg:oauth:2.0:oob as redirect_uri.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah and that seems like it will be a relatively straighforward change to make.

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

Successfully merging this pull request may close these issues.

Outh 2.0 to Sax bank
3 participants